Class: MessageDriver::Adapters::StompAdapter

Inherits:
Base
  • Object
show all
Defined in:
lib/message_driver/adapters/stomp_adapter.rb

Defined Under Namespace

Classes: Destination, Message, StompContext

Instance Attribute Summary collapse

Attributes inherited from Base

#broker

Instance Method Summary collapse

Methods inherited from Base

#contexts, #new_context, #reset_after_tests

Constructor Details

#initialize(broker, config) ⇒ StompAdapter

Returns a new instance of StompAdapter.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/message_driver/adapters/stomp_adapter.rb', line 31

def initialize(broker, config)
  validate_stomp_version

  @broker = broker
  @config = config.symbolize_keys
  connect_headers = @config[:connect_headers] ||= {}
  connect_headers.symbolize_keys
  connect_headers[:"accept-version"] = '1.1,1.2'

  vhost = @config.delete(:vhost)
  connect_headers[:host] = vhost if vhost

  @poll_timeout = 1
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



29
30
31
# File 'lib/message_driver/adapters/stomp_adapter.rb', line 29

def config
  @config
end

#poll_timeoutObject (readonly)

Returns the value of attribute poll_timeout.



29
30
31
# File 'lib/message_driver/adapters/stomp_adapter.rb', line 29

def poll_timeout
  @poll_timeout
end

Instance Method Details

#build_contextObject



90
91
92
# File 'lib/message_driver/adapters/stomp_adapter.rb', line 90

def build_context
  StompContext.new(self)
end

#stopObject



101
102
103
104
# File 'lib/message_driver/adapters/stomp_adapter.rb', line 101

def stop
  super
  @connection.disconnect if @connection
end

#with_connectionObject



94
95
96
97
98
99
# File 'lib/message_driver/adapters/stomp_adapter.rb', line 94

def with_connection
  @connection ||= open_connection
  yield @connection
rescue SystemCallError, IOError => e
  raise MessageDriver::ConnectionError.new(e)
end