question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reactive Messaging (RabbitMQ) - can't ack messages manually with consumer ack

See original GitHub issue

Describe the bug

It seems that whatever I do messages get always acknowledged automatically. How can I ack a message manually?

Code:

    @Incoming("prices")
    @Acknowledgment(Acknowledgment.Strategy.MANUAL)
    public CompletionStage<Void> process(Message<String> message) {
        String priceInUsdString = message.getPayload();
        Integer priceInUsd = Integer.parseInt(priceInUsdString);
        LOGGER.infof("process priceInUsd=%d", priceInUsd);
        return message.ack();
    }
    @Inject
    @Channel("generated-price")
    Emitter<Integer> emitter;

    public Integer generateInteger() {
        Integer i = random.nextInt(100);
        LOGGER.infof("generateInteger i=%d send", i);
        emitter.send(
                Message.of(i, () -> {
                            // Called when the message is acknowledged.
                            LOGGER.infof("generateInteger i=%d ack", i);
                            return CompletableFuture.completedFuture(null);
                        },
                        reason -> {
                            // Called when the message is acknowledged negatively.
                            LOGGER.infof("generateInteger i=%d nack", i);
                            return CompletableFuture.completedFuture(null);
                        }));
        return i;
    }

Calling:

curl http://localhost:8080/prices/generate

Produces the output:

2022-10-03 11:25:31,810 INFO  [org.acm.amq.PriceGenerator] (executor-thread-0) generateInteger i=26 send
2022-10-03 11:25:31,816 INFO  [org.acm.amq.PriceGenerator] (vert.x-eventloop-thread-1) generateInteger i=26 ack
2022-10-03 11:25:31,817 INFO  [org.acm.amq.PriceConverter] (vert.x-eventloop-thread-2) process priceInUsd=26
2022-10-03 11:25:31,818 INFO  [io.sma.rea.mes.rabbitmq] (vert.x-eventloop-thread-2) SRMSG17033: A message sent to channel `prices` has been ack'd

Expected behavior

I’d expect the following output (the ack message only after the message has been acked):

2022-10-03 11:25:31,810 INFO  [org.acm.amq.PriceGenerator] (executor-thread-0) generateInteger i=26 send

2022-10-03 11:25:31,817 INFO  [org.acm.amq.PriceConverter] (vert.x-eventloop-thread-2) process priceInUsd=26
2022-10-03 11:25:31,818 INFO  [io.sma.rea.mes.rabbitmq] (vert.x-eventloop-thread-2) SRMSG17033: A message sent to channel `prices` has been ack'd
2022-10-03 11:25:31,816 INFO  [org.acm.amq.PriceGenerator] (vert.x-eventloop-thread-1) generateInteger i=26 ack

Actual behavior

The ‘message is acknowledged’ block gets called before the message is acked.

How to Reproduce?

  1. Run the attached reproducer.
  2. Run: curl http://localhost:8080/prices/generate
  3. Check output

ack-test.zip

Requirements: an rabbitmq instance

Output of uname -a or ver

Linux a 5.15.65-1-MANJARO #1 SMP PREEMPT Mon Sep 5 10:15:47 UTC 2022 x86_64 GNU/Linux

Output of java -version

openjdk version “18.0.2” 2022-07-19 OpenJDK Runtime Environment (build 18.0.2+0) OpenJDK 64-Bit Server VM (build 18.0.2+0, mixed mode)

Quarkus version or git rev

Quarkus 2.13.0.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63) Maven home: /opt/apache-maven-3.8.6 Java version: 11.0.14.1, vendor: Eclipse Adoptium, runtime: /opt/jdk-11.0.14.1+1 Default locale: en_US, platform encoding: UTF-8 OS name: “linux”, version: “5.15.65-1-manjaro”, arch: “amd64”, family: “unix”

Additional information

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:17 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ozangunalpcommented, Oct 3, 2022

I’ve not confirmed but I believe we use the RabbitMQPublisher feature (from https://vertx.io/docs/vertx-rabbitmq-client/java/#_reliable_message_publishing) of the underlying vertx client, which does publisher confirmations.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Consumer Acknowledgements and Publisher Confirms
In automatic acknowledgement mode, a message is considered to be successfully delivered immediately after it is sent. This mode trades off higher throughput...
Read more >
Reactive Messaging RabbitMQ Connector Reference ...
When a Reactive Messaging Message associated with a RabbitMQ Message is acknowledged, it informs the broker that the message has been accepted. Whether...
Read more >
RabbitMQ + Reactor, sending ACK after passing on message?
I do not think it is possible to acknowledge inside send method. Instead you can try: receiver.consumeManualAck("queue.A") .
Read more >
Incoming and Outgoing - SmallRye Reactive Messaging
SmallRye Reactive Messaging automatically binds matching @Outgoing to @Incoming to ... withAck(() -> // acknowledge the incoming message message.ack() .
Read more >
MicroProfile Reactive Messaging Specification
eclipse.microprofile.reactive.messaging.Message#nack method reports a negative acknowledgement. Note that the ack and nack methods are ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found