Ticket #30: rabbitc.rb

File rabbitc.rb, 0.6 kB (added by tmm1, 1 year ago)
Line 
1 require 'eventmachine'
2
3 class StompClient < EM::Connection
4   include EM::Protocols::Stomp
5
6   def connection_completed
7     connect :login => 'guest', :passcode => 'guest'
8   end
9
10   def receive_msg msg
11     if msg.command == "CONNECTED"
12       subscribe '/some/topic'
13     else
14       p ['got a message', msg]
15       puts msg.body
16     end
17   end
18
19   def receive_data data
20     log data.split("\n").map{|l| ">> #{l}"}
21     super
22   end
23  
24   def send_data data
25     log data.split("\n").map{|l| "<< #{l}"}
26     super
27   end
28
29   private
30  
31   def log msg
32     puts msg
33   end
34 end
35
36 EM.kqueue
37 EM.run{
38   EM.connect 'localhost', 61613, StompClient
39 }