rocketmq-client-remoting-nodejs 0.0.0-stage → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/README.en.md +428 -0
  2. package/README.md +424 -2
  3. package/dist/client/admin.d.ts +229 -0
  4. package/dist/client/admin.js +2462 -0
  5. package/dist/client/allocate.d.ts +48 -0
  6. package/dist/client/allocate.js +365 -0
  7. package/dist/client/backpressure.d.ts +23 -0
  8. package/dist/client/backpressure.js +95 -0
  9. package/dist/client/consumer.d.ts +294 -0
  10. package/dist/client/consumer.js +3095 -0
  11. package/dist/client/consumer_result.d.ts +129 -0
  12. package/dist/client/consumer_result.js +138 -0
  13. package/dist/client/consumer_stats.d.ts +69 -0
  14. package/dist/client/consumer_stats.js +258 -0
  15. package/dist/client/exception.d.ts +39 -0
  16. package/dist/client/exception.js +36 -0
  17. package/dist/client/hook.d.ts +145 -0
  18. package/dist/client/hook.js +171 -0
  19. package/dist/client/latency.d.ts +61 -0
  20. package/dist/client/latency.js +239 -0
  21. package/dist/client/lite_pull_consumer.d.ts +151 -0
  22. package/dist/client/lite_pull_consumer.js +1096 -0
  23. package/dist/client/mq_client.d.ts +188 -0
  24. package/dist/client/mq_client.js +1678 -0
  25. package/dist/client/mq_client_manager.d.ts +21 -0
  26. package/dist/client/mq_client_manager.js +129 -0
  27. package/dist/client/offset_store.d.ts +45 -0
  28. package/dist/client/offset_store.js +389 -0
  29. package/dist/client/open_tracing_hook.d.ts +52 -0
  30. package/dist/client/open_tracing_hook.js +241 -0
  31. package/dist/client/pop_api.d.ts +28 -0
  32. package/dist/client/pop_api.js +224 -0
  33. package/dist/client/pop_consumer.d.ts +23 -0
  34. package/dist/client/pop_consumer.js +719 -0
  35. package/dist/client/pop_process_queue.d.ts +15 -0
  36. package/dist/client/pop_process_queue.js +51 -0
  37. package/dist/client/process_queue.d.ts +49 -0
  38. package/dist/client/process_queue.js +261 -0
  39. package/dist/client/produce_accumulator.d.ts +75 -0
  40. package/dist/client/produce_accumulator.js +288 -0
  41. package/dist/client/producer.d.ts +231 -0
  42. package/dist/client/producer.js +1774 -0
  43. package/dist/client/pull_api.d.ts +26 -0
  44. package/dist/client/pull_api.js +264 -0
  45. package/dist/client/pull_consumer.d.ts +119 -0
  46. package/dist/client/pull_consumer.js +876 -0
  47. package/dist/client/pull_schedule_service.d.ts +71 -0
  48. package/dist/client/pull_schedule_service.js +424 -0
  49. package/dist/client/request_reply.d.ts +61 -0
  50. package/dist/client/request_reply.js +232 -0
  51. package/dist/client/retry_message.d.ts +2 -0
  52. package/dist/client/retry_message.js +27 -0
  53. package/dist/client/send_result.d.ts +57 -0
  54. package/dist/client/send_result.js +70 -0
  55. package/dist/client/top_addressing.d.ts +20 -0
  56. package/dist/client/top_addressing.js +75 -0
  57. package/dist/client/trace_context.d.ts +61 -0
  58. package/dist/client/trace_context.js +373 -0
  59. package/dist/client/trace_dispatcher.d.ts +31 -0
  60. package/dist/client/trace_dispatcher.js +236 -0
  61. package/dist/client/trace_hook.d.ts +23 -0
  62. package/dist/client/trace_hook.js +228 -0
  63. package/dist/client/traceparent.d.ts +9 -0
  64. package/dist/client/traceparent.js +86 -0
  65. package/dist/common/boundary_type.d.ts +7 -0
  66. package/dist/common/boundary_type.js +16 -0
  67. package/dist/common/compress.d.ts +28 -0
  68. package/dist/common/compress.js +512 -0
  69. package/dist/common/message.d.ts +129 -0
  70. package/dist/common/message.js +214 -0
  71. package/dist/common/messageClientIdSetter.d.ts +7 -0
  72. package/dist/common/messageClientIdSetter.js +48 -0
  73. package/dist/common/messageConst.d.ts +68 -0
  74. package/dist/common/messageConst.js +68 -0
  75. package/dist/common/messageDecoder.d.ts +40 -0
  76. package/dist/common/messageDecoder.js +504 -0
  77. package/dist/common/messageType.d.ts +11 -0
  78. package/dist/common/messageType.js +11 -0
  79. package/dist/common/message_accessor.d.ts +39 -0
  80. package/dist/common/message_accessor.js +135 -0
  81. package/dist/common/mixAll.d.ts +106 -0
  82. package/dist/common/mixAll.js +247 -0
  83. package/dist/common/recall_message_handle.d.ts +25 -0
  84. package/dist/common/recall_message_handle.js +98 -0
  85. package/dist/common/subscriptionData.d.ts +36 -0
  86. package/dist/common/subscriptionData.js +64 -0
  87. package/dist/common/sysflag.d.ts +129 -0
  88. package/dist/common/sysflag.js +96 -0
  89. package/dist/common/topic_config.d.ts +66 -0
  90. package/dist/common/topic_config.js +106 -0
  91. package/dist/common/topic_validator.d.ts +49 -0
  92. package/dist/common/topic_validator.js +115 -0
  93. package/dist/common/utilAll.d.ts +39 -0
  94. package/dist/common/utilAll.js +154 -0
  95. package/dist/common/validators.d.ts +25 -0
  96. package/dist/common/validators.js +80 -0
  97. package/dist/index.d.ts +24 -0
  98. package/dist/index.js +36 -0
  99. package/dist/logging.d.ts +24 -0
  100. package/dist/logging.js +246 -0
  101. package/dist/remoting/acl.d.ts +16 -0
  102. package/dist/remoting/acl.js +39 -0
  103. package/dist/remoting/admin_body.d.ts +257 -0
  104. package/dist/remoting/admin_body.js +669 -0
  105. package/dist/remoting/bodies.d.ts +475 -0
  106. package/dist/remoting/bodies.js +1131 -0
  107. package/dist/remoting/client.d.ts +73 -0
  108. package/dist/remoting/client.js +591 -0
  109. package/dist/remoting/codes.d.ts +296 -0
  110. package/dist/remoting/codes.js +301 -0
  111. package/dist/remoting/exception.d.ts +45 -0
  112. package/dist/remoting/exception.js +58 -0
  113. package/dist/remoting/extra_info.d.ts +61 -0
  114. package/dist/remoting/extra_info.js +220 -0
  115. package/dist/remoting/headers.d.ts +758 -0
  116. package/dist/remoting/headers.js +1307 -0
  117. package/dist/remoting/heartbeat.d.ts +91 -0
  118. package/dist/remoting/heartbeat.js +227 -0
  119. package/dist/remoting/namespace.d.ts +14 -0
  120. package/dist/remoting/namespace.js +85 -0
  121. package/dist/remoting/pop_bodies.d.ts +58 -0
  122. package/dist/remoting/pop_bodies.js +214 -0
  123. package/dist/remoting/remotingCommand.d.ts +39 -0
  124. package/dist/remoting/remotingCommand.js +225 -0
  125. package/dist/remoting/route.d.ts +61 -0
  126. package/dist/remoting/route.js +288 -0
  127. package/dist/remoting/rpc_hooks.d.ts +31 -0
  128. package/dist/remoting/rpc_hooks.js +73 -0
  129. package/dist/remoting/serialize.d.ts +33 -0
  130. package/dist/remoting/serialize.js +372 -0
  131. package/dist/remoting/socks_proxy.d.ts +29 -0
  132. package/dist/remoting/socks_proxy.js +379 -0
  133. package/dist/remoting/static_topic.d.ts +49 -0
  134. package/dist/remoting/static_topic.js +244 -0
  135. package/dist/remoting/subscription.d.ts +65 -0
  136. package/dist/remoting/subscription.js +172 -0
  137. package/package.json +38 -4
