Class: Stomp::Client

### Home Classes Methods

### In Files

- lib/client/utils.rb
- lib/stomp/client.rb

### Parent

Object

### Methods

- ::new
- ::open
- #abort
- #acknowledge
- #autoflush
- #autoflush=
- #begin
- #close
- #closed?
- #commit
- #connection_frame
- #disconnect_receipt
- #hbrecv_count
- #hbrecv_interval
- #hbsend_count
- #hbsend_interval
- #join
- #jruby?
- #nack
- #open?
- #poll
- #protocol
- #publish
- #running
- #set_logger
- #sha1
- #subscribe
- #unreceive
- #unsubscribe
- #uuid
- #valid_utf8?

### Files

- CHANGELOG.rdoc
- LICENSE

### Class/Module Index

Quicksearch

- Stomp
- Stomp::Client
- Stomp::Connection
- Stomp::Error
- Stomp::Error::ConnectReadTimeout
- Stomp::Error::DuplicateSubscription
- Stomp::Error::InvalidFormat
- Stomp::Error::InvalidHeartBeatHeaderError
- Stomp::Error::InvalidMessageLength
- Stomp::Error::InvalidServerCommand
- Stomp::Error::LoggerConnectionError
- Stomp::Error::MalformedFailoverOptionsError
- Stomp::Error::MaxReconnectAttempts
- Stomp::Error::MessageIDRequiredError
- Stomp::Error::NilMessageError
- Stomp::Error::NoCurrentConnection
- Stomp::Error::PacketParsingTimeout
- Stomp::Error::ProtocolError11p
- Stomp::Error::ProtocolErrorConnect
- Stomp::Error::SSLClientParamsError
- Stomp::Error::SSLNoCertFileError
- Stomp::Error::SSLNoKeyFileError
- Stomp::Error::SSLNoTruststoreFileError
- Stomp::Error::SSLUnreadableCertFileError
- Stomp::Error::SSLUnreadableKeyFileError
- Stomp::Error::SSLUnreadableTruststoreFileError
- Stomp::Error::SocketOpenTimeout
- Stomp::Error::StompServerError
- Stomp::Error::SubscriptionRequiredError
- Stomp::Error::UTF8ValidationError
- Stomp::Error::UnsupportedProtocolError
- Stomp::HeaderCodec
- Stomp::Message
- Stomp::SSLParams
- Client11Example1
- Client11PutGet1
- Connection11Example1
- Connection11Example2
- ExampleConsumer
- ExamplePublisher
- ExampleRubyCiphers
- ExampleSSL1
- ExampleSSL1C
- ExampleSSL2
- ExampleSSL2C
- ExampleSSL3
- ExampleSSL3C
- ExampleSSL4
- ExampleSSL4C
- ExampleTopicConsumer
- ExampleTopicPublisher
- Hash
- HeartBeatExample1
- LoggerExample
- Object
- Publish11Example1
- Receive11Example1
- Receive11Example2
- RepeatedHeadersExample
- SSLLoggerExample
- Slogger
- Stomp11Common
- TestBase
- TestClient
- TestConnection
- TestConnection1P
- TestMessage
- TestSSL
- TestURLLogins
- Tlogger

No matching classes.

# Stomp::Client

Typical Stomp client class. Uses a listener thread to receive frames from the server, any thread can send.

Receives all happen in one thread, so consider not doing much processing in that thread if you have much message volume.

### Attributes

parameters[R]

Parameters hash

### Public Class Methods

new(login = '', passcode = '', host = 'localhost', port = 61613, reliable = false, autoflush = false) click to toggle source

A new Client object can be initialized using three forms:

Hash (this is the recommended Client initialization method):

    hash = {
      :hosts => [
        {:login => "login1", :passcode => "passcode1", :host => "localhost", :port => 61616, :ssl => false},
        {:login => "login2", :passcode => "passcode2", :host => "remotehost", :port => 61617, :ssl => false}
      ],
      :reliable => true,
      :initial_reconnect_delay => 0.01,
      :max_reconnect_delay => 30.0,
      :use_exponential_back_off => true,
      :back_off_multiplier => 2,
      :max_reconnect_attempts => 0,
      :randomize => false,
      :connect_timeout => 0,
      :connect_headers => {},
      :parse_timeout => 5,
      :logger => nil,
      :dmh => false,
      :closed_check => true,
      :hbser => false,
      :stompconn => false,
      :usecrlf => false,
      :max_hbread_fails => 0,
      :max_hbrlck_fails => 0,
      :fast_hbs_adjust => 0.0,
      :connread_timeout => 0,
    }

    e.g. c = Stomp::Client.new(hash)

