1
我的應用程序中有一些基於優先級的任務。我有兩個隊列「隊列1」和「隊列2」,我想給隊列1最高優先級和隊列2最低優先級。我設置隊列1的優先級號碼是255,隊列2的優先級號碼是200.我在執行任務時遇到問題,一旦執行優先級任務,進程正在等待,直到任務完成同步。但根據我們的項目需求,這個過程不應該等待,而是要開始。我如何實現它?RabbitMQ 3.5和消息優先級隊列進程正在等待,直到任務完成
我審閱this博客,
收到的消息部分:
final CountDownLatch latch = new CountDownLatch(3);
ch.basicConsume(QUEUE, true, new DefaultConsumer(ch) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties, byte[] body) throws IOException {
System.out.println("Received " + new String(body));
latch.countDown();
}
});
latch.await();
我已經在RabbitMQ的https://pamlesleylu.wordpress.com/2013/02/02/hello-world-for-spring-amqp-and-rabbitmq/
監製完成這一過程,而不優先級隊列
public void execute() {
System.out.println("execute...");
messageQueue.convertAndSend("hello " + counter.incrementAndGet());
}
消費者
public void onMessage(Message msg) {
System.out.println(new String(msg.getBody()));
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}