Alaske opened a new pull request, #10548:
URL: https://github.com/apache/rocketmq/pull/10548
### Which Issue(s) This PR Fixes
Fixes #10545
### Brief Description
This PR adds `MessageQueueSelector` support for transactional message
sending in the Java client.
Currently normal message sends can use `MessageQueueSelector`, but
transactional sends only support:
```java
sendMessageInTransaction(Message msg, Object arg)
```
This PR adds a selector-aware overload so users can control the real queue
used by the transactional half message:
```java
sendMessageInTransaction(
Message msg,
MessageQueueSelector selector,
Object selectorArg,
Object transactionArg
)
```
### How Did You Implement It
- Added a Java 8 `default` method to `MQProducer` to preserve binary
compatibility for third-party implementations.
- Kept `DefaultMQProducer` behavior unchanged by explicitly rejecting
transactional sends and directing users to `TransactionMQProducer`.
- Implemented the new overload in `TransactionMQProducer`.
- Added a selector-aware transaction send path in `DefaultMQProducerImpl`.
- Kept `selectorArg` and `transactionArg` separate:
- `selectorArg` is passed only to `MessageQueueSelector`.
- `transactionArg` is passed only to
`TransactionListener#executeLocalTransaction`.
- Reused the existing selector queue resolution and specified-queue send
validation so selected queues follow the same validation semantics as normal
selector sends.
- Did not change broker, store, or remoting protocol behavior. The existing
broker transaction flow already stores `REAL_TOPIC` / `REAL_QID` for half
messages and restores the real queue when committing.
### How to Verify It
Added unit tests covering:
- `TransactionMQProducer` sends transactional messages to the queue selected
by `MessageQueueSelector`.
- `selectorArg` is passed to the selector and `transactionArg` is passed to
the local transaction listener.
- `DefaultMQProducer` still rejects transactional sends.
- Null selector is rejected.
- A selector returning a queue with a different topic is rejected
consistently with normal selector send behavior.
- End transaction routing uses the selected broker/queue.
Verified with JDK 8:
```bash
mvn -pl client \
-Dtest=DefaultMQProducerTest#assertSendMessageInTransactionByQueueSelector+testSendMessageInTransactionByQueueSelector+testSendMessageInTransactionByNullQueueSelector+testSendMessageInTransactionBySelectorWithDifferentTopicQueue
\
-DskipITs test
```
Result:
```text
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0
Checkstyle: 0 violations
SpotBugs: 0 issues
```
The public API schema for `DefaultMQProducer` was also updated.
--
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]