From a8714d59ac20c385d91e15d87fc6281af03b1a1c Mon Sep 17 00:00:00 2001 From: Charlie Mk Date: Mon, 24 Apr 2023 10:09:17 +0200 Subject: [PATCH] feat: Add endpoint examples. --- .../examples/pubsub/SubscriberController.java | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/examples/src/main/java/io/dapr/examples/pubsub/SubscriberController.java b/examples/src/main/java/io/dapr/examples/pubsub/SubscriberController.java index cbfd4f7bc4..a73f6f05d9 100644 --- a/examples/src/main/java/io/dapr/examples/pubsub/SubscriberController.java +++ b/examples/src/main/java/io/dapr/examples/pubsub/SubscriberController.java @@ -39,9 +39,10 @@ public class SubscriberController { private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + /** * Handles a registered publish endpoint on this app. - * + * * @param cloudEvent The cloud event received. * @return A message containing the time. */ @@ -58,6 +59,27 @@ public Mono handleMessage(@RequestBody(required = false) CloudEvent handleMessageWithErrorHandler(@RequestBody(required = false) CloudEvent cloudEvent) { + return Mono.fromRunnable(() -> { + try { + System.out.println("Subscriber got: " + cloudEvent.getData()); + System.out.println("Subscriber got: " + OBJECT_MAPPER.writeValueAsString(cloudEvent)); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + } + /** * Handles a registered publish endpoint on this app (version 2 of a cloud * event). @@ -66,6 +88,7 @@ public Mono handleMessage(@RequestBody(required = false) CloudEvent handleMessageV2(@RequestBody(required = false) CloudEvent cloudEvent) { @@ -84,7 +107,8 @@ public Mono handleMessageV2(@RequestBody(required = false) CloudEvent clou * @param cloudEvent The cloud event received. * @return A message containing the time. */ - @Topic(name = "bulkpublishtesting", pubsubName = "${myAppProperty:messagebus}") + @Topic(name = "bulkpublishtesting", pubsubName = "${myAppProperty:messagebus}", + deadLetterTopic = "${deadLetterProperty:deadTopic}") @PostMapping(path = "/bulkpublishtesting") public Mono handleBulkPublishMessage(@RequestBody(required = false) CloudEvent cloudEvent) { return Mono.fromRunnable(() -> { @@ -104,7 +128,8 @@ public Mono handleBulkPublishMessage(@RequestBody(required = false) CloudE * @return A list of responses for each event. */ @BulkSubscribe() - @Topic(name = "testingtopicbulk", pubsubName = "${myAppProperty:messagebus}") + @Topic(name = "testingtopicbulk", pubsubName = "${myAppProperty:messagebus}", + deadLetterTopic = "${deadLetterProperty:deadTopic}") @PostMapping(path = "/testingtopicbulk") public Mono handleBulkMessage( @RequestBody(required = false) BulkSubscribeMessage> bulkMessage) {