Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: Synchronous jmsTemplate with topics

  1. #11
    Join Date
    Jun 2012
    Posts
    19

    Default

    Quote Originally Posted by Gary Russell View Post
    As I said, receive() on a topic has issues, because the consumer only lives within its scope, when it returns there is no consumer; if someone publishes another message while you are processing the current one, you will miss it. Use execute() with the SessionCallback as I described above.

    A Queue has no such issues. Is there some reason you need to use a topic rather than a queue for this? Do you have a requirement for multiple consumers to get a message?

    The DefaultMessageListenerContainer has a clientId property - use setClientId().
    I originally used queues & it worked fine but then I found out that there will be multiple consumers for this message so I have no choice but to use topics.
    I will use the execute then - Do I call jmsTemplate.execute whenever I am ready to get messages?

    I saw the setClientId - but how do I have that value when I am instantiating it from the applicationContext.xml? where does the client id get generated?

  2. #12
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,020

    Default

    You should call execute() when your application needs to. You won't see any messages until you call it, and create the consumer.


    The client id is simply a unique identifier for the client, so the broker can maintain state for it (such as durable subscription to a topic)



    You can either set it on the connection factory (preferred) or on the listener container bean.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  3. #13
    Join Date
    Jun 2012
    Posts
    19

    Default

    Thanks alot for all you help with this - since I am new to spring I appreciate it very much - I ended up going the MessageListenerContainer - works alot better & cleaner like you had advised earlier - Since I set the clientID on the connectionFactory it is now durable so the consumer is there on the start of my service. I just maintain a static class to hold all the messages for when the client wants it.

    In regard to the synchronous way even when I called execute I got the following message:
    WARNING: Received a message on a connection which is not yet started. Have you forgotten to call Connection.start()?
    Was I supposed to set additional properties in the jmsTemplate for recieving data? Is there a way to set the subscription durable with synchronouse to have the consumer there on start of the application like the messageListener is?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •