Try PubSub+

Consuming from a topic

petegehrmanpetegehrman Member Posts: 34 ✭✭

There seem to be 2 ways of consuming messages from a topic with the JCSMP client:
1. Add a topic subscription directly to your session, then create a message consumer
2. Create a topic & topic endpoint (non-durable in my case), then create a flow receiver to the topic
Can anyone explain the difference between the 2 approaches, and when to use each one?
Thanks!

Comments

  • TomFTomF Member, Employee Posts: 279 Solace Employee

    Hi @petegehrman,

    Sure thing:
    1. This is for messages delivered to your consumer with the DIRECT quality of Service. If your consumer is offline, it won't get messages;
    2. Note: you don't create a "Topic," you create a Topic Endpoint with a subscription. This is a JMS concept. The Topic Endpoint persists messages, so if your consumer is offline messages build up on the Topic Endpoint and are then delivered to your consumer when it comes online. Messages are never lost. Generally, it's better not to use Topic Endpoints and use Queues;
    3. Queues. A persistent message store, so again if your consumer is offline messages build up and are then delivered to your consumer when it comes online. Messages are never lost. Queues can subscribe to topics.

    See this explanation of message durability. Then see this explanation of queues subscribing to topics.

  • petegehrmanpetegehrman Member Posts: 34 ✭✭
    edited October 6 #3

    Thanks Tom, I'm confused about this sample JCSMP code in SimpleFlowToTopic.java:
    Can you explain what the non-durable topic endpoint and temporary topic are?

    // Create Topic Endpoints and Topics to receive messages.
                TopicEndpoint topicEndpoint;
                Topic topic;
                if (useDurable) {
                    topicEndpoint = JCSMPFactory.onlyInstance().createDurableTopicEndpointEx(SampleUtils.SAMPLE_TOPICENDPOINT);
                    topic = JCSMPFactory.onlyInstance().createTopic(SampleUtils.SAMPLE_TOPIC);
                } else {
                    // Creating non-durable Topic Endpoint and temporary Topic.
                    topicEndpoint = session.createNonDurableTopicEndpoint();
                    topic = session.createTemporaryTopic();
                }
    
          // Create and start the receiver.
          receiver = session.createFlow(topicEndpoint, topic, this);
          receiver.start();
    
  • TomFTomF Member, Employee Posts: 279 Solace Employee

    @petegehrman, the TopicEndpoint object is an API object representing a Topic Endpoint on your message broker. It can be to used to create ("provision") a Topic Endpoint on the broker itself. It may be that you already have a Topic Endpoint on the broker, in which case you still need a TopicEndpoint API object.

    The Topic API object is an API representation of a topic. There is no one to one mapping between an API topic and a message topic: the Topic API object can be used to create a topic on a message you're about to publish, and/or it can be used to create a subscription to that topic.

    Durability relates to what happens when the application disconnects. A durable Topic Endpoint will remain on the broker until deleted. A non-durable Topic Endpoint will be deleted after a delay (1 minute, AFAIK) after the application that created it disconnects.

    A gentle reminder: if you're using JCSMP and you're not using JMS you almost certainly don't want to use Topic Endpoints, durable or otherwise. If you're using JMS and you're not using an existing JMS architecture you probably don't want to use Topic Endpoints.

  • nramnram Member, Employee Posts: 66 Solace Employee

    Hi @petegehrman ,
    Topic subscriber provides no delivery guarantee. If the broker runs out of resources or if the subscriber is busy, messages are dropped (there is still underlying TCP delivery guarantee)
    Non-Durable topic subscriber: As long as the client is connected, there is delivery guarantee. Once the client disconnects, the temporary endpoint is deleted (after some delay). So if messages are published after the client disconnects, they are lost.
    Durable topic subscriber: Once created, the endpoint persists until deleted manually. Messages are persisted even when the client goes offline after endpoint is created.
    You may find this blog post a good read.
    https://solace.com/blog/solace-endpoints-durable-vs-non-durable/

  • petegehrmanpetegehrman Member Posts: 34 ✭✭

    Thanks very much for the clarification everyone. It looks like I was doing things correctly ... since I'm not using JMS, I'll stick to using a topic subscriber.

  • nirodha23nirodha23 Member Posts: 2

    @TomF
    Would you please let me know where the sample JCSMP code in SimpleFlowToTopic.java can be accessed.
    I want to subscribe to Durable Topic Endpoint. But my code is not working. Would you please provide a sample code.

Sign In or Register to comment.