From ebd66a77af0483987da2b8dd36ae6432bdd9ce27 Mon Sep 17 00:00:00 2001 From: Carlos Rosales Date: Tue, 25 Apr 2023 16:38:39 +0200 Subject: [PATCH] Create new methods with deadLetterTopic instead of overload existing ones. Signed-off-by: Charlie Mk --- .../springboot/DaprBeanPostProcessor.java | 2 +- .../java/io/dapr/springboot/DaprRuntime.java | 21 ++++ .../springboot/DaprTopicSubscription.java | 96 ++++++++++++++----- .../io/dapr/springboot/DaprRuntimeTest.java | 4 +- 4 files changed, 98 insertions(+), 25 deletions(-) diff --git a/sdk-springboot/src/main/java/io/dapr/springboot/DaprBeanPostProcessor.java b/sdk-springboot/src/main/java/io/dapr/springboot/DaprBeanPostProcessor.java index ab86256e55..b33181884e 100644 --- a/sdk-springboot/src/main/java/io/dapr/springboot/DaprBeanPostProcessor.java +++ b/sdk-springboot/src/main/java/io/dapr/springboot/DaprBeanPostProcessor.java @@ -117,7 +117,7 @@ private static void subscribeToTopics( List routes = getAllCompleteRoutesForPost(clazz, method, topicName); for (String route : routes) { daprRuntime.addSubscribedTopic( - pubSubName, topicName, match, rule.priority(), route,deadLetterTopic, metadata, bulkSubscribe); + pubSubName, topicName, match, rule.priority(), route, deadLetterTopic, metadata, bulkSubscribe); } } catch (JsonProcessingException e) { throw new IllegalArgumentException("Error while parsing metadata: " + e); diff --git a/sdk-springboot/src/main/java/io/dapr/springboot/DaprRuntime.java b/sdk-springboot/src/main/java/io/dapr/springboot/DaprRuntime.java index d45ad46ec3..322fdb67bd 100644 --- a/sdk-springboot/src/main/java/io/dapr/springboot/DaprRuntime.java +++ b/sdk-springboot/src/main/java/io/dapr/springboot/DaprRuntime.java @@ -57,6 +57,27 @@ public static DaprRuntime getInstance() { return instance; } + /** + * Adds a topic to the list of subscribed topics. + * + * @param pubSubName PubSub name to subscribe to. + * @param topicName Name of the topic being subscribed to. + * @param match Match expression for this route. + * @param priority Priority for this match relative to others. + * @param route Destination route for requests. + * @param metadata Metadata for extended subscription functionality. + */ + public synchronized void addSubscribedTopic(String pubSubName, + String topicName, + String match, + int priority, + String route, + Map metadata) { + this.addSubscribedTopic(pubSubName, topicName, match, priority, route, "", + metadata); + } + + /** * Adds a topic to the list of subscribed topics. * diff --git a/sdk-springboot/src/main/java/io/dapr/springboot/DaprTopicSubscription.java b/sdk-springboot/src/main/java/io/dapr/springboot/DaprTopicSubscription.java index 3c2eef2f98..6d9ee0d3d0 100644 --- a/sdk-springboot/src/main/java/io/dapr/springboot/DaprTopicSubscription.java +++ b/sdk-springboot/src/main/java/io/dapr/springboot/DaprTopicSubscription.java @@ -20,7 +20,6 @@ * Class to represent a subscription topic along with its metadata. */ class DaprTopicSubscription { - private final String pubsubName; private final String topic; private final String route; @@ -31,30 +30,80 @@ class DaprTopicSubscription { /** * Create a subscription topic. - * - * @param pubsubName The pubsub name to subscribe to. - * @param topic The topic to subscribe to. - * @param route Destination route for messages. + * @param pubsubName The pubsub name to subscribe to. + * @param topic The topic to subscribe to. + * @param route Destination route for messages. + * @param metadata Metadata for extended subscription functionality. + */ + DaprTopicSubscription(String pubsubName, String topic, String route, Map metadata) { + this(pubsubName, topic, route, metadata, null); + } + + /** + * Create a subscription topic. + * @param pubsubName The pubsub name to subscribe to. + * @param topic The topic to subscribe to. + * @param route Destination route for messages. * @param deadLetterTopic Name of topic to forward undeliverable messages. - * @param metadata Metdata for extended subscription functionality. + * @param metadata Metadata for extended subscription functionality. */ DaprTopicSubscription(String pubsubName, String topic, String route, String deadLetterTopic, Map metadata) { - this(pubsubName, topic, route, deadLetterTopic, metadata, null); + this(pubsubName, topic, route, deadLetterTopic, null, metadata, null); } /** * Create a subscription topic. - * - * @param pubsubName The pubsub name to subscribe to. - * @param topic The topic to subscribe to. - * @param route Destination route for messages. + * @param pubsubName The pubsub name to subscribe to. + * @param topic The topic to subscribe to. + * @param route Destination route for messages. + * @param metadata Metadata for extended subscription functionality. + * @param bulkSubscribe Bulk subscribe configuration. + */ + DaprTopicSubscription(String pubsubName, String topic, String route, + Map metadata, DaprTopicBulkSubscribe bulkSubscribe) { + this(pubsubName, topic, route, "", null, metadata, bulkSubscribe); + } + + /** + * Create a subscription topic. + * @param pubsubName The pubsub name to subscribe to. + * @param topic The topic to subscribe to. + * @param route Destination route for messages. * @param deadLetterTopic Name of topic to forward undeliverable messages. - * @param metadata Metadata for extended subscription functionality. + * @param metadata Metadata for extended subscription functionality. + * @param bulkSubscribe Bulk subscribe configuration. */ DaprTopicSubscription(String pubsubName, String topic, String route, String deadLetterTopic, Map metadata, DaprTopicBulkSubscribe bulkSubscribe) { - this(pubsubName, topic, route, deadLetterTopic,null, metadata, bulkSubscribe); + this(pubsubName, topic, route, deadLetterTopic, null, metadata, bulkSubscribe); + } + + /** + * Create a subscription topic. + * @param pubsubName The pubsub name to subscribe to. + * @param topic The topic to subscribe to. + * @param route Destination route for messages. + * @param routes Destination routes with rules for messages. + * @param metadata Metadata for extended subscription functionality. + */ + DaprTopicSubscription(String pubsubName, String topic, String route, DaprTopicRoutes routes, + Map metadata) { + this(pubsubName, topic, route, "", routes, metadata, null); + } + + /** + * Create a subscription topic. + * @param pubsubName The pubsub name to subscribe to. + * @param topic The topic to subscribe to. + * @param route Destination route for messages. + * @param deadLetterTopic Name of topic to forward undeliverable messages. + * @param routes Destination routes with rules for messages. + * @param metadata Metadata for extended subscription functionality. + */ + DaprTopicSubscription(String pubsubName, String topic, String route, String deadLetterTopic, DaprTopicRoutes routes, + Map metadata) { + this(pubsubName, topic, route, deadLetterTopic, routes, metadata, null); } /** @@ -63,16 +112,18 @@ class DaprTopicSubscription { * @param pubsubName The pubsub name to subscribe to. * @param topic The topic to subscribe to. * @param route Destination route for messages. - * @param deadLetterTopic Name of topic to forward undeliverable messages. * @param routes Destination routes with rules for messages. * @param metadata Metadata for extended subscription functionality. + * @param bulkSubscribe Bulk subscribe configuration. */ - DaprTopicSubscription(String pubsubName, String topic, String route, String deadLetterTopic, + DaprTopicSubscription(String pubsubName, String topic, String route, DaprTopicRoutes routes, - Map metadata) { - this(pubsubName, topic, route, deadLetterTopic, routes, metadata, null); + Map metadata, + DaprTopicBulkSubscribe bulkSubscribe) { + this(pubsubName, topic, route, "", routes, metadata, bulkSubscribe); } + /** * Create a subscription topic. * @@ -86,7 +137,8 @@ class DaprTopicSubscription { */ DaprTopicSubscription(String pubsubName, String topic, String route, String deadLetterTopic, DaprTopicRoutes routes, - Map metadata, DaprTopicBulkSubscribe bulkSubscribe) { + Map metadata, + DaprTopicBulkSubscribe bulkSubscribe) { this.pubsubName = pubsubName; this.topic = topic; this.route = route; @@ -108,14 +160,14 @@ public String getRoute() { return route; } - public String getDeadLetterTopic() { - return deadLetterTopic; - } - public DaprTopicRoutes getRoutes() { return routes; } + public String getDeadLetterTopic() { + return deadLetterTopic; + } + public Map getMetadata() { return metadata; } diff --git a/sdk-springboot/src/test/java/io/dapr/springboot/DaprRuntimeTest.java b/sdk-springboot/src/test/java/io/dapr/springboot/DaprRuntimeTest.java index dd3cdf8418..e49a5bcda5 100644 --- a/sdk-springboot/src/test/java/io/dapr/springboot/DaprRuntimeTest.java +++ b/sdk-springboot/src/test/java/io/dapr/springboot/DaprRuntimeTest.java @@ -72,11 +72,11 @@ public int priority() { Assert.assertNotNull(runtime); runtime.addSubscribedTopic( - pubSubName, topicName, match, rule.priority(), firstRoute,deadLetterTopic, metadata); + pubSubName, topicName, match, rule.priority(), firstRoute, deadLetterTopic, metadata); // Supplying the same pubsub bits but a different route should fail runtime.addSubscribedTopic( - pubSubName, topicName, match, rule.priority(), secondRoute,deadLetterTopic, metadata); + pubSubName, topicName, match, rule.priority(), secondRoute, deadLetterTopic, metadata); }