@@ -0,0 +1,154 @@
1
+ import os from 'node:os';
2
+ import { Buffer } from 'node:buffer';
3
+ const CRC_TABLE = (() => {
4
+ const table = new Int32Array(256);
5
+ for (let n = 0; n < 256; n++) {
6
+ let c = n;
7
+ for (let k = 0; k < 8; k++) {
8
+ c = (c & 1) ? (0xedb88320 ^ (c >>> 1)) : (c >>> 1);
9
+ }
10
+ table[n] = c;
11
+ }
12
+ return table;
13
+ })();
14
+ // Raw full-width CRC-32/ISO-HDLC. Keep this as the generic utility; the value the
15
+ // store frame carries is the masked form below.
16
+ export function crc32(buf) {
17
+ const data = Buffer.isBuffer(buf) ? buf : Buffer.from(buf);
18
+ let c = 0xffffffff;
19
+ for (let i = 0; i < data.length; i++) {
20
+ c = CRC_TABLE[(c ^ data[i]) & 0xff] ^ (c >>> 8);
21
+ }
22
+ return (c ^ 0xffffffff) >>> 0;
23
+ }
24
+ // The BODYCRC form the store actually writes into a message frame: CRC-32/ISO-HDLC
25
+ // with the sign bit dropped. Comparing a full 32-bit CRC against that wire field
26
+ // disagrees for roughly half of all bodies (any body whose CRC has the high bit
27
+ // set), so a check built on crc32() rejects perfectly valid messages.
28
+ export function crc32Match(buf) {
29
+ return crc32(buf) & 0x7fffffff;
30
+ }
31
+ export function serverStringHash(str) {
32
+ let h = 0;
33
+ for (let i = 0; i < str.length; i++) {
34
+ h = (Math.imul(31, h) + str.charCodeAt(i)) | 0;
35
+ }
36
+ return h;
37
+ }
38
+ const HEX = '0123456789ABCDEF';
39
+ export function bytes2string(bs) {
40
+ const buf = Buffer.isBuffer(bs) ? bs : Buffer.from(bs);
41
+ let s = '';
42
+ for (let i = 0; i < buf.length; i++) {
43
+ s += HEX[(buf[i] >> 4) & 0x0f] + HEX[buf[i] & 0x0f];
44
+ }
45
+ return s;
46
+ }
47
+ export function string2bytesHex(hexString) {
48
+ if (!hexString)
49
+ return null;
50
+ try {
51
+ return Buffer.from(hexString, 'hex');
52
+ }
53
+ catch (e) {
54
+ return null;
55
+ }
56
+ }
57
+ export function ipAndPortToBytes(ip, port, v6 = false) {
58
+ const addr = _ipToBytes(ip, v6);
59
+ const out = Buffer.alloc(addr.length + 4);
60
+ addr.copy(out, 0);
61
+ out.writeUInt32BE(port >>> 0, addr.length);
62
+ return out;
63
+ }
64
+ function _ipToBytes(ip, v6) {
65
+ if (v6)
66
+ return Buffer.from(ip.split(':').reduce((acc, part) => {
67
+ // simplistic ipv6 parse via dns not available; rely on caller using 16-byte repr
68
+ return acc;
69
+ }, Buffer.alloc(0))); // placeholder; v6 normally built from raw bytes in decoder
70
+ const parts = ip.split('.').map(Number);
71
+ const b = Buffer.alloc(4);
72
+ b.writeUInt8(parts[0] | 0, 0);
73
+ b.writeUInt8(parts[1] | 0, 1);
74
+ b.writeUInt8(parts[2] | 0, 2);
75
+ b.writeUInt8(parts[3] | 0, 3);
76
+ return b;
77
+ }
78
+ export function bytesToIpAndPort(raw) {
79
+ const buf = Buffer.isBuffer(raw) ? raw : Buffer.from(raw);
80
+ if (buf.length === 8) {
81
+ const ip = `${buf[0]}.${buf[1]}.${buf[2]}.${buf[3]}`;
82
+ const port = buf.readUInt32BE(4);
83
+ return [ip, port];
84
+ }
85
+ // ipv6: 20 bytes total (16 ip + 4 port)
86
+ const ip = buf.slice(0, 16);
87
+ const port = buf.readUInt32BE(16);
88
+ return [ip, port];
89
+ }
90
+ function writeLongBE(value) {
91
+ const b = Buffer.alloc(8);
92
+ b.writeBigInt64BE(BigInt(value), 0);
93
+ return b;
94
+ }
95
+ export function createMessageId(addrBytes, offset) {
96
+ return bytes2string(Buffer.concat([addrBytes, writeLongBE(offset)]));
97
+ }
98
+ export function decodeMessageId(msgId) {
99
+ const raw = string2bytesHex(msgId);
100
+ const ipLen = raw.length === 16 ? 4 : 16;
101
+ const family = raw.length === 16 ? 'IPv4' : 'IPv6';
102
+ void family;
103
+ let ip, port, offset;
104
+ if (ipLen === 4) {
105
+ ip = `${raw[0]}.${raw[1]}.${raw[2]}.${raw[3]}`;
106
+ port = raw.readUInt32BE(4);
107
+ offset = raw.readBigInt64BE(8);
108
+ }
109
+ else {
110
+ ip = raw.slice(0, 16);
111
+ port = raw.readUInt32BE(16);
112
+ offset = raw.readBigInt64BE(20);
113
+ }
114
+ return { ip, port, offset: Number(offset) };
115
+ }
116
+ export function currentTimeMillis() { return Date.now(); }
117
+ export function isBlank(s) { return s == null || /^\s*$/.test(s); }
118
+ export function getPid() { return process.pid; }
119
+ export function getHostIp() {
120
+ const ifaces = os.networkInterfaces();
121
+ for (const name of Object.keys(ifaces)) {
122
+ for (const ni of ifaces[name] || []) {
123
+ if (ni.family === 'IPv4' && !ni.internal)
124
+ return ni.address;
125
+ }
126
+ }
127
+ return '127.0.0.1';
128
+ }
129
+ // The start instant of CONSUME_FROM_TIMESTAMP, in local "yyyyMMddHHmmss".
130
+ export function timeMillisToHumanString3(ms) {
131
+ const d = new Date(ms);
132
+ const p = (n, w = 2) => String(n).padStart(w, '0');
133
+ return `${d.getFullYear()}${p(d.getMonth() + 1)}${p(d.getDate())}${p(d.getHours())}${p(d.getMinutes())}${p(d.getSeconds())}`;
134
+ }
135
+ // Default for a consumer that never set one: boot time minus 30 minutes, so an untouched
136
+ // CONSUME_FROM_TIMESTAMP still replays a recent backlog instead of starting at "now".
137
+ export function defaultConsumeTimestamp() {
138
+ return timeMillisToHumanString3(Date.now() - 30 * 60 * 1000);
139
+ }
140
+ // Parse that instant back. A malformed value is a hard failure: falling back to "now" would silently
141
+ // turn the policy into "skip the backlog", so both consumer families reject it at start-up.
142
+ export function parseConsumeTimestamp(raw) {
143
+ const m = /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/.exec(raw ?? '');
144
+ if (!m) {
145
+ throw new Error(`consumeTimestamp is invalid, the valid format is yyyyMMddHHmmss,but received ${raw}`);
146
+ }
147
+ return new Date(Number(m[1]), Number(m[2]) - 1, Number(m[3]), Number(m[4]), Number(m[5]), Number(m[6])).getTime();
148
+ }
149
+ export default {
150
+ crc32, crc32Match, serverStringHash, bytes2string, string2bytesHex,
151
+ ipAndPortToBytes, bytesToIpAndPort, createMessageId, decodeMessageId,
152
+ currentTimeMillis, isBlank, getPid, getHostIp,
153
+ timeMillisToHumanString3, defaultConsumeTimestamp, parseConsumeTimestamp,
154
+ };
@@ -0,0 +1,25 @@
1
+ import { Message } from './message.js';
2
+ export declare const CHARACTER_MAX_LENGTH = 255;
3
+ export declare const CHARSET_ILLEGAL = "{}\n";
4
+ export declare const VALID_PATTERN = "^[%|a-zA-Z0-9_-]+$";
5
+ export declare const GROUP_NOT_EXIST = "the specified group[%s] does not exist";
6
+ export declare const GROUP_ALREADY_EXIST = "the specified group[%s] already exists";
7
+ export declare const CLIENT_ID_NOT_EXIST = "the specified clientId[%s] does not exist";
8
+ export declare const TOPIC_NOT_EXIST = "the specified topic[%s] does not exist";
9
+ export declare const RESERVED_GROUP_PREFIXES: string[];
10
+ export declare function isGroupIllegal(str: string | null): boolean;
11
+ export declare const Validators: {
12
+ CHARACTER_MAX_LENGTH: number;
13
+ CHARSET_ILLEGAL: string;
14
+ VALID_PATTERN: string;
15
+ GROUP_NOT_EXIST: string;
16
+ GROUP_ALREADY_EXIST: string;
17
+ CLIENT_ID_NOT_EXIST: string;
18
+ TOPIC_NOT_EXIST: string;
19
+ RESERVED_GROUP_PREFIXES: string[];
20
+ isGroupIllegal: typeof isGroupIllegal;
21
+ checkGroup(group: string | null): void;
22
+ checkTopic(topic: string | null): void;
23
+ checkMessage(msg: Message | null, maxMessageSize: number): void;
24
+ };
25
+ export default Validators;
@@ -0,0 +1,80 @@
1
+ import path from 'node:path';
2
+ import { MQClientException } from "../remoting/exception.js";
3
+ import { GROUP_MAX_LENGTH, TOPIC_MAX_LENGTH, VALID_CHAR_PATTERN, isTopicOrGroupIllegal, isNotAllowedSendTopic, } from "./topic_validator.js";
4
+ export const CHARACTER_MAX_LENGTH = 255;
5
+ export const CHARSET_ILLEGAL = '{}\n';
6
+ export const VALID_PATTERN = '^[%|a-zA-Z0-9_-]+$';
7
+ export const GROUP_NOT_EXIST = 'the specified group[%s] does not exist';
8
+ export const GROUP_ALREADY_EXIST = 'the specified group[%s] already exists';
9
+ export const CLIENT_ID_NOT_EXIST = 'the specified clientId[%s] does not exist';
10
+ export const TOPIC_NOT_EXIST = 'the specified topic[%s] does not exist';
11
+ // Group names reserved for broker-internal retry / dlq routing.
12
+ export const RESERVED_GROUP_PREFIXES = ['%RETRY%', '%DLQ%'];
13
+ function checkTopicNotAllowed(topic) {
14
+ if (topic != null && isNotAllowedSendTopic(topic)) {
15
+ throw new MQClientException(`The topic[${topic}] is conflict with system reserved keywords.`);
16
+ }
17
+ }
18
+ // Returns true when the group name contains illegal characters (consistent with topic rule).
19
+ export function isGroupIllegal(str) {
20
+ return isTopicOrGroupIllegal(str);
21
+ }
22
+ export const Validators = {
23
+ CHARACTER_MAX_LENGTH,
24
+ CHARSET_ILLEGAL,
25
+ VALID_PATTERN,
26
+ GROUP_NOT_EXIST,
27
+ GROUP_ALREADY_EXIST,
28
+ CLIENT_ID_NOT_EXIST,
29
+ TOPIC_NOT_EXIST,
30
+ RESERVED_GROUP_PREFIXES,
31
+ isGroupIllegal,
32
+ checkGroup(group) {
33
+ if (group == null || !String(group).trim()) {
34
+ throw new MQClientException('the specified group is blank');
35
+ }
36
+ if (String(group).length > GROUP_MAX_LENGTH) {
37
+ throw new MQClientException(`the specified group[${group}] is longer than group max length: ${GROUP_MAX_LENGTH}.`);
38
+ }
39
+ if (isTopicOrGroupIllegal(group)) {
40
+ throw new MQClientException(`the specified group[${group}] contains illegal characters, allowing only ${VALID_CHAR_PATTERN}`);
41
+ }
42
+ },
43
+ checkTopic(topic) {
44
+ if (topic == null || !String(topic).trim()) {
45
+ throw new MQClientException('The specified topic is blank');
46
+ }
47
+ if (String(topic).length > TOPIC_MAX_LENGTH) {
48
+ throw new MQClientException(`The specified topic is longer than topic max length ${TOPIC_MAX_LENGTH}.`);
49
+ }
50
+ if (isTopicOrGroupIllegal(topic)) {
51
+ throw new MQClientException(`The specified topic[${topic}] contains illegal characters, allowing only ${VALID_CHAR_PATTERN}`);
52
+ }
53
+ },
54
+ checkMessage(msg, maxMessageSize) {
55
+ if (msg == null) {
56
+ throw new MQClientException('the message is null');
57
+ }
58
+ const topic = msg.getTopic();
59
+ this.checkTopic(topic);
60
+ checkTopicNotAllowed(msg.getTopic());
61
+ const body = msg.getBody();
62
+ if (body == null) {
63
+ throw new MQClientException('the message body is null');
64
+ }
65
+ if (body.length === 0) {
66
+ throw new MQClientException('the message body length is zero');
67
+ }
68
+ if (body.length > maxMessageSize) {
69
+ throw new MQClientException(`the message body size over max value, MAX: ${maxMessageSize}`);
70
+ }
71
+ const lmqPath = msg.getUserProperty
72
+ ? msg.getUserProperty('INNER_MULTI_DISPATCH')
73
+ : (msg.getProperty ? msg.getProperty('INNER_MULTI_DISPATCH') : null);
74
+ if (lmqPath != null && String(lmqPath).length > 0
75
+ && (String(lmqPath).includes('/') || String(lmqPath).includes(path.sep))) {
76
+ throw new MQClientException(`INNER_MULTI_DISPATCH ${lmqPath} can not contains ${path.sep} character`);
77
+ }
78
+ },
79
+ };
80
+ export default Validators;
@@ -0,0 +1,24 @@
1
+ export { DefaultMQProducer } from './client/producer.js';
2
+ export { TransactionMQProducer } from './client/producer.js';
3
+ export { TransactionListener } from './client/producer.js';
4
+ export { LocalTransactionState } from './client/producer.js';
5
+ export { MessageQueueSelector } from './client/producer.js';
6
+ export { SelectMessageQueueByHash } from './client/producer.js';
7
+ export { SelectMessageQueueByRandom } from './client/producer.js';
8
+ export type { SendCallback } from './client/producer.js';
9
+ export { DefaultMQPushConsumer } from './client/consumer.js';
10
+ export { DefaultMQPullConsumer } from './client/pull_consumer.js';
11
+ export type { PullCallback } from './client/pull_consumer.js';
12
+ export { DefaultLitePullConsumer } from './client/lite_pull_consumer.js';
13
+ export type { TopicMessageQueueChangeListener } from './client/lite_pull_consumer.js';
14
+ export { DefaultMQAdminExt } from './client/admin.js';
15
+ export { PullConsumerScheduleService, PullTaskContext, DEFAULT_PULL_NEXT_DELAY_MILLIS, PULL_TASK_EXCEPTION_DELAY_MILLIS, DEFAULT_QUEUE_CHECK_INTERVAL_MILLIS, DEFAULT_SHUTDOWN_DRAIN_TIMEOUT_MILLIS, } from './client/pull_schedule_service.js';
16
+ export type { PullTaskCallback, PullTaskOptions } from './client/pull_schedule_service.js';
17
+ export { ConsumeConcurrentlyStatus, ConsumeOrderlyStatus, PullStatus, PullResult, ConsumeConcurrentlyContext, ConsumeOrderlyContext, MessageSelector, MessageQueueListener, MessageListener, MessageListenerConcurrently, MessageListenerOrderly, } from './client/consumer_result.js';
18
+ export { Message, MessageExt, MessageQueue, MessageBatch, isWaitStoreMsgOK } from './common/message.js';
19
+ export { MessageConst } from './common/messageConst.js';
20
+ export { MixAll } from './common/mixAll.js';
21
+ export { MessageSysFlag, PullSysFlag, PermName, SubscriptionMode } from './common/sysflag.js';
22
+ export { MessageAccessor } from './common/message_accessor.js';
23
+ export { ExpressionType, SubscriptionData, FilterAPI } from './common/subscriptionData.js';
24
+ export { MessageModel, ConsumeFromWhere, ConsumeType } from './remoting/heartbeat.js';
package/dist/index.js ADDED
@@ -0,0 +1,36 @@
1
+ // Public API surface of the RocketMQ Node.js client (the npm package entry).
2
+ //
3
+ // The repo itself runs TypeScript directly (`node --experimental-strip-types`), so internal
4
+ // code imports deep paths with explicit `.ts` extensions. This barrel is the **published**
5
+ // entry: `npm run build` compiles it together with the whole src/ tree into dist/, with the
6
+ // `.ts` import specifiers rewritten to `.js` (tsconfig.build.json +
7
+ // rewriteRelativeImportExtensions), and package.json's main/types/exports point here.
8
+ //
9
+ // Consumers of the tarball / registry package import it without any flag:
10
+ // import { DefaultMQProducer, Message } from 'rocketmq-client-remoting-nodejs';
11
+ // ---- producer ----
12
+ export { DefaultMQProducer } from "./client/producer.js";
13
+ export { TransactionMQProducer } from "./client/producer.js";
14
+ export { TransactionListener } from "./client/producer.js";
15
+ export { LocalTransactionState } from "./client/producer.js";
16
+ export { MessageQueueSelector } from "./client/producer.js";
17
+ export { SelectMessageQueueByHash } from "./client/producer.js";
18
+ export { SelectMessageQueueByRandom } from "./client/producer.js";
19
+ // ---- consumer ----
20
+ export { DefaultMQPushConsumer } from "./client/consumer.js";
21
+ export { DefaultMQPullConsumer } from "./client/pull_consumer.js";
22
+ export { DefaultLitePullConsumer } from "./client/lite_pull_consumer.js";
23
+ export { DefaultMQAdminExt } from "./client/admin.js";
24
+ // ---- pull schedule service (per-queue scheduled pull tasks) ----
25
+ export { PullConsumerScheduleService, PullTaskContext, DEFAULT_PULL_NEXT_DELAY_MILLIS, PULL_TASK_EXCEPTION_DELAY_MILLIS, DEFAULT_QUEUE_CHECK_INTERVAL_MILLIS, DEFAULT_SHUTDOWN_DRAIN_TIMEOUT_MILLIS, } from "./client/pull_schedule_service.js";
26
+ // ---- consume results / listeners / selectors ----
27
+ export { ConsumeConcurrentlyStatus, ConsumeOrderlyStatus, PullStatus, PullResult, ConsumeConcurrentlyContext, ConsumeOrderlyContext, MessageSelector, MessageQueueListener, MessageListener, MessageListenerConcurrently, MessageListenerOrderly, } from "./client/consumer_result.js";
28
+ // ---- message model ----
29
+ export { Message, MessageExt, MessageQueue, MessageBatch, isWaitStoreMsgOK } from "./common/message.js";
30
+ export { MessageConst } from "./common/messageConst.js";
31
+ export { MixAll } from "./common/mixAll.js";
32
+ export { MessageSysFlag, PullSysFlag, PermName, SubscriptionMode } from "./common/sysflag.js";
33
+ export { MessageAccessor } from "./common/message_accessor.js";
34
+ export { ExpressionType, SubscriptionData, FilterAPI } from "./common/subscriptionData.js";
35
+ // ---- remoting-level enums (public knobs) ----
36
+ export { MessageModel, ConsumeFromWhere, ConsumeType } from "./remoting/heartbeat.js";
@@ -0,0 +1,24 @@
1
+ export declare const DEFAULT_LOG_DIR: any;
2
+ export declare const DEFAULT_LOG_FILE = "rocketmq_node_client.log";
3
+ export declare function setLevel(level: string | number): void;
4
+ export declare class Logger {
5
+ name: string;
6
+ constructor(name?: string);
7
+ _log(level: number, levelName: string, args: any[]): void;
8
+ debug(...args: any[]): void;
9
+ info(...args: any[]): void;
10
+ warn(...args: any[]): void;
11
+ warning(...args: any[]): void;
12
+ error(...args: any[]): void;
13
+ }
14
+ export declare function getLogger(name?: string): Logger;
15
+ export declare function logFilePath(): string | null;
16
+ declare const _default: {
17
+ getLogger: typeof getLogger;
18
+ setLevel: typeof setLevel;
19
+ Logger: typeof Logger;
20
+ logFilePath: typeof logFilePath;
21
+ DEFAULT_LOG_DIR: any;
22
+ DEFAULT_LOG_FILE: string;
23
+ };
24
+ export default _default;
@@ -0,0 +1,246 @@
1
+ // -*- coding: utf-8 -*-
2
+ // Client logging: environment-variable switches plus a size-rotating file sink.
3
+ //
4
+ // ROCKETMQ_CLIENT_LOG_LEVEL TRACE|DEBUG|INFO|WARN|ERROR (default INFO)
5
+ // ROCKETMQ_CLIENT_LOG_DIR log directory (default $HOME/logs/rocketmqlogs)
6
+ // ROCKETMQ_CLIENT_LOG_FILE file name (default rocketmq_node_client.log;
7
+ // set to '' / OFF / NONE to disable the file sink)
8
+ // ROCKETMQ_CLIENT_LOG_USE_STDOUT any non-empty value -> log to stdout instead of a file
9
+ //
10
+ // The file name deliberately avoids rocketmq_client.log: if it ran concurrently
11
+ // with a classic client process on the same machine, the two processes would
12
+ // interleave writes and rotations on the same file and corrupt each other's logs.
13
+ //
14
+ // Rotation is triggered by SIZE and uses a fixed backup window (RollLocked style):
15
+ // <file>.N is the oldest (deleted first), .N-1 -> .N ... .1 -> .2, base -> .1.
16
+ // ROCKETMQ_CLIENT_LOG_FILE_MAX_SIZE default 64MB
17
+ // ROCKETMQ_CLIENT_LOG_FILE_MAX_INDEX default 10 backups
18
+ //
19
+ // Thread safety: Node runs JS on a single event-loop thread, and every write
20
+ // below is a single-line synchronous fs.writeSync — this process is the only
21
+ // writer, so no extra locking is needed.
22
+ import fs from 'node:fs';
23
+ import os from 'node:os';
24
+ import path from 'node:path';
25
+ import { format } from 'node:util';
26
+ const LEVELS = { TRACE: 5, DEBUG: 10, INFO: 20, WARN: 30, ERROR: 40 };
27
+ function levelFromEnv() {
28
+ const l = (process.env.ROCKETMQ_CLIENT_LOG_LEVEL || 'INFO').toUpperCase();
29
+ return LEVELS[l] != null ? LEVELS[l] : 20;
30
+ }
31
+ function envInt(name, def) {
32
+ const raw = process.env[name];
33
+ if (raw == null || raw === '')
34
+ return def;
35
+ const v = parseInt(raw, 10);
36
+ return Number.isFinite(v) && v > 0 ? v : def;
37
+ }
38
+ export const DEFAULT_LOG_DIR = path.join(os.homedir(), 'logs', 'rocketmqlogs');
39
+ // The default file name carries a "node" marker so that it stays deliberately
40
+ // distinct from the generic rocketmq_client.log — see the file header comment.
41
+ export const DEFAULT_LOG_FILE = 'rocketmq_node_client.log';
42
+ class FileSink {
43
+ path;
44
+ fd = null;
45
+ size = 0;
46
+ failed = false;
47
+ maxSize;
48
+ maxIndex;
49
+ constructor(filePath) {
50
+ this.path = filePath;
51
+ this.maxSize = envInt('ROCKETMQ_CLIENT_LOG_FILE_MAX_SIZE', 64 * 1024 * 1024);
52
+ this.maxIndex = envInt('ROCKETMQ_CLIENT_LOG_FILE_MAX_INDEX', 10);
53
+ }
54
+ open() {
55
+ if (this.failed)
56
+ return false;
57
+ if (this.fd != null)
58
+ return true;
59
+ try {
60
+ fs.mkdirSync(path.dirname(this.path), { recursive: true });
61
+ try {
62
+ this.size = fs.statSync(this.path).size;
63
+ }
64
+ catch (e) {
65
+ this.size = 0;
66
+ }
67
+ this.fd = fs.openSync(this.path, 'a');
68
+ return true;
69
+ }
70
+ catch (e) {
71
+ // Non-fatal: keep console-only logging, never try again this process.
72
+ this.failed = true;
73
+ console.error('failed to open rocketmq client log file:', e.message);
74
+ return false;
75
+ }
76
+ }
77
+ // rollLocked — size-based rotation: delete .N, shift .N-1..1 up,
78
+ // move base to .1, then reopen a fresh file.
79
+ roll() {
80
+ if (this.fd != null) {
81
+ try {
82
+ fs.closeSync(this.fd);
83
+ }
84
+ catch (e) { /* best effort */ }
85
+ this.fd = null;
86
+ }
87
+ try {
88
+ const top = `${this.path}.${this.maxIndex}`;
89
+ if (fs.existsSync(top)) {
90
+ try {
91
+ fs.unlinkSync(top);
92
+ }
93
+ catch (e) { /* best effort */ }
94
+ }
95
+ for (let i = this.maxIndex - 1; i >= 1; i--) {
96
+ const src = `${this.path}.${i}`;
97
+ if (!fs.existsSync(src))
98
+ continue;
99
+ const dst = `${this.path}.${i + 1}`;
100
+ if (fs.existsSync(dst)) {
101
+ try {
102
+ fs.unlinkSync(dst);
103
+ }
104
+ catch (e) { /* best effort */ }
105
+ }
106
+ try {
107
+ fs.renameSync(src, dst);
108
+ }
109
+ catch (e) { /* best effort */ }
110
+ }
111
+ if (fs.existsSync(this.path)) {
112
+ try {
113
+ fs.renameSync(this.path, `${this.path}.1`);
114
+ }
115
+ catch (e) { /* best effort */ }
116
+ }
117
+ }
118
+ catch (e) { /* rotation failure degrades to appending to the current file */ }
119
+ this.size = 0;
120
+ this.open();
121
+ }
122
+ write(line) {
123
+ if (!this.open())
124
+ return;
125
+ const buf = Buffer.from(line + '\n', 'utf8');
126
+ if (this.maxSize > 0 && this.maxIndex > 0 && this.size + buf.length > this.maxSize) {
127
+ this.roll();
128
+ if (!this.open())
129
+ return;
130
+ }
131
+ try {
132
+ fs.writeSync(this.fd, buf);
133
+ this.size += buf.length;
134
+ }
135
+ catch (e) {
136
+ this.failed = true;
137
+ try {
138
+ if (this.fd != null)
139
+ fs.closeSync(this.fd);
140
+ }
141
+ catch (e2) { /* ignore */ }
142
+ this.fd = null;
143
+ }
144
+ }
145
+ close() {
146
+ if (this.fd != null) {
147
+ try {
148
+ fs.closeSync(this.fd);
149
+ }
150
+ catch (e) { /* ignore */ }
151
+ this.fd = null;
152
+ }
153
+ }
154
+ }
155
+ // Resolve the sink once at module load.
156
+ function buildSink() {
157
+ if (process.env.ROCKETMQ_CLIENT_LOG_USE_STDOUT)
158
+ return null;
159
+ let file = process.env.ROCKETMQ_CLIENT_LOG_FILE;
160
+ if (file === undefined)
161
+ file = DEFAULT_LOG_FILE;
162
+ if (file === '' || file.toUpperCase() === 'OFF' || file.toUpperCase() === 'NONE')
163
+ return null;
164
+ const dir = process.env.ROCKETMQ_CLIENT_LOG_DIR || DEFAULT_LOG_DIR;
165
+ // A file value containing a separator is treated as a full path, else it is
166
+ // joined under the log dir.
167
+ const p = path.isAbsolute(file) || file.includes('/') || file.includes('\\')
168
+ ? file : path.join(dir, file);
169
+ return new FileSink(p);
170
+ }
171
+ const sink = buildSink();
172
+ if (sink != null) {
173
+ const onExit = () => { sink.close(); };
174
+ process.once('exit', onExit);
175
+ }
176
+ let gLevel = levelFromEnv();
177
+ export function setLevel(level) {
178
+ if (typeof level === 'number' && LEVELS.TRACE <= level && level <= LEVELS.ERROR)
179
+ gLevel = level;
180
+ else if (typeof level === 'string' && LEVELS[level] != null)
181
+ gLevel = LEVELS[level];
182
+ }
183
+ function pad2(n) { return n < 10 ? '0' + n : '' + n; }
184
+ function ts() {
185
+ const d = new Date();
186
+ return `${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())} ` +
187
+ `${pad2(d.getHours())}:${pad2(d.getMinutes())}:${pad2(d.getSeconds())}.` +
188
+ `${String(d.getMilliseconds()).padStart(3, '0')}`;
189
+ }
190
+ export class Logger {
191
+ name;
192
+ constructor(name = 'rocketmq') {
193
+ this.name = name;
194
+ }
195
+ _log(level, levelName, args) {
196
+ if (level < gLevel)
197
+ return;
198
+ // Roughly 70 call sites inside the client use printf-style placeholders
199
+ // (logger.info('rebalance changed, group=%s assigned=%d', g, n)).
200
+ // With plain space joining `%s` would be printed verbatim with the arguments
201
+ // dumped after it, making the log unreadable.
202
+ // util.format substitutes %s/%d/%j, and when the first argument is not a
203
+ // string it degrades to the original space joining — so existing multi-argument
204
+ // log calls keep working unchanged.
205
+ const msg = (args.length > 1 && typeof args[0] === 'string')
206
+ ? format(...args)
207
+ : args.map(a => (typeof a === 'string' ? a : safeStringify(a))).join(' ');
208
+ const line = `${ts()} ${levelName.padEnd(5)} ${this.name} - ${msg}`;
209
+ if (level >= LEVELS.ERROR)
210
+ console.error(line);
211
+ else
212
+ console.log(line);
213
+ if (sink)
214
+ sink.write(line);
215
+ }
216
+ debug(...args) { this._log(LEVELS.DEBUG, 'DEBUG', args); }
217
+ info(...args) { this._log(LEVELS.INFO, 'INFO', args); }
218
+ warn(...args) { this._log(LEVELS.WARN, 'WARN', args); }
219
+ // `warning` alias: roughly 30 call sites in the client use this name (offset
220
+ // store, trace dispatcher, consume loops, etc.). Without the alias the error
221
+ // paths themselves would throw a TypeError.
222
+ warning(...args) { this._log(LEVELS.WARN, 'WARN', args); }
223
+ error(...args) { this._log(LEVELS.ERROR, 'ERROR', args); }
224
+ }
225
+ function safeStringify(o) {
226
+ try {
227
+ return JSON.stringify(o);
228
+ }
229
+ catch (e) {
230
+ return String(o);
231
+ }
232
+ }
233
+ const cache = new Map();
234
+ export function getLogger(name = 'rocketmq') {
235
+ let l = cache.get(name);
236
+ if (!l) {
237
+ l = new Logger(name);
238
+ cache.set(name, l);
239
+ }
240
+ return l;
241
+ }
242
+ // Test/diagnostic hook: the resolved sink path (null = stdout mode or disabled).
243
+ export function logFilePath() {
244
+ return sink != null ? sink.path : null;
245
+ }
246
+ export default { getLogger, setLevel, Logger, logFilePath, DEFAULT_LOG_DIR, DEFAULT_LOG_FILE };
@@ -0,0 +1,16 @@
1
+ import { Buffer } from 'node:buffer';
2
+ import { RemotingCommand } from './remotingCommand.js';
3
+ export declare function signAcl(accessKey: string, secretKey: string, extFields: Record<string, string>, body: Buffer | null, securityToken?: string | null): string;
4
+ export declare class AclRPCHook {
5
+ accessKey: string;
6
+ secretKey: string;
7
+ securityToken: string | null;
8
+ constructor(accessKey: string, secretKey: string, securityToken?: string | null);
9
+ doBeforeRequest(_addr: string, cmd: RemotingCommand): void;
10
+ doAfterResponse(_addr: string, _request: RemotingCommand | null, _response: RemotingCommand | null): void;
11
+ }
12
+ declare const _default: {
13
+ signAcl: typeof signAcl;
14
+ AclRPCHook: typeof AclRPCHook;
15
+ };
16
+ export default _default;
@@ -0,0 +1,39 @@
1
+ import crypto from 'node:crypto';
2
+ import { Buffer } from 'node:buffer';
3
+ export function signAcl(accessKey, secretKey, extFields, body, securityToken = null) {
4
+ extFields['AccessKey'] = accessKey;
5
+ if (securityToken != null)
6
+ extFields['SecurityToken'] = securityToken;
7
+ const keys = Object.keys(extFields).sort();
8
+ let content = '';
9
+ for (const k of keys) {
10
+ if (k === 'Signature')
11
+ continue;
12
+ content += extFields[k];
13
+ }
14
+ const buf = Buffer.concat([Buffer.from(content, 'utf8'), body || Buffer.alloc(0)]);
15
+ const sig = crypto.createHmac('sha1', secretKey).update(buf).digest().toString('base64');
16
+ extFields['Signature'] = sig;
17
+ return sig;
18
+ }
19
+ export class AclRPCHook {
20
+ accessKey;
21
+ secretKey;
22
+ securityToken;
23
+ constructor(accessKey, secretKey, securityToken = null) {
24
+ this.accessKey = accessKey;
25
+ this.secretKey = secretKey;
26
+ this.securityToken = securityToken;
27
+ }
28
+ doBeforeRequest(_addr, cmd) {
29
+ // extFields must be materialized before signing: this implementation's RemotingCommand generates
30
+ // extFields lazily (only inside headerEncode()), so without first calling makeCustomHeaderToNet(),
31
+ // the ACL signature would cover an empty field set.
32
+ cmd.makeCustomHeaderToNet();
33
+ signAcl(this.accessKey, this.secretKey, cmd.extFields, cmd.body, this.securityToken);
34
+ }
35
+ doAfterResponse(_addr, _request, _response) {
36
+ // no-op
37
+ }
38
+ }
39
+ export default { signAcl, AclRPCHook };