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

Instance Method Summary collapse

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


198
199
200
# File 'lib/em/protocols/stomp.rb', line 198

def ack msgid
  send_frame "ACK", 'message-id'=> msgid
end

#connect(parms = {}) ⇒ Object

CONNECT command, for authentication

connect :login => 'guest', :passcode => 'guest'


159
160
161
# File 'lib/em/protocols/stomp.rb', line 159

def connect parms={}
  send_frame "CONNECT", parms
end

#receive_msg(msg) ⇒ Object

Invoked with an incoming Stomp::Message received from the STOMP server


151
152
153
# File 'lib/em/protocols/stomp.rb', line 151

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'


167
168
169
# File 'lib/em/protocols/stomp.rb', line 167

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


175
176
177
# File 'lib/em/protocols/stomp.rb', line 175

def subscribe dest, ack=false
  send_frame "SUBSCRIBE", {:destination=>dest, :ack=>(ack ? "client" : "auto")}
end