Skip to content

Commit

Permalink
feat: Add endpoint examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
charlieMk1 committed Apr 24, 2023
1 parent 358af42 commit a8714d5
Showing 1 changed file with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -58,6 +59,27 @@ public Mono<Void> handleMessage(@RequestBody(required = false) CloudEvent<String
});
}


/**
* Handles a registered publish endpoint on this app adding a topic which manage to forward undeliverable messages.
*
* @param cloudEvent The cloud event received.
* @return A message containing the time.
*/
@Topic(name = "testingtopic", pubsubName = "${myAppProperty:messagebus}",
deadLetterTopic = "${deadLetterProperty:deadTopic}")
@PostMapping(path = "/testingtopic")
public Mono<Void> handleMessageWithErrorHandler(@RequestBody(required = false) CloudEvent<String> 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).
Expand All @@ -66,6 +88,7 @@ public Mono<Void> handleMessage(@RequestBody(required = false) CloudEvent<String
* @return A message containing the time.
*/
@Topic(name = "testingtopic", pubsubName = "${myAppProperty:messagebus}",
deadLetterTopic = "${deadLetterProperty:deadTopic}",
rule = @Rule(match = "event.type == \"v2\"", priority = 1))
@PostMapping(path = "/testingtopicV2")
public Mono<Void> handleMessageV2(@RequestBody(required = false) CloudEvent cloudEvent) {
Expand All @@ -84,7 +107,8 @@ public Mono<Void> 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<Void> handleBulkPublishMessage(@RequestBody(required = false) CloudEvent cloudEvent) {
return Mono.fromRunnable(() -> {
Expand All @@ -104,7 +128,8 @@ public Mono<Void> 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<BulkSubscribeAppResponse> handleBulkMessage(
@RequestBody(required = false) BulkSubscribeMessage<CloudEvent<String>> bulkMessage) {
Expand Down

0 comments on commit a8714d5

Please sign in to comment.