Class: Banter::Publisher
- Inherits:
-
Object
- Object
- Banter::Publisher
- Defined in:
- lib/banter/publisher.rb
Constant Summary collapse
- @@publisher =
nil
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#publisher ⇒ Object
readonly
Returns the value of attribute publisher.
Class Method Summary collapse
Instance Method Summary collapse
- #delay_messages ⇒ Object
- #enable(value) ⇒ Object
-
#initialize(exchange = nil) ⇒ Publisher
constructor
A new instance of Publisher.
- #publish(context, key, payload) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(exchange = nil) ⇒ Publisher
Returns a new instance of Publisher.
15 16 17 18 19 20 |
# File 'lib/banter/publisher.rb', line 15 def initialize(exchange = nil) @exchange = exchange || Banter::Configuration.exchange_name @disabled = false @batch_messages = false @stack_depth = 0 end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
4 5 6 |
# File 'lib/banter/publisher.rb', line 4 def channel @channel end |
#publisher ⇒ Object (readonly)
Returns the value of attribute publisher.
3 4 5 |
# File 'lib/banter/publisher.rb', line 3 def publisher @publisher end |
Class Method Details
Instance Method Details
#delay_messages ⇒ Object
27 28 29 30 31 32 |
# File 'lib/banter/publisher.rb', line 27 def delay_start yield ensure delay_execute end |
#enable(value) ⇒ Object
22 23 24 25 |
# File 'lib/banter/publisher.rb', line 22 def enable(value) @disabled = !value @disabled end |
#publish(context, key, payload) ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/banter/publisher.rb', line 60 def publish(context, key, payload) routing_key = "#{@exchange}.#{key}" envelope = ::Banter::Message.new.serialize(context, key, payload) if @batch_messages (routing_key, envelope) else execute_publish(routing_key, envelope) end end |
#start ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/banter/publisher.rb', line 34 def start unless Configuration.push_enabled @disabled = true return end # grab server configuration from initialization file somewhere begin @connection = Bunny.new(Configuration.connection) @connection.start @channel = @connection.create_channel @publisher = @channel.topic(@exchange, :durable => true, :auto_delete => false) rescue => e Airbrake.notify(e, parameters: { message: e. }, environment_name: ENV['RAILS_ENV']) return end @publisher.on_return do |return_info, properties, content| # contents are already transformed into message that we want to send Banter::RabbitLogger.failed_publish(return_info[:routing_key], properties, Hashie::Mash.new(::JSON.parse(content))) end end |