Well, I just read the documentation and found the section on publishing one-off messages:
So the code as follows now works:
def publish_message_to_direct(server_params, exchange, payload)
AMQP.start(server_params) do |connection|
channel = AMQP::Channel.new(connection)
exchange = channel.direct(exchange,:durable=>true)
exchange.publish(payload, :nowait => false) do
puts payload
connection.close do
EM.stop
end
end
end
end
Apparently, the difference was adding the closing event inside a block passed to the publish function and using the option :nowait => false
. Hope this helps someone else with the same question.