Rabbitmq使用者持久性消息 [英] Rabbitmq consumer for persistence message

查看:84
本文介绍了Rabbitmq使用者持久性消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我已经宣布了一个包含以下参数的队列。

Hi,

I have declared a queue with following parametrs.

channel.exchangeDeclare(EXCHANGE_NAME, ExchangeType.DIRECT.getExchangeName(), true);

Map<String, Object> args = new HashMap<String, Object>();
args.put("x-queue-mode", "lazy");

// First Queue
channel.queueDeclare(QUEUE_NAME_1, false, true, false, args);
channel.queueBind(QUEUE_NAME_1, EXCHANGE_NAME, ROUTING_KEY_1);



发送数据时:


While sending data :

channel.basicPublish(DirectExchange.EXCHANGE_NAME, DirectExchange.ROUTING_KEY_1, MessageProperties.PERSISTENT_TEXT_PLAIN, MESSAGE_1.getBytes());



正确存储在本地磁盘及其控制中也可以重新启动服务器。



但是当我启动我的消费者时,它不会消耗配置队列中可用的数据。



以下代码我用于消费者:


Its properly storing in the local disk as well as its holding post server restart also.

But When I start my consumer its not consuming the data which is available inside the configure queue.

Following code I am using for the consumer:

Connection conn = RabbitMQConnection.getConnection();
if (conn != null)
{
Channel channel = conn.createChannel();
// Consumer reading from queue 1
Consumer consumer1 = new DefaultConsumer(channel)
{
    @Override
    public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException
    {
	String message = new String(body, "UTF-8");
	System.out.println(" Message Received Queue 1 '" + message + "'");
    }
};
channel.basicConsume(DirectExchange.QUEUE_NAME_1, false, consumer1);



请帮我解决此问题。



谢谢,



我尝试了什么:



我曾尝试过以上消费者。但它没有用。


Kindly help me on this to resolve this issue.

Thanks,

What I have tried:

I have tried with above consumer. But its not working.

推荐答案

根据代码,队列被作为独占队列,因此您需要使用与消费者相同的连接。



您需要使用Durable队列。
As per the code the queue was made as exclusive queue, so you need to use the same connection to consumer.

You need to use the Durable queue for this .


这篇关于Rabbitmq使用者持久性消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