Module: EventMachine::Protocols::Stomp
- Includes:
- LineText2
- Defined in:
- lib/em/protocols/stomp.rb
Overview
Implements Stomp (http://docs.codehaus.org/display/STOMP/Protocol).
== Usage example
module StompClient include EM::Protocols::Stomp
def connection_completed connect :login => 'guest', :passcode => 'guest' end
def receive_msg msg if msg.command == "CONNECTED" subscribe '/some/topic' else p ['got a message', msg] puts msg.body end end end
EM.run{ EM.connect 'localhost', 61613, StompClient }
Defined Under Namespace
Classes: Message
Constant Summary
Constants included from LineText2
LineText2::MaxBinaryLength, LineText2::MaxLineLength
Instance Method Summary collapse
-
#ack(msgid) ⇒ Object
ACK command, for acknowledging receipt of messages.
-
#connect(parms = {}) ⇒ Object
CONNECT command, for authentication.
-
#receive_msg(msg) ⇒ Object
Invoked with an incoming Stomp::Message received from the STOMP server.
-
#send(destination, body, parms = {}) ⇒ Object
SEND command, for publishing messages to a topic.
-
#subscribe(dest, ack = false) ⇒ Object
SUBSCRIBE command, for subscribing to topics.
Methods included from LineText2
#receive_data, #receive_end_of_binary_data, #set_binary_mode, #set_delimiter, #set_line_mode, #set_text_mode, #unbind
Instance Method Details
#ack(msgid) ⇒ Object
ACK command, for acknowledging receipt of messages
module StompClient include EM::P::Stomp
def connection_completed connect :login => 'guest', :passcode => 'guest' # subscribe with ack mode subscribe '/some/topic', true end
def receive_msg msg if msg.command == "MESSAGE" ack msg.headers['message-id'] puts msg.body end end end
195 196 197 |
# File 'lib/em/protocols/stomp.rb', line 195 def ack msgid send_frame "ACK", 'message-id'=> msgid end |
#connect(parms = {}) ⇒ Object
CONNECT command, for authentication
connect :login => 'guest', :passcode => 'guest'
156 157 158 |
# File 'lib/em/protocols/stomp.rb', line 156 def connect parms={} send_frame "CONNECT", parms end |
#receive_msg(msg) ⇒ Object
Invoked with an incoming Stomp::Message received from the STOMP server
148 149 150 |
# File 'lib/em/protocols/stomp.rb', line 148 def receive_msg msg # stub, overwrite this in your handler end |
#send(destination, body, parms = {}) ⇒ Object
SEND command, for publishing messages to a topic
send '/topic/name', 'some message here'
164 165 166 |
# File 'lib/em/protocols/stomp.rb', line 164 def send destination, body, parms={} send_frame "SEND", parms.merge( :destination=>destination ), body.to_s end |
#subscribe(dest, ack = false) ⇒ Object
SUBSCRIBE command, for subscribing to topics
subscribe '/topic/name', false
172 173 174 |
# File 'lib/em/protocols/stomp.rb', line 172 def subscribe dest, ack=false send_frame "SUBSCRIBE", {:destination=>dest, :ack=>(ack ? "client" : "auto")} end |