Class: OnStomp::Client
- Inherits:
-
Object
- Object
- OnStomp::Client
- Includes:
- OnStomp::Components::Scopes, Interfaces::ClientConfigurable, Interfaces::ClientEvents, Interfaces::FrameMethods, Interfaces::ReceiptManager, Interfaces::SubscriptionManager
- Defined in:
- lib/onstomp/client.rb,
lib/onstomp/failover/new_with_failover.rb
Overview
This class encapsulates a client connection to a message broker through the Stomp protocol.
Instance Attribute Summary collapse
-
#connection ⇒ OnStomp::Connections::Base
readonly
Connection object specific to the established STOMP protocol version.
-
#ssl ⇒ Symbol => Object
readonly
SSL options for the connection.
-
#uri ⇒ String
readonly
The
URI
reference to the STOMP broker.
Methods you ought not use directly. collapse
-
#dispatch_received(frame) ⇒ Object
Called by #connection when a frame has been read from the socket connection to the STOMP broker.
-
#dispatch_transmitted(frame) ⇒ Object
Called by #connection when a frame has been written to the socket connection to the STOMP broker.
-
#transmit(frame, cbs = {}) ⇒ OnStomp::Components::Frame
Ultimately sends a frame to the STOMP broker.
Class Method Summary collapse
-
.new_with_failover(uri, options = {}) ⇒ OnStomp::Client, OnStomp::Failover::Client
(also: new)
Creates an alias chain for Client.new so that if a failover: URI or an array of URIs are passed to the constructor, a failover client is built instead.
Instance Method Summary collapse
-
#close! ⇒ self
Forces the connection between broker and client closed.
-
#connect(headers = {}) ⇒ self
(also: #open)
Connects to the STOMP broker referenced by #uri.
-
#connected? ⇒ true, false
Returns true if a connection to the broker exists and itself is connected.
-
#disconnect_with_flush(headers = {}) ⇒ OnStomp::Components::Frame
(also: #disconnect)
Sends a DISCONNECT frame to the broker and blocks until the connection has been closed.
-
#heartbeats ⇒ Array<Fixnum>
The client-side heartbeat settings to allow for this connection.
-
#host ⇒ String
The host header value to send to the broker when connecting.
-
#initialize(uri, options = {}) ⇒ Client
constructor
Creates a new client for the specified uri and optional hash of options.
-
#login ⇒ String
The login header value to send to the broker when connecting.
-
#passcode ⇒ String
The passcode header value to send to the broker when connecting.
-
#processor ⇒ Class
The class to use when instantiating a new IO processor for the connection.
-
#versions ⇒ Array<String>
The protocol versions to allow for this connection.
Methods included from OnStomp::Components::Scopes
#transaction, #with_headers, #with_receipt
Methods included from Interfaces::SubscriptionManager
Methods included from Interfaces::ClientEvents
#pending_connection_events, #trigger_after_receiving, #trigger_after_transmitting, #trigger_before_receiving, #trigger_before_transmitting, #trigger_frame_event
Methods included from Interfaces::EventManager
#bind_event, #event_callbacks, included, #trigger_event
Methods included from Interfaces::FrameMethods
#abort, #ack, #beat, #begin, #commit, #nack, #send, #subscribe, #unsubscribe
Methods included from Interfaces::ClientConfigurable
Constructor Details
#initialize(uri, options = {}) ⇒ Client
Creates a new client for the specified uri and optional hash of options.
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/onstomp/client.rb', line 53 def initialize uri, ={} @uri = uri.is_a?(::URI) ? uri : ::URI.parse(uri) @ssl = .delete(:ssl) configure_configurable configure_subscription_management configure_receipt_management on_disconnect do |f, con| close unless f[:receipt] end end |
Instance Attribute Details
#connection ⇒ OnStomp::Connections::Base (readonly)
Connection object specific to the established STOMP protocol version
21 22 23 |
# File 'lib/onstomp/client.rb', line 21 def connection @connection end |
#ssl ⇒ Symbol => Object (readonly)
SSL options for the connection
18 19 20 |
# File 'lib/onstomp/client.rb', line 18 def ssl @ssl end |
#uri ⇒ String (readonly)
The URI
reference to the STOMP broker
15 16 17 |
# File 'lib/onstomp/client.rb', line 15 def uri @uri end |
Class Method Details
.new_with_failover(uri, options = {}) ⇒ OnStomp::Client, OnStomp::Failover::Client Also known as: new
9 10 11 12 13 14 15 |
# File 'lib/onstomp/failover/new_with_failover.rb', line 9 def new_with_failover(uri, ={}) if uri.is_a?(Array) || uri.to_s =~ /^failover:/i OnStomp::Failover::Client.new(uri, ) else new_without_failover(uri, ) end end |
Instance Method Details
#close! ⇒ self
Use of this method may result in frames never being sent to the broker. This method should only be used if #disconnect is not an option and the connection needs to be terminated immediately.
Forces the connection between broker and client closed.
103 104 105 106 107 |
# File 'lib/onstomp/client.rb', line 103 def close! close processor_inst.stop self end |
#connect(headers = {}) ⇒ self Also known as: open
Connects to the STOMP broker referenced by #uri. Includes optional headers in the CONNECT frame, if specified.
68 69 70 71 72 73 74 75 |
# File 'lib/onstomp/client.rb', line 68 def connect headers={} @connection = OnStomp::Connections.connect self, headers, { :'accept-version' => @versions.join(','), :host => @host, :'heart-beat' => @heartbeats.join(','), :login => @login, :passcode => @passcode }, pending_connection_events processor_inst.start self end |
#connected? ⇒ true, false
Returns true if a connection to the broker exists and itself is connected.
94 95 96 |
# File 'lib/onstomp/client.rb', line 94 def connected? connection && connection.connected? end |
#disconnect_with_flush(headers = {}) ⇒ OnStomp::Components::Frame Also known as: disconnect
Sends a DISCONNECT frame to the broker and blocks until the connection has been closed. This method ensures that all frames not yet sent to the broker will get processed barring any IO exceptions.
83 84 85 86 87 88 |
# File 'lib/onstomp/client.rb', line 83 def disconnect_with_flush headers={} processor_inst.prepare_to_close disconnect_without_flush(headers).tap do processor_inst.join end end |
#dispatch_received(frame) ⇒ Object
Called by #connection when a frame has been read from the socket connection to the STOMP broker.
125 126 127 128 |
# File 'lib/onstomp/client.rb', line 125 def dispatch_received frame trigger_before_receiving frame trigger_after_receiving frame end |
#dispatch_transmitted(frame) ⇒ Object
Called by #connection when a frame has been written to the socket connection to the STOMP broker.
132 133 134 |
# File 'lib/onstomp/client.rb', line 132 def dispatch_transmitted frame trigger_after_transmitting frame end |
#heartbeats ⇒ Array<Fixnum>
The client-side heartbeat settings to allow for this connection
29 |
# File 'lib/onstomp/client.rb', line 29 attr_configurable_client_beats :heartbeats |
#host ⇒ String
The host header value to send to the broker when connecting. This allows the client to inform the server which host it wishes to connect with when multiple brokers may share an IP address through virtual hosting.
35 |
# File 'lib/onstomp/client.rb', line 35 attr_configurable_str :host, :default => 'localhost', :uri_attr => :host |
#login ⇒ String
The login header value to send to the broker when connecting.
39 |
# File 'lib/onstomp/client.rb', line 39 attr_configurable_str :login, :default => '', :uri_attr => :user |
#passcode ⇒ String
The passcode header value to send to the broker when connecting.
43 |
# File 'lib/onstomp/client.rb', line 43 attr_configurable_str :passcode, :default => '', :uri_attr => :password |
#processor ⇒ Class
The class to use when instantiating a new IO processor for the connection. Defaults to OnStomp::Components::ThreadedProcessor
48 |
# File 'lib/onstomp/client.rb', line 48 attr_configurable_processor :processor |
#transmit(frame, cbs = {}) ⇒ OnStomp::Components::Frame
Ultimately sends a frame to the STOMP broker. This method should not be invoked directly. Use the frame methods provided by the Interfaces:FrameMethod interface.
115 116 117 118 119 120 121 |
# File 'lib/onstomp/client.rb', line 115 def transmit frame, cbs={} frame.tap do register_callbacks frame, cbs trigger_before_transmitting frame connection && connection.write_frame_nonblock(frame) end end |
#versions ⇒ Array<String>
The protocol versions to allow for this connection
25 |
# File 'lib/onstomp/client.rb', line 25 attr_configurable_protocols :versions |