RabbitMQ: How to specify the queue to publish to?

前端 未结 3 964
逝去的感伤
逝去的感伤 2021-02-08 01:43

RabbitMQ\'s Channel#basicConsume method gives us the following arguments:

channel.basicConsume(queueName, autoAck, consumerTag, noLocal,
    exclusi         


        
3条回答
  •  再見小時候
    2021-02-08 02:23

    Basically queues can be binded to an exchange based on routingKeys.

    Assume that you have 3 different publishers.
    Publisher1 sending message to exchange with routingKey "events"
    Publisher2 sending message to exchange with routingKey "tasks"
    Publisher3 sending message to exchange with routingKey "jobs"

    You can have a consumer that consumes only messages with specific routhingKey.
    For example in order to have a consumer for "events" messages you declare like this

     channel.queueBind(queueName, exchangeName, "events");
    

    If you want to consume all the messages coming to the exchange you give the routing as '#'

    So in short what i can say is,
    1. Messages will be published to an exchange.
    2. Queues will be bound to exchange based on routingKeys.
    3. RabbitMQ will forward messages with matching routing keys to the corresponding queues.

    Please see the tutorial - http://www.rabbitmq.com/tutorials/tutorial-three-java.html

    The core idea in the messaging model in RabbitMQ is that the producer never sends any messages directly to a queue. Actually, quite often the producer doesn't even know if a message will be delivered to any queue at all. Instead, the producer can only send messages to an exchange

提交回复
热议问题