Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

channel.addConfirmListener() , interface ackCallback Some callbacks are missing ?#757

HongJian-Yang started this conversation inGeneral
Discussion options

You must be logged in to vote

Replies: 2 comments 4 replies

Comment options

This is my code, channel.addConfirmListener() ackCallback Some callbacks will be lost, The message is indeed sent to the rabbitmq server and can be consumed normally , But I sleep for 2ms after sending the message, and all ack callbacks can be received,

I don't know if this is an error in my code or a rabbitmq bug

importcom.rabbitmq.client.AMQP;importcom.rabbitmq.client.Channel;importcom.rabbitmq.client.Connection;importcom.rabbitmq.client.ConnectionFactory;importlombok.extern.log4j.Log4j2;importjava.io.IOException;importjava.nio.charset.StandardCharsets;importjava.util.concurrent.TimeoutException;@Log4j2publicclass异步确认发布{publicstaticvoidmain(String[]args)throwsIOException,TimeoutException,InterruptedException {ConnectionFactoryconnectionFactory =newConnectionFactory();connectionFactory.setHost("");connectionFactory.setPort(7005);connectionFactory.setUsername("");connectionFactory.setPassword("");Connectionconnection =connectionFactory.newConnection();Channelchannel =connection.createChannel();// 开启确认发布AMQP.Confirm.SelectOkselectOk =channel.confirmSelect();channel.queueDeclare("hello",true,false,false,null);//  异步确认发布消息 回调channel.addConfirmListener(                (deliveryTag,multiple) -> {log.info("消息deliveryTag=>{}, send successful",deliveryTag);                },                (deliveryTag,multiple) -> {log.info("消息deliveryTag=>{}, fail in send",deliveryTag);                }        );for (inti =0;i <5;i++) {Stringmessage ="Hello World!!!   " +i;channel.basicPublish("","hello",null,message.getBytes(StandardCharsets.UTF_8));        }    }}

The console shows some callbacks missing

17:04:29.607 [AMQP Connection27.11.210.232:7005] INFO me.demo.me.rabbitmq.consumer.发布确认.异步确认发布 - ackCallback, deliveryTag=>4, send successful17:04:29.615 [AMQP Connection27.11.210.232:7005] INFO me.demo.me.rabbitmq.consumer.发布确认.异步确认发布 - ackCallback, deliveryTag=>5, send successful

But I sleep for 2ms after sending the message, and all callbacks can be received

example code

for (inti =0;i <5;i++) {Stringmessage ="Hello World!!!   " +i;channel.basicPublish("","hello",null,message.getBytes(StandardCharsets.UTF_8));Thread.sleep(2);// I sleep for 2ms after sending the message, and all ack callbacks can be received}

console log

17:05:18.037 [AMQP Connection27.11.210.232:7005] INFO me.demo.me.rabbitmq.consumer.发布确认.异步确认发布 - ackCallback, deliveryTag=>1, send successful17:05:18.043 [AMQP Connection27.11.210.232:7005] INFO me.demo.me.rabbitmq.consumer.发布确认.异步确认发布 - ackCallback, deliveryTag=>2, send successful17:05:18.043 [AMQP Connection27.11.210.232:7005] INFO me.demo.me.rabbitmq.consumer.发布确认.异步确认发布 - ackCallback, deliveryTag=>3, send successful17:05:18.043 [AMQP Connection27.11.210.232:7005] INFO me.demo.me.rabbitmq.consumer.发布确认.异步确认发布 - ackCallback, deliveryTag=>4, send successful17:05:18.043 [AMQP Connection27.11.210.232:7005] INFO me.demo.me.rabbitmq.consumer.发布确认.异步确认发布 - ackCallback, deliveryTag=>5, send successful

My RabbitMQ Server Version is 3.9.14 (No configuration has been modified. The default configuration is used), Erlang 24.3.2 ,

Maven Project dependency in

<dependency>    <groupId>org.springframework.amqp</groupId>    <artifactId>spring-rabbit</artifactId>    <version>2.2.18.RELEASE</version></dependency>

I tried to prevent the main thread from shutting down, but it doesn't seem to be the reason for the main thread to shut down, because the main thread won't shut down automatically once the connection is created

You must be logged in to vote
0 replies
Comment options

RabbitMQ can acknowledge multiple published messages at a time, in that case themultiple flag onbasic.ack will be set totrue.

You must be logged in to vote
4 replies
@HongJian-Yang
Comment options

Thank your answer very much from the bottom of my heart. I'm not very understand what you mean.

like this?

channel.waitForConfirms();

I want to use it

channel.addConfirmListener(ConfirmCallbackackCallback,ConfirmCallbacknackCallback)

To confirm which messages have been received by RabbitMQ Server,

@michaelklishin
Comment options

You assume that one published message will result in one confirmation sent by RabbitMQ. That's not necessarily the case. RabbitMQ can acknowledge two, three or N number of messages at once.
For example, for 10 published messages under load you can get only one acknowledgement back and it will have themultiple property set totrue.

@HongJian-Yang
Comment options

Thank you very much for your answer, which has solved my problem

Because in com.rabbitmq.client.ConfirmCallback No explanation was found for the multiple parameter, Mistakenly think channel.addConfirmListener Call back every time you send it,

I'm watchinghttps://www.rabbitmq.com/tutorials/tutorial-seven-java.html The next explanation came to understand。

multiple:   this is a boolean value. Iffalse, only one message is confirmed/nack-ed,iftrue, all messages with a loweror equal sequencenumber are confirmed/nack-ed.

Console1:

11:43:54.969 [main]INFOme.demo.me.rabbitmq.consumer.发布确认.异步确认发布 - #method<confirm.select-ok>()11:43:54.989 [main]INFOme.demo.me.rabbitmq.consumer.发布确认.异步确认发布 - #method<queue.declare-ok>(queue=hello,message-count=28,consumer-count=0)11:43:54.999 [main]INFOme.demo.me.rabbitmq.consumer.发布确认.异步确认发布 -耗时1711:43:55.005 [AMQPConnection27.11.210.232:7005]INFOme.demo.me.rabbitmq.consumer.发布确认.异步确认发布 -消息deliveryTag=>2,multiple=>true,内容=>HelloWorld!!!1,发送成功

The Console1 log display multiple=true

Console2:

11:50:45.940 [main] INFO me.yaohu.me.rabbitmq.consumer.发布确认.异步确认发布 -#method<confirm.select-ok>()11:50:45.955 [main] INFO me.yaohu.me.rabbitmq.consumer.发布确认.异步确认发布 -#method<queue.declare-ok>(queue=hello, message-count=30, consumer-count=0)11:50:45.992 [AMQP Connection27.11.210.232:7005] INFO me.yaohu.me.rabbitmq.consumer.发布确认.异步确认发布 - 消息deliveryTag=>1, multiple=>false, 内容=>Hello World!!!0, 发送成功11:50:46.010 [main] INFO me.yaohu.me.rabbitmq.consumer.发布确认.异步确认发布 - 耗时6411:50:46.018 [AMQP Connection27.11.210.232:7005] INFO me.yaohu.me.rabbitmq.consumer.发布确认.异步确认发布 - 消息deliveryTag=>2, multiple=>false, 内容=>Hello World!!!1, 发送成功

The Console2 log display multiple=false

multiple:   this is a boolean value. If false, only one message is confirmed/nack-ed, if true, all messages with a lower or equal sequence number are confirmed/nack-ed.
@michaelklishin
Comment options

Some frames will ack multiple messages at once (so,multile=true), others just a single message (multiple-false). I'm not sure if there are more questions at this point?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
General
Labels
None yet
2 participants
@HongJian-Yang@michaelklishin
Converted from issue

This discussion was converted from issue #756 on April 12, 2022 10:04.


[8]ページ先頭

©2009-2025 Movatter.jp