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();
}
}