Class: Legion::Transport::Exchange
- Inherits:
-
Exchange
- Object
- Exchange
- Legion::Transport::Exchange
show all
- Includes:
- Common
- Defined in:
- lib/legion/transport/exchange.rb
Instance Method Summary
collapse
Methods included from Common
#channel_open?, #close, #close!, #deep_merge, #generate_consumer_tag, #open_channel, #options_builder
Constructor Details
#initialize(exchange = exchange_name, options = {}) ⇒ Exchange
Returns a new instance of Exchange.
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/legion/transport/exchange.rb', line 8
def initialize(exchange = exchange_name, options = {})
@options = options
@type = options[:type] || default_type
super(channel, @type, exchange, options_builder(default_options, exchange_options, @options))
rescue Legion::Transport::CONNECTOR::PreconditionFailed, Legion::Transport::CONNECTOR::ChannelAlreadyClosed
raise unless @retries.nil?
@retries = 1
delete_exchange(exchange)
retry
end
|
Instance Method Details
#default_options ⇒ Object
26
27
28
29
30
31
32
33
|
# File 'lib/legion/transport/exchange.rb', line 26
def default_options
hash = Concurrent::Hash.new
hash[:durable] = true
hash[:auto_delete] = false
hash[:arguments] = {}
hash[:passive] = passive?
hash
end
|
#default_type ⇒ Object
54
55
56
|
# File 'lib/legion/transport/exchange.rb', line 54
def default_type
'topic'
end
|
#delete(options = {}) ⇒ Object
47
48
49
50
51
52
|
# File 'lib/legion/transport/exchange.rb', line 47
def delete(options = {})
super
true
rescue Legion::Transport::CONNECTOR::PreconditionFailed
false
end
|
#delete_exchange(exchange) ⇒ Object
20
21
22
23
24
|
# File 'lib/legion/transport/exchange.rb', line 20
def delete_exchange(exchange)
Legion::Transport.logger.warn "Exchange:#{exchange} exists with wrong parameters, deleting and creating"
@channel = Legion::Transport::Connection.channel
@channel.exchange_delete(exchange)
end
|
#exchange_name ⇒ Object
39
40
41
|
# File 'lib/legion/transport/exchange.rb', line 39
def exchange_name
self.class.ancestors.first.to_s.split('::')[2].downcase
end
|
#exchange_options ⇒ Object
43
44
45
|
# File 'lib/legion/transport/exchange.rb', line 43
def exchange_options
Concurrent::Hash.new
end
|
#passive? ⇒ Boolean
35
36
37
|
# File 'lib/legion/transport/exchange.rb', line 35
def passive?
false
end
|