Positional parameters:

    login     (String,  default : '')
    passcode  (String,  default : '')
    host      (String,  default : 'localhost')
    port      (Integer, default : 61613)
    reliable  (Boolean, default : false)

    e.g. c = Stomp::Client.new('login', 'passcode', 'localhost', 61613, true)

Stomp URL :

    A Stomp URL must begin with 'stomp://' and can be in one of the following forms:

    stomp://host:port
    stomp://host.domain.tld:port
    stomp://login:passcode@host:port
    stomp://login:passcode@host.domain.tld:port

    e.g. c = Stomp::Client.new(urlstring)

    # File lib/stomp/client.rb, line 74
    def initialize(login = '', passcode = '', host = 'localhost', port = 61613, reliable = false, autoflush = false)
      parse_hash_params(login) ||
        parse_stomp_url(login) ||
        parse_failover_url(login) ||
        parse_positional_params(login, passcode, host, port, reliable)

      check_arguments!()

      @id_mutex = Mutex.new()
      @ids = 1

      create_connection(autoflush)

      start_listeners()

    end

open(login = '', passcode = '', host = 'localhost', port = 61613, reliable = false) click to toggle source

open is syntactic sugar for 'Client.new', see 'initialize' for usage.

    # File lib/stomp/client.rb, line 98
    def self.open(login = '', passcode = '', host = 'localhost', port = 61613, reliable = false)
      Client.new(login, passcode, host, port, reliable)
    end

### Public Instance Methods

abort(name, headers = {}) click to toggle source

Abort aborts work in a transaction by name.

    # File lib/stomp/client.rb, line 114
    def abort(name, headers = {})
      @connection.abort(name, headers)

      # replay any ack'd messages in this transaction
      replay_list = @replay_messages_by_txn[name]
      if replay_list
        replay_list.each do |message|
          if listener = find_listener(message)
            listener.call(message)
          end
        end
      end
    end

acknowledge(message, headers = {}) click to toggle source

