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"
    '/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

MaxBinaryLength, MaxLineLength

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

- (Object) ack(msgid)

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
  '/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

- (Object) connect(parms = {})

CONNECT command, for authentication

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



156
# File 'lib/em/protocols/stomp.rb', line 156

def connect parms={}

- (Object) receive_msg(msg)

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

- (Object) send(destination, body, parms = {})

SEND command, for publishing messages to a topic

send '/topic/name', 'some message here'



164
# File 'lib/em/protocols/stomp.rb', line 164

def send destination, body, parms={}

- (Object) subscribe(dest, ack = false)

SUBSCRIBE command, for subscribing to topics

subscribe '/topic/name', false



172
173
174
# File 'lib/em/protocols/stomp.rb', line 172

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