qingli9374 opened a new issue, #13:
URL: https://github.com/apache/rocketmq-ai/issues/13
# [Bug] sendMessageStreaming can lose a response before listener registration
## Describe the Bug
`RocketMQTransport.sendMessageStreaming` currently sends the request first
and registers
the request-id listener only after `RocketMQUtil.sendRocketMQRequest`
returns:
```java
String requestId = sendRocketMQRequest(...);
MESSAGE_STREAM_RESPONSE_MAP
.computeIfAbsent(namespace, key -> new ConcurrentHashMap<>())
.put(requestId, new SSEEventListener(eventConsumer, errorConsumer));
```
The remote agent can receive the request and send its first streaming
response while the
producer call is still returning. If that message is consumed before the
`put`, no listener
exists for the request ID, so `processStreamResult` drops the event. The
same ordering also
leaves a registered listener behind if a later step in the send path throws.
## Expected Behavior
The request ID must be exposed before `Producer.send` is called. The
streaming listener can
then be registered before the request becomes visible to a remote worker,
and the entry should
be removed if the send fails.
## Proposed Fix
- Add a callback overload of `RocketMQUtil.sendRocketMQRequest` that
receives the generated
request ID before sending the message.
- In `sendMessageStreaming`, register the `SSEEventListener` in that
callback and remove it from
`MESSAGE_STREAM_RESPONSE_MAP` if the send throws.
- Add a deterministic unit test that fails unless the callback runs before
`Producer.send`.
## Verification
The focused unit test and Checkstyle pass on JDK 17.
--
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]