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

   ## What was wrong
   
   [CAMEL-26692](https://issues.apache.org/jira/browse/CAMEL-26692): with 
`username` and `password` set (on the component, or the same values on the 
endpoints), a message sent from a transacted route such as 
`from("jms:queue:in?transacted=true").to("jms:queue:out")` was not part of the 
transaction of the consumed message. When the route failed, the consumed 
message was rolled back and delivered again, but the message sent to `out` was 
already committed: `out` got it twice.
   
   `JmsComponent#createEndpoint` wrapped the connection factory of each 
endpoint in a `UserCredentialsConnectionFactoryAdapter` of its own. Spring 
finds the session of a transaction by the connection factory instance 
(`JmsTransactionManager` binds it under its factory, `JmsTemplate` looks it up 
with its own, `ConnectionFactoryUtils#doGetTransactionalSession`), so the 
producer never found the session of the consumer and sent in a session of its 
own. Without credentials the endpoints share the factory of the component, and 
the send is part of the transaction.
   
   ## What changed
   
   - `JmsComponent#createEndpoint`: the endpoints that wrap the connection 
factory of the component with the same username and password now share one 
adapter, kept in a small component cache keyed by username (LRU, at most 100 
entries).
     - An entry is reused only for the same target factory instance and the 
same password; other credentials, such as a rotated password, get a new adapter 
that replaces the entry. Endpoints created before keep their adapter. The 
adapter is not stored in the component configuration, so endpoints created 
again after a secret rotation get the newly resolved credentials, as 
CAMEL-24637 expects.
     - An endpoint with its own `connectionFactory` (or another factory, such 
as the one camel-activemq creates per endpoint from `brokerURL`) gets its own 
adapter, as before.
   - The subclasses (`AMQPComponent`, `ActiveMQComponent` in camel-activemq and 
camel-activemq6) do not wrap the factory themselves, so they get the fix 
through `JmsComponent`.
   
   ## Behaviour
   
   - A message sent from a transacted route with credentials is now rolled back 
with the consumed message, as without credentials.
   - In a non-transacted consumer route, a message sent from the thread of the 
consumer now uses the session the listener exposes (`exposeListenerSession`), 
as without credentials, instead of a connection of its own (no pool: one 
connection per message before).
   
   ## Tests
   
   - camel-jms, embedded Artemis (VM): `JmsTransactedCredentialsTest` (rollback 
with credentials on the component and on the endpoints, control without 
credentials, connections opened by sends from a consumer) and 
`JmsComponentCredentialsConnectionFactoryTest` (adapter instances: shared, 
other credentials, rotated password, endpoint factory).
   - camel-amqp, embedded Artemis AMQP: `AMQPTransactedCredentialsTest`. 
camel-activemq: `ActiveMQCredentialsConnectionFactoryTest` (instance 
comparison, its broker tests need a container).
   - On `main`: 6 of the 9 camel-jms tests fail (`mock://out Received message 
count. Expected: <1> but was: <2>`, `expected: <0> but was: <5>` connections, 
different adapter instances), 2 of 3 in camel-amqp, 1 of 2 in camel-activemq; 
with the fix all pass.
   - Module suites: camel-jms 479 unit tests and 366 integration tests on the 
embedded broker (including the transaction ITs and 
`JmsToJmsTransactedSecurityIT`), camel-amqp 28, camel-activemq unit tests: 0 
failures. The camel-activemq ITs need a container and were not run.
   
   ## Docs and upgrade guide
   
   - `jms-component.adoc` ("Enabling Transacted Consumption"): when a message 
sent from the route is part of the transaction of the consumer. Catalog copy 
refreshed.
   - `camel-4x-upgrade-guide-4_24.adoc`: new entry.
   
   ## Backport
   
   Not proposed for `camel-4.18.x` / `camel-4.22.x`: it changes the 
transactional behaviour of working routes (a send that was committed at once is 
now rolled back with the route), and the issue comes from a code survey, not a 
user report.
   
   _Claude Code on behalf of Federico Mariani_
   


-- 
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