Class: JSCommander::StompProxy
- Inherits:
-
Object
- Object
- JSCommander::StompProxy
- Defined in:
- lib/jscmd/stompproxy.rb
Overview
This broker proxy should be instantiated in each process.
Instance Method Summary collapse
-
#initialize(url = nil) ⇒ StompProxy
constructor
A new instance of StompProxy.
- #send(name, msg) ⇒ Object
- #subscribe(name, &proc) ⇒ Object
- #unsubscribe(name, subscriber) ⇒ Object
Constructor Details
#initialize(url = nil) ⇒ StompProxy
Returns a new instance of StompProxy.
4 5 6 7 8 9 |
# File 'lib/jscmd/stompproxy.rb', line 4 def initialize(url = nil) require "stomp" url = "stomp://localhost:61613/" if url.nil? @stomp = Stomp::Client.new(url) end |
Instance Method Details
#send(name, msg) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/jscmd/stompproxy.rb', line 28 def send(name, msg) headers = {} msg.attributes.each do |key, value| headers["jscmd." + key] = value end @stomp.send("/topic/#{name}", msg.body || "", headers) end |
#subscribe(name, &proc) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/jscmd/stompproxy.rb', line 11 def subscribe(name, &proc) @stomp.subscribe("/topic/#{name}") do |msg| attributes = {} msg.headers.each do |key, value| if key =~ /^jscmd\.(.*)/ attributes[$1] = value end end proc.call(Message.new(msg.body, attributes)) end proc end |
#unsubscribe(name, subscriber) ⇒ Object
24 25 26 |
# File 'lib/jscmd/stompproxy.rb', line 24 def unsubscribe(name, subscriber) @stomp.unsubscribe("/topic/#{name}") end |