Skip to content

Commit

Permalink
attempt at java example (#2486)
Browse files Browse the repository at this point in the history
Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>
  • Loading branch information
hhunter-ms committed Jun 2, 2022
1 parent c113088 commit 93a6a51
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,19 @@ public async Task<ActionResult<Stock>> HandleCheckout(Checkout checkout, [FromSe
{{% codetab %}}

```java

private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

@Topic(name = "checkout", pubsubName = "order_pub_sub")
@PostMapping(path = "/orders")
public Mono<Void> handleMessage(@RequestBody(required = false) CloudEvent<String> cloudEvent) {
return Mono.fromRunnable(() -> {
try {
System.out.println("Subscriber received: " + cloudEvent.getData());
System.out.println("Subscriber received: " + OBJECT_MAPPER.writeValueAsString(cloudEvent));
} catch (Exception e) {
throw new RuntimeException(e);
}
});
```

{{% /codetab %}}
Expand Down

0 comments on commit 93a6a51

Please sign in to comment.