我在 JRuby 中有代码:
class Receiver
def initialize(channel_id)
@channel_id = channel_id
factory = ConnectionFactory.new
factory.setHost("localhost")
connection = factory.newConnection
@channel = connection.createChannel
@channel.exchangeDeclare(exchange_name, "direct");
@channel.queueDeclare(queue_name, true, false, false, nil)
@channel.queueBind(queue_name, exchange_name, routing_key)
@consumer = QueueingConsumer.new(@channel);
@channel.basicConsume(queue_name, true, @consumer);
end
def receive
String.from_java_bytes @consumer.nextDelivery.getBody
end
private
def queue_name
@channel_id
end
def exchange_name
@channel_id
end
def routing_key
@channel_id
end
end
此代码负责在我的架构中获取消息。但是,当我有 ie。当我向此交换机发送消息时,具有相同 channel_id 的两个实例Receiver
(基本上是交换机名称和路由密钥),一条消息发送给一个接收者,一个发送给另一个接收者。为什么,我做错了什么?