RabbitMQ使用者不使用Java中的消息

时间:2018-12-03 07:51:38

标签: rabbitmq

我已经用Java编写了Rabit MQ使用者。可以稳定运行1天。然后,rabbitmq使用者停止使用该消息,并且RabbitMQ管理控制台中没有与队列有关的使用者。

channel = Rabbitconn.createChannel();
channel.basicQos(20);
// Consumer reading from queue 1
com.rabbitmq.client.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");

    if( ProcessData(message, connMySQL, 1, 1) == true)
    {
    channel.basicAck(envelope.getDeliveryTag(), true);
    System.out.println(envelope.getRoutingKey()+" - Processing completed and Acknowledged for Message: "+message);
    }
    else
    {
    System.out.println(envelope.getRoutingKey() +" - Sending Nack for Message:"+message);
    channel.basicNack(envelope.getDeliveryTag(), false ,true);
    try
    {
        Thread.sleep(1000*5);
    }
    catch(Exception ex)
    {

    }
    }
}


};
//strGroupName  will consider as the queue name
channel.basicConsume(QueueName, false, consumer1);

while (true)
{
Thread.sleep(Long.MAX_VALUE);
}

0 个答案:

没有答案