Skip to content

Commit

Permalink
Ability to pass 'properties' to Bunny session
Browse files Browse the repository at this point in the history
With this change we will be able to define a `properties` property in
the `Sneakers` configuration, that will be passed to `Bunny` when a
connection is created.

```ruby
Sneakers.configure({
  amqp: 'amqp://guest:guest@localhost:5672',
  properties: {
    key: "value",
    key2: "value2"
  }
})
```

This can be useful, for example, to identify where a connection is
coming from, when we have dozens of applications using a `RabbitMQ` instance.

This is something that can already be done with `Bunny`:

```ruby
Bunny.new(connection_string, { properties: { key: 'value' } })
```

So we are just leveraging that functionality when the connection is
created from `Sneakers`.
  • Loading branch information
brianstorti committed Apr 12, 2017
1 parent e93a8cf commit 90fd20f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lib/sneakers/publisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ def connected?
end

def create_bunny_connection
Bunny.new(@opts[:amqp], :vhost => @opts[:vhost], :heartbeat => @opts[:heartbeat], :logger => Sneakers::logger)
Bunny.new(@opts[:amqp], :vhost => @opts[:vhost],
:heartbeat => @opts[:heartbeat],
:properties => @opts[:properties],
:logger => Sneakers::logger)
end
end
end

5 changes: 4 additions & 1 deletion lib/sneakers/queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ def unsubscribe
end

def create_bunny_connection
Bunny.new(@opts[:amqp], :vhost => @opts[:vhost], :heartbeat => @opts[:heartbeat], :logger => Sneakers::logger)
Bunny.new(@opts[:amqp], :vhost => @opts[:vhost],
:heartbeat => @opts[:heartbeat],
:properties => @opts[:properties],
:logger => Sneakers::logger)
end
private :create_bunny_connection
end
3 changes: 2 additions & 1 deletion spec/sneakers/publisher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
exchange: 'another_exchange',
exchange_options: { :type => :topic, :arguments => { 'x-arg' => 'value' } },
log: logger,
properties: { key: "value" },
durable: false)

channel = Object.new
Expand All @@ -86,7 +87,7 @@
mock(bunny).start
mock(bunny).create_channel { channel }

mock(Bunny).new('amqp://someuser:somepassword@somehost:5672', heartbeat: 1, vhost: '/', logger: logger) { bunny }
mock(Bunny).new('amqp://someuser:somepassword@somehost:5672', heartbeat: 1, vhost: '/', logger: logger, properties: { key: "value" }) { bunny }

p = Sneakers::Publisher.new

Expand Down

0 comments on commit 90fd20f

Please sign in to comment.