Simple utilities to achieve various AMQP tasks.
Daemon
AMQPHelpers::Daemon
allows you to build a simple message consumer.
Example
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.
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