Module: LontaraUtilities::RMQ::Client
- Defined in:
- lib/lontara_utilities/rmq/client.rb,
lib/lontara_utilities/rmq/client/publisher.rb,
lib/lontara_utilities/rmq/client/rpc_producer.rb
Overview
Base module for RMQ client.
Defined Under Namespace
Classes: Publisher, RPCProducer
Class Method Summary collapse
- .publish(request) ⇒ Object
-
.start(url: ENV['RABBITMQ_URL'], client: 'RPCProducer', **options) ⇒ Object
Client interface for RMQ Publisher or RPC Publisher.
- .stop ⇒ Object
Class Method Details
.publish(request) ⇒ Object
43 44 45 |
# File 'lib/lontara_utilities/rmq/client.rb', line 43 def publish(request) @client.publish { request } end |
.start(url: ENV['RABBITMQ_URL'], client: 'RPCProducer', **options) ⇒ Object
Client interface for RMQ Publisher or RPC Publisher.
Start client by giving url and queue name. Parameter client must be ‘RPCProducer` or `Publisher`. If parameter not defined, default is `RPCProducer`.
**Use ‘Publisher` if no need to listen the request’s responses.**
Options params are:
-
‘default_exchange: (default: true)`
That option is changing the way Connection object is created. If set to ‘false`, connection object didn’t create exchange, also connection.exchange property will be ‘nil`.
-
‘queue:`,
-
‘reply_queue: (default: ’amq.rabbitmq.reply-to’)‘
(Reply queue is only applicable if ‘client` is `RPCProducer`).
These options only applicable if ‘default_exchange` is `false`, and `client` is `Publisher` (exchange created inside consumer).
- `exchange:`
- `exchange_type: (default: :direct)`
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/lontara_utilities/rmq/client.rb', line 29 def start(url: ENV['RABBITMQ_URL'], client: 'RPCProducer', **) parameter_validator(client, ) client_opts = client_opts_assigner(client, ) conn_opts = %i[exchange exchange_type] client = Object.const_get("LontaraUtilities::RMQ::Client::#{client}") @connection = Connection.new(url:, **.slice(*conn_opts)) @client = client.new(@connection, **client_opts) self end |
.stop ⇒ Object
47 48 49 |
# File 'lib/lontara_utilities/rmq/client.rb', line 47 def stop @connection.close end |