Book Image

RabbitMQ Essentials

By : David Dossot
Book Image

RabbitMQ Essentials

By: David Dossot

Overview of this book

Table of Contents (17 chapters)

Calling the authentication service


If you remember the initial use case, CCM wants to interact with the authentication service from the Ruby-on-Rails back office application. Therefore, you will implement the client in Ruby. The code you came up with is reproduced as follows:

channel  = AMQP::Channel.new(connection)

channel.on_error do |ch, channel_close|
  connection.close { EventMachine.stop }
  raise "Channel error: #{channel_close.inspect()}"
end

channel.headers(
       'internal-services',
       :durable     => true,
       :auto_delete => false,
       :passive     => true) do |exchange|

  channel.queue('',
    :exclusive => true,
    :durable => false,
    :auto_delete => true) do |response_queue|

    response_queue.subscribe do |metadata, payload|
      handle_response(metadata.content_type, payload)
    end

    puts "Response queue created: #{response_queue.name}"
    message_id = SecureRandom.uuid
    message_json = JSON.generate({
       :username =>...