java - Rabbit MQ - why my setup not provide messages to all clients? -
java - Rabbit MQ - why my setup not provide messages to all clients? -
i have code in jruby:
class receiver def initialize(channel_id) @channel_id = channel_id mill = 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
this code responsible getting messages in architecture. however, when have ie. 2 instances of receiver
same channel_id (which exchange name, , route key) when send message exchange 1 message goes 1 receiver, 1 another. why, wrong?
the question why want have acted on 2 agents simultaneously subscribed single queue? in rabbitmq, multiple agents can subscribed 1 queue same thing , redundancy/load balancing purposes. random agent picks message queue , acks clears beingness consumed else.
usually queue implies 1 action , agents listening equivalent , can pick on message. if want have message go 1 place broadcasted multiple agents, preferable utilize fanout exchange , have each agent hear on separate queue.
so think of each queue if doing 1 thing. behavior describing intended.
please see this tutorial details on setting fanout exchange , different exchanges do.
java ruby jruby rabbitmq
Comments
Post a Comment