Subscriptions

Subscribing to a Topic

  • Clients must set up subscriptions for each topic Rize enables. Subscription requests must include the prefix “/topic/” ahead of the topic name. For example: /topic/acme-widgets.sandbox.transactions
  • The example below, taken from the ruby Stomp gem documentation (here and here), demonstrates one method for setting up a subscription. Other methods are possible, depending on your choice of protocol and implementation language.
  • Rows 19 and 20 in the example capture the Rize provided username and password values. The host and port values depend on the protocol Clients select.
  • Row 30 demonstrates the “/topic/topic_name” syntax.

Unsubscribing from a Topic

  • Clients can unsubscribe from topics by submitting an unsubscribe request as outlined on line 42 of the example below.
A recent experience suggested that we might provide an example of how
to establish a "durable" topic subscription using ActiveMQ.
This code attemps to do that. 
References:
http:activemq.apache.org/stomp.html
http:activemq.apache.org/how-does-a-queue-compare-to-a-topic.html
http:activemq.apache.org/how-do-durable-queues-and-topics-work.html
Specifically, locate the section titled: ActiveMQ extensions to Stomp.
There are two programmatic requirements:
1) On CONNECT, indicate to AMQ the code will be using durable topic 
subscription(s).
Done by providing a "client-id" CONNECT header.
2) On SUBSCRIBE, indicate an AMQ specific (unique) subscription ID. Done
by providing a "activemq.subscriptionName" header to SUBSCRIBE.
=end

# login hash
hash = { :host => [
             {:login => login(), :passcode => passcode(), :host => host(), :port()
            :ssl => true}, #
     ],
     :reliable => true,
                                     :closed_check => false,
     :connect_headers => {:host => "localhost", :"accept-version" => "1.2",
         # Requirement 1, name should be unique.
       :"client-id" => "dursubcli01", # REF the 1st AMQ link above
                                     }
   }
# The topic 
topic = "/topic/topicName"

# Establish the client connection
cli = Stomp::Client.open(hash)
# SUBSCRIBE Headers
sh = {"activemq.subscriptionName" => "subname01" } # REF the 1st AMQ link above
# And the client subscribe
cli.subscribe(topic, sh) do |msg|
    puts "msg: #{msg}"
end

# Unsubscribe when we are done subscribing for now:
cli.unsubscribe(topic)