Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ninech/amqp_helpers

Simple helpers to achieve various AMQP tasks.
https://github.com/ninech/amqp_helpers

Last synced: about 1 month ago
JSON representation

Simple helpers to achieve various AMQP tasks.

Awesome Lists containing this project

README

        

# amqp_helpers [![Build Status](https://travis-ci.org/ninech/amqp_helpers.svg)](https://travis-ci.org/ninech/amqp_helpers)

Simple utilities to achieve various AMQP tasks.

## Daemon

`AMQPHelpers::Daemon` allows you to build a simple message consumer.

### Example

``` ruby
AMQPHelpers::Daemon.new({
name: 'nba-scores-daemon',
environment: 'production',
logger: PXEConfGen.logger,
connection_params: {
host: 'localhost',
port: 5672
},
queue_params: { durable: false },
exchanges: {
'nba.scores': {
params: {
type: :topic,
durable: false
},
bindings: [
{ routing_key: 'north.#' },
{ routing_key: 'south.#' }
]
}
}
}).start do |delivery_info, payload|
puts "AMQP Incoming message #{payload}"
end
```

## Publisher

`AMQPHelpers::Publisher` allows you to publish an AMQP message in an easy way.

### Example

It takes the same configuration hash as the daemon does.
* First argument of publish is the payload which will be JSON encoded.
* Second arugment specifies the exchange configuration which should be used.
* Third argument defines the routing key.

```ruby
publisher = AMQPHelpers::Publisher.new({
name: 'nba-scores-daemon',
environment: 'production',
logger: PXEConfGen.logger,
connection_params: {
host: 'localhost',
port: 5672
},
queue_params: { durable: false },
exchanges: {
'nba.scores': {
params: {
type: :topic,
durable: false
},
bindings: [
{ routing_key: 'north.#' },
{ routing_key: 'south.#' }
]
}
})

publisher.publish('1:1', 'nba.scores', 'south.east') # => true
```