module EventMachine::Protocols::Stomp

def ack msgid


end
end
end
puts msg.body
ack msg.headers['message-id']
if msg.command == "MESSAGE"
def receive_msg msg

end
subscribe '/some/topic', true
# subscribe with ack mode
connect :login => 'guest', :passcode => 'guest'
def connection_completed

include EM::P::Stomp
module StompClient

ACK command, for acknowledging receipt of messages
def ack msgid
  send_frame "ACK", 'message-id'=> msgid
end

def connect parms={}


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

CONNECT command, for authentication
def connect parms={}
  send_frame "CONNECT", parms
end

def init_message_reader

Other tags:
    Private: -
def init_message_reader
  @stomp_initialized = true
  set_delimiter "\n"
  set_line_mode
  @stomp_message = Message.new
end

def receive_binary_data data

Other tags:
    Private: -
def receive_binary_data data
  @stomp_message.body = data[0..-2]
  receive_msg(@stomp_message) if respond_to?(:receive_msg)
  init_message_reader
end

def receive_line line

Other tags:
    Private: -
def receive_line line
  @stomp_initialized || init_message_reader
  @stomp_message.consume_line(line) {|outcome|
    if outcome.first == :sized_text
      set_text_mode outcome[1]
    elsif outcome.first == :unsized_text
      set_delimiter "\0"
    elsif outcome.first == :dispatch
      receive_msg(@stomp_message) if respond_to?(:receive_msg)
      init_message_reader
    end
  }
end

def receive_msg msg

Invoked with an incoming Stomp::Message received from the STOMP server
def receive_msg msg
  # stub, overwrite this in your handler
end

def send destination, body, parms={}


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

SEND command, for publishing messages to a topic
def send destination, body, parms={}
  send_frame "SEND", parms.merge( :destination=>destination ), body.to_s
end

def send_frame verb, headers={}, body=""

Other tags:
    Private: -
def send_frame verb, headers={}, body=""
  body = body.to_s
  ary = [verb, "\n"]
  body_bytesize = body.bytesize if body.respond_to? :bytesize
  body_bytesize ||= body.size
  headers.each {|k,v| ary << "#{k}:#{v}\n" }
  ary << "content-length: #{body_bytesize}\n"
  ary << "content-type: text/plain; charset=UTF-8\n" unless headers.has_key? 'content-type'
  ary << "\n"
  ary << body
  ary << "\0"
  send_data ary.join
end

def subscribe dest, ack=false


subscribe '/topic/name', false

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