examples/ruby/topic-broadcast-with-unsubscribe.rb
author Tony Garnock-Jones <tonyg@lshift.net>
Tue Sep 09 13:36:11 2008 +0100 (2008-09-09)
changeset 52 8972d204473a
child 237 1001ca6867cf
permissions -rw-r--r--
More ruby examples: broadcasting, unsubscribing
tonyg@52
     1
require 'rubygems'
tonyg@52
     2
require 'stomp' # this is a gem
tonyg@52
     3
require 'uuidtools' # this is a gem
tonyg@52
     4
tonyg@52
     5
conn = Stomp::Connection.open('guest', 'guest', 'localhost')
tonyg@52
     6
subid = UUID.random_create.to_s
tonyg@52
     7
puts "Subscribing to #{subid}..."
tonyg@52
     8
conn.subscribe('', :id => subid, :exchange => 'amq.topic', :routing_key => "x.#")
tonyg@52
     9
puts 'Receiving...'
tonyg@52
    10
mesg = conn.receive
tonyg@52
    11
puts mesg.body
tonyg@52
    12
puts "Unsubscribing from #{subid}..."
tonyg@52
    13
conn.unsubscribe('', :id => subid)
tonyg@52
    14
puts 'Sleeping 5 seconds...'
tonyg@52
    15
sleep 5