Module: EventMachine::Protocols::Stomp

### Home Classes Methods

### In Files

- lib/em/protocols/stomp.rb

### Namespace

- CLASS EventMachine::Protocols::Stomp::Message

### Methods

- #ack
- #connect
- #init_message_reader
- #receive_binary_data
- #receive_line
- #receive_msg
- #send
- #send_frame
- #subscribe

### Included Modules

- EventMachine::Protocols::LineText2

### Files

- ChangeLog
- DEFERRABLES
- EPOLL
- INSTALL
- KEYBOARD
- LEGAL
- LIGHTWEIGHT_CONCURRENCY
- PURE_RUBY
- RELEASE_NOTES
- SMTP
- SPAWNED_PROCESSES
- TODO

### Class/Module Index

Quicksearch

- EventMachine
- EventMachine
- EventMachine::Channel
- EventMachine::Completion
- EventMachine::Connection
- EventMachine::DNS
- EventMachine::DNS::Request
- EventMachine::DNS::RequestIdAlreadyUsed
- EventMachine::DNS::Resolver
- EventMachine::DNS::Socket
- EventMachine::DatagramObject
- EventMachine::DefaultDeferrable
- EventMachine::Deferrable
- EventMachine::DeferrableChildProcess
- EventMachine::Error
- EventMachine::EvmaKeyboard
- EventMachine::EvmaTCPClient
- EventMachine::EvmaTCPServer
- EventMachine::EvmaUDPSocket
- EventMachine::EvmaUNIXClient
- EventMachine::EvmaUNIXServer
- EventMachine::FileNotFoundException
- EventMachine::FileStreamer
- EventMachine::FileWatch
- EventMachine::Iterator
- EventMachine::LoopbreakReader
- EventMachine::PeriodicTimer
- EventMachine::Pool
- EventMachine::ProcessWatch
- EventMachine::Protocols
- EventMachine::Protocols
- EventMachine::Protocols::HeaderAndContentProtocol
- EventMachine::Protocols::HttpClient
- EventMachine::Protocols::HttpClient2
- EventMachine::Protocols::HttpClient2::Request
- EventMachine::Protocols::LineAndTextProtocol
- EventMachine::Protocols::LineProtocol
- EventMachine::Protocols::LineText2
- EventMachine::Protocols::Memcache
- EventMachine::Protocols::Memcache::ParserError
- EventMachine::Protocols::ObjectProtocol
- EventMachine::Protocols::Postgres3
- EventMachine::Protocols::SASLauth
- EventMachine::Protocols::SASLauthclient
- EventMachine::Protocols::SmtpClient
- EventMachine::Protocols::SmtpServer
- EventMachine::Protocols::Socks4
- EventMachine::Protocols::Stomp
- EventMachine::Protocols::Stomp::Message
- EventMachine::Protocols::TcpConnectTester
- EventMachine::Queue
- EventMachine::Reactor
- EventMachine::Selectable
- EventMachine::SpawnedProcess
- EventMachine::StreamObject
- EventMachine::SystemCmd
- EventMachine::ThreadedResource
- EventMachine::TickLoop
- EventMachine::Timer
- EventMachine::UuidGenerator
- EventMachine::YieldBlockFromSpawnedProcess
- Object
- Object::EM
- Object::P
- BufferedTokenizer
- IO
- StringIO
- TestConnection

No matching classes.

# EventMachine::Protocols::Stomp

Implements Stomp (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
    }

### Public Instance Methods

ack(msgid) click to toggle source

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

    # File lib/em/protocols/stomp.rb, line 198
    def ack msgid
      send_frame "ACK", 'message-id'=> msgid
    end

connect(parms={}) click to toggle source

CONNECT command, for authentication

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

    # File lib/em/protocols/stomp.rb, line 159
    def connect parms={}
      send_frame "CONNECT", parms
    end

init_message_reader() click to toggle source

@private

    # File lib/em/protocols/stomp.rb, line 143
    def init_message_reader
      @stomp_initialized = true
      set_delimiter "\n"
      set_line_mode
      @stomp_message = Message.new
    end

receive_binary_data(data) click to toggle source

@private

    # File lib/em/protocols/stomp.rb, line 136
    def receive_binary_data data
      @stomp_message.body = data[0..-2]
      receive_msg(@stomp_message) if respond_to?(:receive_msg)
      init_message_reader
    end

receive_line(line) click to toggle source

@private

    # File lib/em/protocols/stomp.rb, line 121
    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 "\00""
        elsif outcome.first == :dispatch
          receive_msg(@stomp_message) if respond_to?(:receive_msg)
          init_message_reader
        end
      }
    end

receive_msg(msg) click to toggle source

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

    # File lib/em/protocols/stomp.rb, line 151
    def receive_msg msg
      # stub, overwrite this in your handler
    end

send(destination, body, parms={}) click to toggle source

SEND command, for publishing messages to a topic

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

    # File lib/em/protocols/stomp.rb, line 167
    def send destination, body, parms={}
      send_frame "SEND", parms.merge( :destination=>destination ), body.to_s
    end

send_frame(verb, headers={}) click to toggle source

@private

    # File lib/em/protocols/stomp.rb, line 106
    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 << "\00""
      send_data ary.join
    end

subscribe(dest, ack=false) click to toggle source

SUBSCRIBE command, for subscribing to topics

    subscribe '/topic/name', false

    # File lib/em/protocols/stomp.rb, line 175
    def subscribe dest, ack=false
      send_frame "SUBSCRIBE", {:destination=>dest, :ack=>(ack ? "client" : "auto")}
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.