sinberCS opened a new pull request, #29:
URL: https://github.com/apache/rocketmq-client-nodejs/pull/29
## Summary
This PR adds broadcasting consumption support to `PushConsumer`.
- expose `messageModel: "BROADCASTING" | "CLUSTERING"` in the Node.js API;
- keep `CLUSTERING` as the backward-compatible default;
- pass the selected model to the existing C++ `SetPushConsumerMessageModel`
API;
- expose `PushConsumer#setSessionCredentials`, matching the producer API;
- resolve name-server hostnames before passing them to the pinned C++ SDK
1.2.0, which otherwise only accepts numeric IPv4 addresses;
- add unit tests, a two-process broadcast E2E harness, and documentation.
## Motivation
The bundled C++ client already supports `BROADCASTING`, but the Node.js
binding did not expose or forward the message model. Therefore, Node.js
consumers could only use the C++ client's default clustering behavior.
The managed RocketMQ E2E test also exposed an existing compatibility issue:
C++ SDK 1.2.0 calls `inet_addr` directly and cannot connect when `nameServer`
is a DNS hostname. The small resolver added here keeps the public Node.js
configuration in the documented `host:port` form and is shared by producers and
consumers.
## Usage
```js
const consumer = new PushConsumer("GROUP_ID", "INSTANCE_NAME", {
nameServer: "example.nameserver:8080",
messageModel: "BROADCASTING"
});
consumer.setSessionCredentials("ACCESS_KEY", "SECRET_KEY", "ALIYUN");
```
## Test report
### Environment
- Revision: `77a31e0`
- macOS 15.0 on Apple Silicon
- Node.js `v10.24.1 x64` under Rosetta, matching this repository's legacy
native-addon compatibility
- Bundled RocketMQ C++ SDK: `1.2.0`
- Local regression broker: Apache RocketMQ `4.9.4`
- Managed E2E target: Alibaba Cloud RocketMQ 5.x, `cn-hangzhou`, public
Remoting endpoint on port `8080` (instance details and credentials omitted)
### Results
| Test | Result | Notes |
| --- | --- | --- |
| Native build (`npm run install`) | PASS | Built the x86_64 native addon;
only pre-existing V8/NAN deprecation warnings were emitted. |
| Full suite (`npm test`) | PASS | Lint, unit tests, and the original
producer/consumer examples passed against a temporary RocketMQ 4.9.4 broker; 10
messages were sent and consumed. |
| Broadcast E2E (`npm run test:broadcast`) | PASS | Used the original DNS
endpoint, two independent consumer processes, one shared group, and
`BROADCASTING`. |
| Patch validation (`git diff --check`) | PASS | No whitespace errors. |
| Credential scan | PASS | No test credentials are present in the patch; E2E
credentials are read only from environment variables. |
Broadcast E2E procedure:
1. Create a temporary normal topic and concurrent consumer group.
2. Start two independent consumers with the same group and `messageModel:
"BROADCASTING"`.
3. Wait until both consumers report ready.
4. Send six uniquely identified messages.
5. Compare each consumer's received-message set with the producer's
sent-message set.
6. Delete the temporary topic and consumer group.
Observed result:
```json
{
"messageModel": "BROADCASTING",
"sent": 6,
"consumerAReceived": 6,
"consumerBReceived": 6,
"verified": true
}
```
### 中文摘要
本 PR 为 Node.js `PushConsumer` 增加广播消费模式,并保持集群消费为默认行为。底层 C++ SDK
原本已经支持广播,本次主要补齐 Node.js 参数映射和透传;同时补充消费者云上鉴权入口,并修复旧版 C++ SDK 无法解析 NameServer
域名的问题。
测试覆盖原生编译、单元测试、代码规范、RocketMQ 4.9.4 原有完整测试,以及 RocketMQ 5.x 云上广播 E2E。云上测试中,同一
Group 的两个独立消费者均完整收到 6/6 条消息,消息集合完全一致。测试 Topic 和 Group 已删除,临时凭证未写入代码或提交记录。
##### Checklist
- [x] `npm test` passes
- [x] tests and/or benchmarks are included
- [x] documentation is changed or added
- [x] commit message follows [commit
guidelines](https://github.com/apache/rocketmq-client-nodejs/blob/master/CONTRIBUTING.md#commit-message-guidelines)
##### Description of change
- Adds broadcasting message-model support to `PushConsumer`.
- Adds unit and managed RocketMQ E2E coverage.
--
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]