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

Inherits:
BasePublisher
  • Object
show all
Defined in:
lib/rrj/rabbit/publish/publisher.rb

Overview

This publisher send and read an message in queues

Author:

Direct Known Subclasses

PublishNonExclusive, PublisherAdmin

Instance Attribute Summary

Attributes inherited from BasePublisher

#response, #responses

Instance Method Summary collapse

Constructor Details

#initialize(exchange) ⇒ Publisher

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/publish/publisher.rb', line 16

def initialize(exchange)
  super()
  @exchange = exchange.default_exchange
  @message = nil
rescue
  raise Errors::Rabbit::Publish::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/publish/publisher.rb', line 30

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