Class: Urabbit::Publisher
- Inherits:
-
Object
- Object
- Urabbit::Publisher
- Defined in:
- lib/urabbit/publisher.rb
Overview
Usage: begin
pubisher = Publisher.new(
exchange_name: "courier_tracker",
routing_key: "in.courier_statuses.created"
)
publisher.publish()
rescue Publisher::Error => exception
puts exception.
puts exception.cause
end
Message is usually a JSON. Exception can contain a cause raised from Bunny.
Instance Method Summary collapse
-
#initialize(opts) ⇒ Publisher
constructor
A new instance of Publisher.
- #publish(message) ⇒ Object
Constructor Details
#initialize(opts) ⇒ Publisher
Returns a new instance of Publisher.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/urabbit/publisher.rb', line 16 def initialize(opts) exchange_type = opts[:exchange_type] || :topic exchange_name = opts[:exchange_name] || raise(Urabbit::Error.new("Please provide an 'exchange_name'")) @routing_key = opts[:routing_key] || raise(Urabbit::Error.new("Please provide a 'routing_key'")) @channel = Urabbit.create_channel @exchange = Bunny::Exchange.new( @channel, exchange_type, exchange_name, durable: true ) rescue Bunny::Exception raise Urabbit::Error.new("Error connecting to queue") end |