title: Rabbitmq - AMQP GEM: Not able to publish messages on multiple exchanges
body: <p>In my ROR application, I have the requirement where I need to consume the messages from one exchange and then publish the same to another exhange after appending of some additional data to headers. So I have created an rake task to start the AMQP.</p>
  
  <pre><code>     EventMachine.run do
          $configurations = Config.new.config
         rmq_configurations = Config.new.rmq
          connection = AMQP.connect(rmq_configurations)
          $channel  = AMQP::Channel.new(connection)
          puts "AMQP listening"
          worker   = MessageHandler.new
          puts "Message handler started"
          worker.start
        end
  </code></pre>
  
  <p>And in the Message handler class, I have defined the exchanges as like below</p>
  
  <pre><code>     def initialize
           @ns_exchange = $configurations["ns_exchange"]
           @sc_exchange = $configurations["sc_exchange"]
           @ns_queue = $configurations["ns_queue"]
           @sc_queue = $configurations["sc_queue"]
         end
  
  
      def start
        @ns_x = $channel.direct(ns_exchange, :durable =&gt; true)
        @sc_x = $channel.direct(sc_exchange, :durable =&gt; true)
        @ns_queue   = $channel.queue(ns_queue, :auto_delete =&gt; true)
        @ns_queue.bind(@ns_x, :routing_key =&gt; "ipam").subscribe(&amp;method(:handle_ns_message))
        message_headers = {"messageType" =&gt; "ipam/operations/ip/checkCanAllocateIP"}
        message_body = {"ipsToAllocate" =&gt; "1", "orgId" =&gt; "438c6cdd-aa2d-4f3c-bec3-aefb85d6fca5"}
        @ns_x.publish(message_body,  :routing_key =&gt; "ipam", :headers =&gt; message_headers, :mandatory =&gt; true)
  
        @sc_queue   = ch2.queue(sc_queue, :auto_delete =&gt; true)
        @sc_queue.bind(@sc_x, :routing_key =&gt; @sc_queue.name).subscribe(&amp;method(:handle_sc_message))
       @sc_x.publish(message_body,  :routing_key =&gt; "ipam", :headers =&gt; message_headers, :mandatory =&gt; true)
       end
  </code></pre>
  
  <p>Publishing is working only if I have one exchange. Also I never want to close the connection since AMQP needs to run always to consume &amp; produce the message</p>