Skip to content

Commit

Permalink
Create new methods with deadLetterTopic instead of overload existing …
Browse files Browse the repository at this point in the history
…ones.

Signed-off-by: Charlie Mk <[email protected]>
  • Loading branch information
charlieMk1 committed Apr 25, 2023
1 parent eb6a149 commit ebd66a7
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private static void subscribeToTopics(
List<String> 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);
Expand Down
21 changes: 21 additions & 0 deletions sdk-springboot/src/main/java/io/dapr/springboot/DaprRuntime.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> metadata) {
this.addSubscribedTopic(pubSubName, topicName, match, priority, route, "",
metadata);
}


/**
* Adds a topic to the list of subscribed topics.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> metadata) {
this(pubsubName, topic, route, deadLetterTopic, routes, metadata, null);
}

/**
Expand All @@ -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<String, String> metadata) {
this(pubsubName, topic, route, deadLetterTopic, routes, metadata, null);
Map<String, String> metadata,
DaprTopicBulkSubscribe bulkSubscribe) {
this(pubsubName, topic, route, "", routes, metadata, bulkSubscribe);
}


/**
* Create a subscription topic.
*
Expand All @@ -86,7 +137,8 @@ class DaprTopicSubscription {
*/
DaprTopicSubscription(String pubsubName, String topic, String route, String deadLetterTopic,
DaprTopicRoutes routes,
Map<String, String> metadata, DaprTopicBulkSubscribe bulkSubscribe) {
Map<String, String> metadata,
DaprTopicBulkSubscribe bulkSubscribe) {
this.pubsubName = pubsubName;
this.topic = topic;
this.route = route;
Expand All @@ -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<String, String> getMetadata() {
return metadata;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}

Expand Down

0 comments on commit ebd66a7

Please sign in to comment.