我正在使用带有ruby-amqp gem的rails。它与rails app本身一起工作正常,但是android java客户端无法接收消息。
android客户端基于此 http://simonwdixon.wordpress.com/2011/06/03/getting-started-with-rabbitmq-on-android-part-1/
mConsumer = new MessageConsumer("192.168.1.123", "nodes.metadata", "fanout");
我的ruby实现基于此
EventMachine.next_tick do
connection = AMQP.connect(:host => '127.0.0.1')
channel = AMQP::Channel.new(connection)
exchange = channel.fanout("nodes.metadata")
channel.queue("joe", :auto_delete => true).bind(exchange).subscribe do |payload|
puts "#{payload} => joe"
end
channel.queue("aaron", :auto_delete => true).bind(exchange).subscribe do |payload|
puts "#{payload} => aaron"
end
channel.queue("bob", :auto_delete => true).bind(exchange).subscribe do |payload|
puts "#{payload} => bob"
end
exchange.publish("BOS")
# disconnect & exit after 2 seconds
EventMachine.add_timer(2) do
exchange.delete
# connection.close { EventMachine.stop }
end
end
当我运行它时工作正常我在终端获得发布消息但是 当android正在监听rabbitmq时,我没有在终端中得到消息,而且android也没有收到消息。我将android中的rabbitmq与我电脑的ip地址连接起来
答案 0 :(得分:0)
问题出在这个
mModel.exchangeDeclare(mExchange,MyExchangeType,true);
将其更改为
mModel.exchangeDeclare(mExchange,MyExchangeType)(不是被动交换); ref https://groups.google.com/forum/#!topic/rabbitmq-discuss/hCtGUefIcRg
然后从ruby代码中删除了exchange.delete(因为删除了交换,你只会收到一条消息)