Acknowledge a message, used when a subscription has specified client acknowledgement ( connection.subscribe("/queue/a",{:ack => 'client'}). Accepts a transaction header ( :transaction => 'some_transaction_id' ).

    # File lib/stomp/client.rb, line 161
    def acknowledge(message, headers = {})
      txn_id = headers[:transaction]
      if txn_id
        # lets keep around messages ack'd in this transaction in case we rollback
        replay_list = @replay_messages_by_txn[txn_id]
        if replay_list.nil?
          replay_list = []
          @replay_messages_by_txn[txn_id] = replay_list
        end
        replay_list << message
      end
      if block_given?
        headers['receipt'] = register_receipt_listener lambda {|r| yield r}
      end
      if protocol() == Stomp::SPL_12
        @connection.ack(message.headers['ack'], headers)
      else
        @connection.ack(message.headers['message-id'], headers)
      end
    end

autoflush() click to toggle source

autoflush returns the current connection's autoflush setting.

    # File lib/stomp/client.rb, line 297
    def autoflush()
      @connection.autoflush()
    end

autoflush=(af) click to toggle source

autoflush= sets the current connection's autoflush setting.

    # File lib/stomp/client.rb, line 292
    def autoflush=(af)
      @connection.autoflush = af
    end

begin(name, headers = {}) click to toggle source

Begin starts work in a a transaction by name.

    # File lib/stomp/client.rb, line 109
    def begin(name, headers = {})
      @connection.begin(name, headers)
    end

close(headers={}) click to toggle source

close frees resources in use by this client. The listener thread is terminated, and disconnect on the connection is called.

    # File lib/stomp/client.rb, line 230
    def close(headers={})
      @listener_thread.exit
      @connection.disconnect(headers)
    end

closed?() click to toggle source

close? tests if this client connection is closed.

    # File lib/stomp/client.rb, line 219
    def closed?()
      @connection.closed?()
    end

commit(name, headers = {}) click to toggle source

Commit commits work in a transaction by name.

    # File lib/stomp/client.rb, line 129
    def commit(name, headers = {})
      txn_id = headers[:transaction]
      @replay_messages_by_txn.delete(txn_id)
      @connection.commit(name, headers)
    end

connection_frame() click to toggle source

Return the broker's CONNECTED frame to the client. Misnamed.

    # File lib/stomp/client.rb, line 204
    def connection_frame()
      @connection.connection_frame
    end

disconnect_receipt() click to toggle source

Return any RECEIPT frame received by DISCONNECT.

    # File lib/stomp/client.rb, line 209
    def disconnect_receipt()
      @connection.disconnect_receipt
    end

hbrecv_count() click to toggle source

hbrecv_count returns the current connection's heartbeat receive count.

    # File lib/stomp/client.rb, line 281
    def hbrecv_count()
      @connection.hbrecv_count()
    end

hbrecv_interval() click to toggle source

hbrecv_interval returns the connection's heartbeat receive interval.

    # File lib/stomp/client.rb, line 271
    def hbrecv_interval()
      @connection.hbrecv_interval()
    end

hbsend_count() click to toggle source

hbsend_count returns the current connection's heartbeat send count.

    # File lib/stomp/client.rb, line 276
    def hbsend_count()
      @connection.hbsend_count()
    end

hbsend_interval() click to toggle source

hbsend_interval returns the connection's heartbeat send interval.

    # File lib/stomp/client.rb, line 266
    def hbsend_interval()
      @connection.hbsend_interval()
    end

join(limit = nil) click to toggle source

join the listener thread for this client, generally used to wait for a quit signal.

    # File lib/stomp/client.rb, line 104
    def join(limit = nil)
      @listener_thread.join(limit)
    end

jruby?() click to toggle source

jruby? tests if the connection has detcted a JRuby environment

    # File lib/stomp/client.rb, line 224
    def jruby?()
      @connection.jruby
    end

nack(message_id, headers = {}) click to toggle source

Stomp 1.1+ NACK.

    # File lib/stomp/client.rb, line 183
    def nack(message_id, headers = {})
      @connection.nack(message_id, headers)
    end

open?() click to toggle source

open? tests if this client connection is open.

    # File lib/stomp/client.rb, line 214
    def open?
      @connection.open?()
    end

poll() click to toggle source

Poll for asynchronous messages issued by broker. Return nil of no message available, else the message

    # File lib/stomp/client.rb, line 287
    def poll()
      @connection.poll()
    end

protocol() click to toggle source

protocol returns the current client's protocol level.

    # File lib/stomp/client.rb, line 246
    def protocol()
      @connection.protocol()
    end

publish(destination, message, headers = {}) click to toggle source

Publishes message to destination. If a block is given a receipt will be requested and passed to the block on receipt. Accepts a transaction header ( :transaction => 'some_transaction_id' ).

    # File lib/stomp/client.rb, line 196
    def publish(destination, message, headers = {})
      if block_given?
        headers['receipt'] = register_receipt_listener lambda {|r| yield r}
      end
      @connection.publish(destination, message, headers)
    end

running() click to toggle source

running checks if the thread was created and is not dead.

    # File lib/stomp/client.rb, line 236
    def running()
      @listener_thread && !!@listener_thread.status
    end

set_logger(logger) click to toggle source

set_logger identifies a new callback logger.

    # File lib/stomp/client.rb, line 241
    def set_logger(logger)
      @connection.set_logger(logger)
    end

sha1(data) click to toggle source

sha1 returns a SHA1 sum of a given string.

    # File lib/stomp/client.rb, line 256
    def sha1(data)
      @connection.sha1(data)
    end

subscribe(destination, headers = {}) click to toggle source

Subscribe to a destination, must be passed a block which will be used as a callback listener. Accepts a transaction header ( :transaction => 'some_transaction_id' ).

    # File lib/stomp/client.rb, line 138
    def subscribe(destination, headers = {})
      raise "No listener given" unless block_given?
      # use subscription id to correlate messages to subscription. As described in
      # the SUBSCRIPTION section of the protocol: http://stomp.github.com/.
      # If no subscription id is provided, generate one.
      set_subscription_id_if_missing(destination, headers)
      if @listeners[headers[:id]]
        raise "attempting to subscribe to a queue with a previous subscription"
      end
      @listeners[headers[:id]] = lambda {|msg| yield msg}
      @connection.subscribe(destination, headers)
    end

unreceive(message, options = {}) click to toggle source

Unreceive a message, sending it back to its queue or to the DLQ.

    # File lib/stomp/client.rb, line 188
    def unreceive(message, options = {})
      @connection.unreceive(message, options)
    end

unsubscribe(name, headers = {}) click to toggle source

Unsubscribe from a subscription by name.

    # File lib/stomp/client.rb, line 152
    def unsubscribe(name, headers = {})
      set_subscription_id_if_missing(name, headers)
      @connection.unsubscribe(name, headers)
      @listeners[headers[:id]] = nil
    end

uuid() click to toggle source

uuid returns a type 4 UUID.

    # File lib/stomp/client.rb, line 261
    def uuid()
      @connection.uuid()
    end

valid_utf8?(s) click to toggle source

valid_utf8? validates any given string for UTF8 compliance.

    # File lib/stomp/client.rb, line 251
    def valid_utf8?(s)
      @connection.valid_utf8?(s)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.