Search code examples
javasolace

Can I subscribe to a durable topic endpoint using wildcards in Solace using Java?


The idea is to send messages to topic and consume them in stripes via pub/sub only (without queues) and using PERSISTENT delivery mode. For simplicity, lets say producer(s) publish messages to specific topics having the following hierarchy: bus/<componentId/<transactionId>.

Consumers want to receive topic "stripes", for simplicity lets say there are 10 consumers and they want to stripe traffic among themselves by transactionId:

  • bus/*/0*
  • bus/*/1*
  • ...
  • bus/*/9*

When I try to subscribe to topic endpoint using wildcards, like this:

    DurableTopicEndpoint topicEndpoint = JCSMPFactory.onlyInstance().createDurableTopicEndpoint("bus/*/1*");

    ConsumerFlowProperties propsFlow = new ConsumerFlowProperties();
    propsFlow.setEndpoint(topicEndpoint);

I get the following exception:

Exception in thread "main" java.lang.IllegalArgumentException: Topic Endpoint name "bus/*/1*" contains illegal character [*]
    at com.solacesystems.common.util.DestinationUtil.isValidEndpointName(DestinationUtil.java:234)
    at com.solacesystems.common.util.DestinationUtil.isValidTopicEndpointPhysicalName(DestinationUtil.java:209)
    at com.solacesystems.common.util.DestinationUtil.isValidDTEPhysicalName(DestinationUtil.java:213)
    at com.solacesystems.jcsmp.impl.SessionModeSupport.createFlow(SessionModeSupport.java:247)
    at com.solacesystems.jcsmp.impl.SessionModeSupport.createFlow(SessionModeSupport.java:170)
    at com.solacesystems.jcsmp.impl.JCSMPBasicSession.createFlow(JCSMPBasicSession.java:953)

In the light of this article's section "Adding Subscriptions to Topic Endpoints" - is it at all possible with Solace Java API?


Solution

  • There are two problems here.

    1. You are trying to create an TopicEndpoint named bus/*/1*. Note that this is the name of the TopicEndpoint and not the topic that it is subscribing to. * is not a valid character for the name of a TopicEndpoint.

    2. TopicEndpoints are only allowed to have one subscription. This means that you can only subscribe to bus/*/0*. If you want to subscribe to bus/*/0* all the way to bus/*/9* you will need to make use of a Queue instead of a TopicEndpoint.