Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • for a queue, receive is the standard JMS receive method. for topic, a blocking call 
  • for topics, the receive() method is a blocking operation that create a 'temporary subscription'. The 'temporary subscription' wait for the first message and then unsubscribe and return the message. If a 'within' expiry time is provided, the 'temporary subscription' will be unsubscribed when the 'within' time is reached, and return null. This feature is typically used with message selector, and is useful for simulating a synchronous operation with the asynchronous JMS infrastructure. e.g. a client use a new thread to send a request with some delay, and in the main thread listen to the server response topic in synchronous manner.
    Code Block
    def pool = new JMSPool()
    pool.send toQueue:'chatService',message:\[user:'groovy100',room:100\],delay:500 //it sends a message in another thread, the delay is avoid getting a result before the subscribed to the topic
    def result = pool.receive fromTopic:'signedOnBroadcast',messageSelector:"newUser = 'groovy100'"
    if (result) // you have successfully signed on
    else // retry? or tell user to sign in again.
    

...