Class: RubyRabbitmqJanus::Rabbit::Publisher::Base

Inherits:
BaseEvent
  • Object
show all
Defined in:
lib/rrj/rabbit/publisher/base.rb

Overview

This publisher send and read an message in queues

Author:

Direct Known Subclasses

Admin, Exclusive, Keepalive, NonExclusive

Instance Attribute Summary

Attributes inherited from BaseEvent

#response, #responses

Instance Method Summary collapse

Constructor Details

#initialize(exchange) ⇒ Base

Intialize a publisher for sending and reading a message

Parameters:

  • exchange (String)

    Determine type exchange used for all transaction between gem and rabbitmq



16
17
18
19
20
21
22
# File 'lib/rrj/rabbit/publisher/base.rb', line 16

def initialize(exchange)
  super()
  @exchange = exchange.default_exchange
  @message = nil
rescue
  raise Errors::Rabbit::Publisher::Base::Initialize
end

Instance Method Details

#publish(request) ⇒ Object

Publish an message in queue

Parameters:

  • request (String)

    JSON request sending to rabbitmq queue

Raises:

  • (Errors::RabbitPublishMessage)

    If request is false the execption is calling



30
31
32
33
34
35
36
# File 'lib/rrj/rabbit/publisher/base.rb', line 30

def publish(request)
  @message = request
  @exchange.publish(@message.to_json,
                    request.options.merge!(reply_to: reply.name))
rescue
  raise Errors::Rabbit::Publisher::Base::Publish
end