gnodet opened a new pull request, #31130:
URL: https://github.com/apache/camel/pull/31130

   ## Summary
   
   Fix a message-loss bug in `camel-seda`: a message sent to a SEDA queue 
before the consumer route
   starts is silently lost when the producer that sent it is stopped before the 
consumer starts.
   
   ## Root Cause
   
   `SedaComponent.onShutdownEndpoint()` is called when a `SedaEndpoint` shuts 
down. When all
   producers stop and no consumers are registered, the method removes the 
`QueueReference` from the
   component's internal `queues` map unconditionally — even when the queue 
still holds messages.
   
   When the consumer route later starts, `SedaEndpoint.registerQueueIfStale()` 
looks up the queue key
   in the component's map, finds nothing (the reference was removed), and 
creates a brand-new empty
   queue for the same URI. The messages that were buffered in the original 
queue are never delivered.
   
   ## Fix
   
   Add a `queue.isEmpty()` guard in `SedaComponent.onShutdownEndpoint()` before 
removing the
   `QueueReference` from the map:
   
   ```java
   if (ref.getCount() <= 0 && !ref.hasConsumers() && !ref.hasProducers()
           && ref.getQueue().isEmpty()) {
       // reference no longer needed so remove from queues; keep it when the 
queue
       // still holds messages so a consumer that starts later can drain them
       getQueues().remove(key);
   }
   ```
   
   The reference is now only evicted when it has no registered endpoints AND 
the queue is empty.
   
   ## Tests
   
   Two new tests in `SedaMessageSentBeforeConsumerStartsTest`:
   
   1. `testMessageBufferedByProducerRouteBeforeConsumerStartIsNotLost` — starts 
the producer route,
      sends one message, stops the route (triggering `onShutdownEndpoint`), 
then starts the consumer
      route and asserts the message is received.
   2. `testMultipleMessagesBufferedBeforeConsumerStartAreNotLost` — same 
scenario with three messages.
   
   Both tests fail with 2 × "Expected: 1/3, was: 0" on unfixed code and pass on 
the fix, confirming
   the regression test is effective.
   
   Fixes CAMEL-27776.
   Related to CAMEL-27547.
   
   ---
   _Hermes Agent (Claude Sonnet 4.6) on behalf of Guillaume Nodet_
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to