Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>RabbitMQ discards messages if their routing key doesn't match any queues bound to the exchange. When you start <code>MQSender</code> first, no queues are bound, so the messages it sends are lost. When you start <code>MQReceiver</code>, it binds queues to the exchange, so RabbitMQ has a place to put the message from <code>MQSender</code>. When you stop MQReceiver, since you created an anonymous queue, the queue and all bindings are removed from the exchange.</p> <p>If you want messages to be stored on the server while <code>MQReceiver</code> is not running, you need the receiver to create a named queue, and bind the routing keys to that queue. Note that creating a named queue is idempotent, and the queue won't be created if it already exists. Then you need the receiver to pull messages off the named queue. </p> <p>Change your code to look something like this:</p> <p><strong>MQSender</strong></p> <pre><code>.... String namedQueue = "logqueue"; //declare named queue and bind log level routing keys to it. //RabbitMQ will put messages with matching routing keys in this queue channel.queueDeclare(namedQueue, false, false, false, null); for (int level = 0; level &lt; LOG_LEVELS.length; level++) { channel.queueBind(namedQueue, EXCHANGE_NAME, LOG_LEVELS[level]); } ... </code></pre> <p><strong>MQReceiver</strong></p> <pre><code>... channel.exchangeDeclare(EXCHANGE_NAME, "direct"); QueueingConsumer consumer = new QueueingConsumer(channel); //Consume messages off named queue instead of anonymous queue String namedQueue = "logqueue"; channel.basicConsume(namedQueue, true, consumer); while(true) { ... </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload