shashank created CAMEL-25274:
--------------------------------

             Summary: camel-dapr - the pub/sub consumer acknowledges every 
event with SUCCESS before the route has processed it, so Dapr drops the events 
whose route fails
                 Key: CAMEL-25274
                 URL: https://issues.apache.org/jira/browse/CAMEL-25274
             Project: Camel
          Issue Type: Bug
          Components: camel-dapr
            Reporter: shashank


{{DaprPubSubConsumer}} subscribes with the Dapr streaming subscription 
({{DaprPreviewClient.subscribeToEvents}}) and its listener does:

{code:java}
public Mono<Status> onEvent(CloudEvent<byte[]> cloudEvent) {
    final Exchange exchange = createServiceBusExchange(cloudEvent);
    AsyncCallback cb = defaultConsumerCallback(exchange, true);
    getAsyncProcessor().process(exchange, cb);
    return Mono.just(Status.SUCCESS);
}
{code}

The returned status is the acknowledgement of the event: the SDK 
({{io.dapr.client.Subscription}}) sends it to the sidecar as the 
{{TopicEventResponse}} status ({{SUCCESS}}, {{RETRY}} or {{DROP}}). So:
* an event whose route fails is acknowledged with {{SUCCESS}}: Dapr does not 
redeliver it, and it is lost;
* the event is acknowledged as soon as the exchange is handed to the route, 
before an asynchronous route has processed it.

The SDK itself answers {{RETRY}} when a listener fails 
({{onErrorReturn(Status.RETRY)}}).

h3. Reproduction

{{DaprPubSubConsumerTest}} (mocked client and processor, as the existing test):
* {{testFailedExchangeIsRedelivered}}: the processor sets an exception on the 
exchange: main returns {{SUCCESS}}, expected {{RETRY}};
* {{testEventIsAcknowledgedWhenTheExchangeIsDone}}: the processor completes 
later: on main the status is already there before the callback ({{expected: 
<false> but was: <true>}}).

h3. Proposed fix

Return a {{Mono}} that emits when the exchange is done: {{SUCCESS}} when it 
completed, {{RETRY}} when it failed. The existing test is adapted (its mocked 
processor now calls the callback, else the status never comes). With the fix 
the camel-dapr tests pass (54). The upgrade guide for 4.23 gets a note (failed 
events are now redelivered).

Affected: 4.14.x, 4.18.x and main (same code since the consumer was added, 
#18015, 2025-05).

Duplicate check (2026-10-02): JIRA text "dapr" (8 issues): CAMEL-23645 (open, 
moving to the new Topic API, no work linked) and features. GitHub pull requests 
"dapr pubsub": only the CAMEL-23630 header filter PRs.

_Filed with Claude Code on behalf of allthingssecurity._




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to