@azure/event-hubs 6.0.1-alpha.20250619.1 → 6.0.1-alpha.20250804.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 (140) hide show
  1. package/dist/browser/batchingPartitionChannel.js +23 -17
  2. package/dist/browser/batchingPartitionChannel.js.map +1 -1
  3. package/dist/browser/connectionContext.js +18 -32
  4. package/dist/browser/connectionContext.js.map +1 -1
  5. package/dist/browser/diagnostics/instrumentEventData.js +6 -7
  6. package/dist/browser/diagnostics/instrumentEventData.js.map +1 -1
  7. package/dist/browser/eventData.js +6 -4
  8. package/dist/browser/eventData.js.map +1 -1
  9. package/dist/browser/eventDataAdapter.js +5 -2
  10. package/dist/browser/eventDataAdapter.js.map +1 -1
  11. package/dist/browser/eventDataBatch.js +61 -9
  12. package/dist/browser/eventDataBatch.js.map +1 -1
  13. package/dist/browser/eventHubBufferedProducerClient.js +65 -50
  14. package/dist/browser/eventHubBufferedProducerClient.js.map +1 -1
  15. package/dist/browser/eventHubConsumerClient.js +70 -24
  16. package/dist/browser/eventHubConsumerClient.js.map +1 -1
  17. package/dist/browser/eventHubProducerClient.js +58 -15
  18. package/dist/browser/eventHubProducerClient.js.map +1 -1
  19. package/dist/browser/eventHubSender.js +118 -35
  20. package/dist/browser/eventHubSender.js.map +1 -1
  21. package/dist/browser/eventProcessor.js +27 -5
  22. package/dist/browser/eventProcessor.js.map +1 -1
  23. package/dist/browser/impl/awaitableQueue.js +6 -2
  24. package/dist/browser/impl/awaitableQueue.js.map +1 -1
  25. package/dist/browser/impl/partitionAssigner.js +2 -4
  26. package/dist/browser/impl/partitionAssigner.js.map +1 -1
  27. package/dist/browser/impl/partitionGate.js +1 -3
  28. package/dist/browser/impl/partitionGate.js.map +1 -1
  29. package/dist/browser/inMemoryCheckpointStore.js +10 -8
  30. package/dist/browser/inMemoryCheckpointStore.js.map +1 -1
  31. package/dist/browser/loadBalancerStrategies/balancedStrategy.js +1 -0
  32. package/dist/browser/loadBalancerStrategies/balancedStrategy.js.map +1 -1
  33. package/dist/browser/loadBalancerStrategies/greedyStrategy.js +1 -0
  34. package/dist/browser/loadBalancerStrategies/greedyStrategy.js.map +1 -1
  35. package/dist/browser/managementClient.js +53 -19
  36. package/dist/browser/managementClient.js.map +1 -1
  37. package/dist/browser/partitionProcessor.js +5 -2
  38. package/dist/browser/partitionProcessor.js.map +1 -1
  39. package/dist/browser/partitionPump.js +15 -6
  40. package/dist/browser/partitionPump.js.map +1 -1
  41. package/dist/browser/partitionReceiver.js +30 -25
  42. package/dist/browser/partitionReceiver.js.map +1 -1
  43. package/dist/browser/pumpManager.js +3 -1
  44. package/dist/browser/pumpManager.js.map +1 -1
  45. package/dist/browser/util/delayWithoutThrow.js +1 -1
  46. package/dist/browser/util/delayWithoutThrow.js.map +1 -1
  47. package/dist/commonjs/batchingPartitionChannel.js +23 -17
  48. package/dist/commonjs/batchingPartitionChannel.js.map +1 -1
  49. package/dist/commonjs/connectionContext.js +18 -32
  50. package/dist/commonjs/connectionContext.js.map +1 -1
  51. package/dist/commonjs/diagnostics/instrumentEventData.js +6 -7
  52. package/dist/commonjs/diagnostics/instrumentEventData.js.map +1 -1
  53. package/dist/commonjs/eventData.js +6 -4
  54. package/dist/commonjs/eventData.js.map +1 -1
  55. package/dist/commonjs/eventDataAdapter.js +5 -2
  56. package/dist/commonjs/eventDataAdapter.js.map +1 -1
  57. package/dist/commonjs/eventDataBatch.js +61 -9
  58. package/dist/commonjs/eventDataBatch.js.map +1 -1
  59. package/dist/commonjs/eventHubBufferedProducerClient.js +65 -50
  60. package/dist/commonjs/eventHubBufferedProducerClient.js.map +1 -1
  61. package/dist/commonjs/eventHubConsumerClient.js +70 -24
  62. package/dist/commonjs/eventHubConsumerClient.js.map +1 -1
  63. package/dist/commonjs/eventHubProducerClient.js +58 -15
  64. package/dist/commonjs/eventHubProducerClient.js.map +1 -1
  65. package/dist/commonjs/eventHubSender.js +118 -35
  66. package/dist/commonjs/eventHubSender.js.map +1 -1
  67. package/dist/commonjs/eventProcessor.js +27 -5
  68. package/dist/commonjs/eventProcessor.js.map +1 -1
  69. package/dist/commonjs/impl/awaitableQueue.js +6 -2
  70. package/dist/commonjs/impl/awaitableQueue.js.map +1 -1
  71. package/dist/commonjs/impl/partitionAssigner.js +2 -4
  72. package/dist/commonjs/impl/partitionAssigner.js.map +1 -1
  73. package/dist/commonjs/impl/partitionGate.js +1 -3
  74. package/dist/commonjs/impl/partitionGate.js.map +1 -1
  75. package/dist/commonjs/inMemoryCheckpointStore.js +10 -8
  76. package/dist/commonjs/inMemoryCheckpointStore.js.map +1 -1
  77. package/dist/commonjs/loadBalancerStrategies/balancedStrategy.js +1 -0
  78. package/dist/commonjs/loadBalancerStrategies/balancedStrategy.js.map +1 -1
  79. package/dist/commonjs/loadBalancerStrategies/greedyStrategy.js +1 -0
  80. package/dist/commonjs/loadBalancerStrategies/greedyStrategy.js.map +1 -1
  81. package/dist/commonjs/managementClient.js +53 -19
  82. package/dist/commonjs/managementClient.js.map +1 -1
  83. package/dist/commonjs/partitionProcessor.js +5 -2
  84. package/dist/commonjs/partitionProcessor.js.map +1 -1
  85. package/dist/commonjs/partitionPump.js +15 -6
  86. package/dist/commonjs/partitionPump.js.map +1 -1
  87. package/dist/commonjs/partitionReceiver.js +30 -25
  88. package/dist/commonjs/partitionReceiver.js.map +1 -1
  89. package/dist/commonjs/pumpManager.js +3 -1
  90. package/dist/commonjs/pumpManager.js.map +1 -1
  91. package/dist/commonjs/tsdoc-metadata.json +11 -11
  92. package/dist/commonjs/util/delayWithoutThrow.js +1 -1
  93. package/dist/commonjs/util/delayWithoutThrow.js.map +1 -1
  94. package/dist/esm/batchingPartitionChannel.js +23 -17
  95. package/dist/esm/batchingPartitionChannel.js.map +1 -1
  96. package/dist/esm/connectionContext.js +18 -32
  97. package/dist/esm/connectionContext.js.map +1 -1
  98. package/dist/esm/diagnostics/instrumentEventData.js +6 -7
  99. package/dist/esm/diagnostics/instrumentEventData.js.map +1 -1
  100. package/dist/esm/eventData.js +6 -4
  101. package/dist/esm/eventData.js.map +1 -1
  102. package/dist/esm/eventDataAdapter.js +5 -2
  103. package/dist/esm/eventDataAdapter.js.map +1 -1
  104. package/dist/esm/eventDataBatch.js +61 -9
  105. package/dist/esm/eventDataBatch.js.map +1 -1
  106. package/dist/esm/eventHubBufferedProducerClient.js +65 -50
  107. package/dist/esm/eventHubBufferedProducerClient.js.map +1 -1
  108. package/dist/esm/eventHubConsumerClient.js +70 -24
  109. package/dist/esm/eventHubConsumerClient.js.map +1 -1
  110. package/dist/esm/eventHubProducerClient.js +58 -15
  111. package/dist/esm/eventHubProducerClient.js.map +1 -1
  112. package/dist/esm/eventHubSender.js +118 -35
  113. package/dist/esm/eventHubSender.js.map +1 -1
  114. package/dist/esm/eventProcessor.js +27 -5
  115. package/dist/esm/eventProcessor.js.map +1 -1
  116. package/dist/esm/impl/awaitableQueue.js +6 -2
  117. package/dist/esm/impl/awaitableQueue.js.map +1 -1
  118. package/dist/esm/impl/partitionAssigner.js +2 -4
  119. package/dist/esm/impl/partitionAssigner.js.map +1 -1
  120. package/dist/esm/impl/partitionGate.js +1 -3
  121. package/dist/esm/impl/partitionGate.js.map +1 -1
  122. package/dist/esm/inMemoryCheckpointStore.js +10 -8
  123. package/dist/esm/inMemoryCheckpointStore.js.map +1 -1
  124. package/dist/esm/loadBalancerStrategies/balancedStrategy.js +1 -0
  125. package/dist/esm/loadBalancerStrategies/balancedStrategy.js.map +1 -1
  126. package/dist/esm/loadBalancerStrategies/greedyStrategy.js +1 -0
  127. package/dist/esm/loadBalancerStrategies/greedyStrategy.js.map +1 -1
  128. package/dist/esm/managementClient.js +53 -19
  129. package/dist/esm/managementClient.js.map +1 -1
  130. package/dist/esm/partitionProcessor.js +5 -2
  131. package/dist/esm/partitionProcessor.js.map +1 -1
  132. package/dist/esm/partitionPump.js +15 -6
  133. package/dist/esm/partitionPump.js.map +1 -1
  134. package/dist/esm/partitionReceiver.js +30 -25
  135. package/dist/esm/partitionReceiver.js.map +1 -1
  136. package/dist/esm/pumpManager.js +3 -1
  137. package/dist/esm/pumpManager.js.map +1 -1
  138. package/dist/esm/util/delayWithoutThrow.js +1 -1
  139. package/dist/esm/util/delayWithoutThrow.js.map +1 -1
  140. package/package.json +1 -1
@@ -21,22 +21,100 @@ const utils_js_1 = require("./util/utils.js");
21
21
  * @internal
22
22
  */
23
23
  class EventHubSender {
24
+ /**
25
+ * The unique lock name per connection that is used to acquire the
26
+ * lock for establishing a sender link by an entity on that connection.
27
+ */
28
+ senderLock = (0, utils_js_1.getRandomName)("sender");
29
+ /**
30
+ * The handler function to handle errors that happen on the
31
+ * underlying sender.
32
+ */
33
+ _onAmqpError;
34
+ /**
35
+ * The handler function to handle "sender_close" event
36
+ * that happens on the underlying sender.
37
+ */
38
+ _onAmqpClose;
39
+ /**
40
+ * The message handler that will be set as the handler on
41
+ * the underlying rhea sender's session for the "session_error" event.
42
+ */
43
+ _onSessionError;
44
+ /**
45
+ * The message handler that will be set as the handler on
46
+ * the underlying rhea sender's session for the "session_close" event.
47
+ */
48
+ _onSessionClose;
49
+ /**
50
+ * The AMQP sender link.
51
+ */
52
+ _sender;
53
+ /**
54
+ * The partition ID.
55
+ */
56
+ partitionId;
57
+ /**
58
+ * Indicates whether the sender is configured for idempotent publishing.
59
+ */
60
+ _isIdempotentProducer;
61
+ /**
62
+ * Indicates whether the sender has an in-flight send while idempotent
63
+ * publishing is enabled.
64
+ */
65
+ _hasPendingSend;
66
+ /**
67
+ * A local copy of the PartitionPublishingProperties that can be mutated to
68
+ * keep track of the lastSequenceNumber used.
69
+ */
70
+ _localPublishingProperties;
71
+ /**
72
+ * The user-provided set of options that can be specified to influence
73
+ * publishing behavior specific to a partition.
74
+ */
75
+ _userProvidedPublishingOptions;
76
+ /**
77
+ * Indicates whether the link is in the process of connecting
78
+ * (establishing) itself. Default value: `false`.
79
+ */
80
+ isConnecting = false;
81
+ /**
82
+ * The unique name for the entity (mostly a guid).
83
+ */
84
+ name;
85
+ /**
86
+ * The address in the following form:
87
+ * - `"<hubName>"`
88
+ * - `"<hubName>/Partitions/<partitionId>"`.
89
+ */
90
+ address;
91
+ /**
92
+ * The token audience in the following form:
93
+ * - `"sb://<yournamespace>.servicebus.windows.net/<hubName>"`
94
+ * - `"sb://<yournamespace>.servicebus.windows.net/<hubName>/Partitions/<partitionId>"`.
95
+ */
96
+ audience;
97
+ /**
98
+ * Provides relevant information about the amqp connection,
99
+ * cbs and $management sessions, token provider, sender and receivers.
100
+ */
101
+ _context;
102
+ /**
103
+ * The auth loop.
104
+ */
105
+ authLoop;
106
+ /**
107
+ * The logger.
108
+ */
109
+ logger;
110
+ /** The client identifier */
111
+ _id;
24
112
  /**
25
113
  * Creates a new EventHubSender instance.
26
114
  * @param context - The connection context.
27
115
  * @param options - Options used to configure the EventHubSender.
28
116
  */
29
117
  constructor(context, senderId, { partitionId, enableIdempotentProducer, partitionPublishingOptions }) {
30
- /**
31
- * The unique lock name per connection that is used to acquire the
32
- * lock for establishing a sender link by an entity on that connection.
33
- */
34
- this.senderLock = (0, utils_js_1.getRandomName)("sender");
35
- /**
36
- * Indicates whether the link is in the process of connecting
37
- * (establishing) itself. Default value: `false`.
38
- */
39
- this.isConnecting = false;
40
118
  this.address = context.config.getSenderAddress(partitionId);
41
119
  this.name = this.address;
42
120
  this._id = senderId;
@@ -60,7 +138,7 @@ class EventHubSender {
60
138
  this._onAmqpClose = async (eventContext) => {
61
139
  const sender = this._sender || eventContext.sender;
62
140
  this.logger.verbose("'sender_close' event occurred. Value for isItselfClosed on the receiver is: '%s' " +
63
- "Value for isConnecting on the session is: '%s'.", sender === null || sender === void 0 ? void 0 : sender.isItselfClosed().toString(), this.isConnecting);
141
+ "Value for isConnecting on the session is: '%s'.", sender?.isItselfClosed().toString(), this.isConnecting);
64
142
  if (sender && !this.isConnecting) {
65
143
  // Call close to clean up timers & other resources
66
144
  await sender.close().catch((err) => {
@@ -71,7 +149,7 @@ class EventHubSender {
71
149
  this._onSessionClose = async (eventContext) => {
72
150
  const sender = this._sender || eventContext.sender;
73
151
  this.logger.verbose("'session_close' event occurred. Value for isSessionItselfClosed on the session is: '%s' " +
74
- "Value for isConnecting on the session is: '%s'.", sender === null || sender === void 0 ? void 0 : sender.isSessionItselfClosed().toString(), this.isConnecting);
152
+ "Value for isConnecting on the session is: '%s'.", sender?.isSessionItselfClosed().toString(), this.isConnecting);
75
153
  if (sender && !this.isConnecting) {
76
154
  // Call close to clean up timers & other resources
77
155
  await sender.close().catch((err) => {
@@ -84,19 +162,18 @@ class EventHubSender {
84
162
  * Deletes the sender from the context. Clears the token renewal timer. Closes the sender link.
85
163
  */
86
164
  async close() {
87
- var _a;
88
165
  try {
89
166
  if (this._sender) {
90
167
  this.logger.info("closing");
91
168
  const senderLink = this._sender;
92
169
  this._deleteFromCache();
93
170
  await senderLink.close();
94
- (_a = this.authLoop) === null || _a === void 0 ? void 0 : _a.stop();
171
+ this.authLoop?.stop();
95
172
  this.logger.verbose("closed.");
96
173
  }
97
174
  }
98
175
  catch (err) {
99
- const msg = `an error occurred while closing: ${err === null || err === void 0 ? void 0 : err.name}: ${err === null || err === void 0 ? void 0 : err.message}`;
176
+ const msg = `an error occurred while closing: ${err?.name}: ${err?.message}`;
100
177
  this.logger.warning(msg);
101
178
  (0, logger_js_1.logErrorStackTrace)(err);
102
179
  throw err;
@@ -128,14 +205,13 @@ class EventHubSender {
128
205
  * for the producer client.
129
206
  */
130
207
  async getPartitionPublishingProperties(options = {}) {
131
- var _a, _b;
132
208
  if (this._localPublishingProperties) {
133
209
  // Send a copy of the properties so it can't be mutated downstream.
134
- return Object.assign({}, this._localPublishingProperties);
210
+ return { ...this._localPublishingProperties };
135
211
  }
136
212
  const properties = {
137
213
  isIdempotentPublishingEnabled: this._isIdempotentProducer,
138
- partitionId: (_a = this.partitionId) !== null && _a !== void 0 ? _a : "",
214
+ partitionId: this.partitionId ?? "",
139
215
  };
140
216
  if (this._isIdempotentProducer) {
141
217
  this._sender = await this._getLink(options);
@@ -145,14 +221,14 @@ class EventHubSender {
145
221
  // deleted while setting up token refreshing, make sure it exists.
146
222
  throw new Error(`Failed to retrieve partition publishing properties for partition "${this.partitionId}".`);
147
223
  }
148
- const { [constants_js_1.idempotentProducerAmqpPropertyNames.epoch]: ownerLevel, [constants_js_1.idempotentProducerAmqpPropertyNames.producerId]: producerGroupId, [constants_js_1.idempotentProducerAmqpPropertyNames.producerSequenceNumber]: lastPublishedSequenceNumber, } = (_b = this._sender.properties) !== null && _b !== void 0 ? _b : {};
224
+ const { [constants_js_1.idempotentProducerAmqpPropertyNames.epoch]: ownerLevel, [constants_js_1.idempotentProducerAmqpPropertyNames.producerId]: producerGroupId, [constants_js_1.idempotentProducerAmqpPropertyNames.producerSequenceNumber]: lastPublishedSequenceNumber, } = this._sender.properties ?? {};
149
225
  properties.ownerLevel = parseInt(ownerLevel, 10);
150
226
  properties.producerGroupId = parseInt(producerGroupId, 10);
151
227
  properties.lastPublishedSequenceNumber = parseInt(lastPublishedSequenceNumber, 10);
152
228
  }
153
229
  this._localPublishingProperties = properties;
154
230
  // Send a copy of the properties so it can't be mutated downstream.
155
- return Object.assign({}, properties);
231
+ return { ...properties };
156
232
  }
157
233
  /**
158
234
  * Send a batch of EventData to the EventHub. The "message_annotations",
@@ -190,7 +266,7 @@ class EventHubSender {
190
266
  }
191
267
  catch (err) {
192
268
  rollbackIdempotentSequenceNumbers(events);
193
- this.logger.warning(`an error occurred while sending the batch message ${err === null || err === void 0 ? void 0 : err.name}: ${err === null || err === void 0 ? void 0 : err.message}`);
269
+ this.logger.warning(`an error occurred while sending the batch message ${err?.name}: ${err?.message}`);
194
270
  (0, logger_js_1.logErrorStackTrace)(err);
195
271
  throw err;
196
272
  }
@@ -204,11 +280,10 @@ class EventHubSender {
204
280
  * @param sender - The rhea sender that contains the idempotent producer properties.
205
281
  */
206
282
  _populateLocalPublishingProperties(sender) {
207
- var _a, _b;
208
- const { [constants_js_1.idempotentProducerAmqpPropertyNames.epoch]: ownerLevel, [constants_js_1.idempotentProducerAmqpPropertyNames.producerId]: producerGroupId, [constants_js_1.idempotentProducerAmqpPropertyNames.producerSequenceNumber]: lastPublishedSequenceNumber, } = (_a = sender.properties) !== null && _a !== void 0 ? _a : {};
283
+ const { [constants_js_1.idempotentProducerAmqpPropertyNames.epoch]: ownerLevel, [constants_js_1.idempotentProducerAmqpPropertyNames.producerId]: producerGroupId, [constants_js_1.idempotentProducerAmqpPropertyNames.producerSequenceNumber]: lastPublishedSequenceNumber, } = sender.properties ?? {};
209
284
  this._localPublishingProperties = {
210
285
  isIdempotentPublishingEnabled: this._isIdempotentProducer,
211
- partitionId: (_b = this.partitionId) !== null && _b !== void 0 ? _b : "",
286
+ partitionId: this.partitionId ?? "",
212
287
  lastPublishedSequenceNumber,
213
288
  ownerLevel,
214
289
  producerGroupId,
@@ -255,7 +330,6 @@ class EventHubSender {
255
330
  const timeoutInMs = (0, retries_js_1.getRetryAttemptTimeoutInMs)(retryOptions);
256
331
  retryOptions.timeoutInMs = timeoutInMs;
257
332
  const sendEventPromise = async () => {
258
- var _a, _b;
259
333
  const initStartTime = Date.now();
260
334
  // TODO: (jeremymeng) A or B
261
335
  // variant A:
@@ -269,7 +343,7 @@ class EventHubSender {
269
343
  if (!sender.sendable() && timeoutInMs - timeTakenByInit > waitTimeForSendable) {
270
344
  this.logger.verbose("waiting for 1 second for sender to become sendable");
271
345
  await (0, core_amqp_1.delay)(waitTimeForSendable);
272
- this.logger.verbose("after waiting for a second, credit: %d available: %d", sender.credit, (_b = (_a = sender.session) === null || _a === void 0 ? void 0 : _a.outgoing) === null || _b === void 0 ? void 0 : _b.available());
346
+ this.logger.verbose("after waiting for a second, credit: %d available: %d", sender.credit, sender.session?.outgoing?.available());
273
347
  }
274
348
  else {
275
349
  waitTimeForSendable = 0;
@@ -320,7 +394,7 @@ class EventHubSender {
320
394
  }
321
395
  catch (err) {
322
396
  const translatedError = (0, core_amqp_1.translate)(err);
323
- this.logger.warning("an error occurred while sending the message %s", `${translatedError === null || translatedError === void 0 ? void 0 : translatedError.name}: ${translatedError === null || translatedError === void 0 ? void 0 : translatedError.message}`);
397
+ this.logger.warning("an error occurred while sending the message %s", `${translatedError?.name}: ${translatedError?.message}`);
324
398
  (0, logger_js_1.logErrorStackTrace)(translatedError);
325
399
  throw translatedError;
326
400
  }
@@ -338,7 +412,11 @@ class EventHubSender {
338
412
  return core_amqp_1.defaultCancellableLock.acquire(this.senderLock, () => {
339
413
  const taskStartTime = Date.now();
340
414
  const taskTimeoutInMs = timeoutInMs - (taskStartTime - startTime);
341
- return this._init(Object.assign(Object.assign({}, senderOptions), { abortSignal: options.abortSignal, timeoutInMs: taskTimeoutInMs }));
415
+ return this._init({
416
+ ...senderOptions,
417
+ abortSignal: options.abortSignal,
418
+ timeoutInMs: taskTimeoutInMs,
419
+ });
342
420
  }, { abortSignal: options.abortSignal, timeoutInMs: timeoutInMs });
343
421
  };
344
422
  const config = {
@@ -353,7 +431,7 @@ class EventHubSender {
353
431
  }
354
432
  catch (err) {
355
433
  const translatedError = (0, core_amqp_1.translate)(err);
356
- this.logger.warning("an error occurred while creating: %s", `${translatedError === null || translatedError === void 0 ? void 0 : translatedError.name}: ${translatedError === null || translatedError === void 0 ? void 0 : translatedError.message}`);
434
+ this.logger.warning("an error occurred while creating: %s", `${translatedError?.name}: ${translatedError?.message}`);
357
435
  (0, logger_js_1.logErrorStackTrace)(translatedError);
358
436
  throw translatedError;
359
437
  }
@@ -390,7 +468,7 @@ class EventHubSender {
390
468
  }
391
469
  catch (err) {
392
470
  const translatedError = (0, core_amqp_1.translate)(err);
393
- this.logger.warning("an error occurred while being created: %s", `${translatedError === null || translatedError === void 0 ? void 0 : translatedError.name}: ${translatedError === null || translatedError === void 0 ? void 0 : translatedError.message}`);
471
+ this.logger.warning("an error occurred while being created: %s", `${translatedError?.name}: ${translatedError?.message}`);
394
472
  (0, logger_js_1.logErrorStackTrace)(translatedError);
395
473
  throw translatedError;
396
474
  }
@@ -473,7 +551,6 @@ function generateIdempotentLinkProperties(userProvidedPublishingOptions, localPu
473
551
  * @param options - Options used to configure this function.
474
552
  */
475
553
  function transformEventsForSend(events, publishingProps, options = {}) {
476
- var _a;
477
554
  if ((0, eventDataBatch_js_1.isEventDataBatch)(events)) {
478
555
  return events._generateMessage(publishingProps);
479
556
  }
@@ -481,18 +558,24 @@ function transformEventsForSend(events, publishingProps, options = {}) {
481
558
  const eventCount = events.length;
482
559
  // convert events to rhea messages
483
560
  const rheaMessages = [];
484
- const tracingProperties = (_a = options.tracingProperties) !== null && _a !== void 0 ? _a : [];
561
+ const tracingProperties = options.tracingProperties ?? [];
485
562
  for (let i = 0; i < eventCount; i++) {
486
563
  const originalEvent = events[i];
487
564
  const tracingProperty = tracingProperties[i];
488
565
  // Create a copy of the user's event so we can add the tracing property.
489
- const event = Object.assign(Object.assign({}, originalEvent), { properties: Object.assign(Object.assign({}, originalEvent.properties), tracingProperty) });
566
+ const event = {
567
+ ...originalEvent,
568
+ properties: { ...originalEvent.properties, ...tracingProperty },
569
+ };
490
570
  const rheaMessage = (0, eventData_js_1.toRheaMessage)(event, options.partitionKey);
491
571
  // populate idempotent message annotations
492
572
  const { lastPublishedSequenceNumber = 0 } = publishingProps;
493
573
  const startingSequenceNumber = lastPublishedSequenceNumber + 1;
494
574
  const pendingPublishSequenceNumber = startingSequenceNumber + i;
495
- (0, eventData_js_1.populateIdempotentMessageAnnotations)(rheaMessage, Object.assign(Object.assign({}, publishingProps), { publishSequenceNumber: pendingPublishSequenceNumber }));
575
+ (0, eventData_js_1.populateIdempotentMessageAnnotations)(rheaMessage, {
576
+ ...publishingProps,
577
+ publishSequenceNumber: pendingPublishSequenceNumber,
578
+ });
496
579
  if (publishingProps.isIdempotentPublishingEnabled) {
497
580
  // Set pending seq number on user's event.
498
581
  originalEvent[constants_js_1.PENDING_PUBLISH_SEQ_NUM_SYMBOL] =
@@ -507,7 +590,7 @@ function transformEventsForSend(events, publishingProps, options = {}) {
507
590
  // Set message_annotations of the first message as
508
591
  // that of the envelope (batch message).
509
592
  if (rheaMessages[0].message_annotations) {
510
- batchMessage.message_annotations = Object.assign({}, rheaMessages[0].message_annotations);
593
+ batchMessage.message_annotations = { ...rheaMessages[0].message_annotations };
511
594
  }
512
595
  // Finally encode the envelope (batch message).
513
596
  return rhea_promise_1.message.encode(batchMessage);
@@ -1 +1 @@
1
- {"version":3,"file":"eventHubSender.js","sourceRoot":"","sources":["../../src/eventHubSender.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AA6qBlC,4EAyCC;AAaD,wDA4DC;AArxBD,+CAA8C;AAE9C,gDAO0B;AAE1B,iDAAqF;AAErF,2DAAuD;AAEvD,2CAAoG;AASpG,kDAA+D;AAC/D,sDAI6B;AAC7B,gDAA6C;AAC7C,8CAAiD;AAEjD,+CAAyC;AACzC,8CAAgD;AAqBhD;;;GAGG;AACH,MAAa,cAAc;IA2FzB;;;;OAIG;IACH,YACE,OAA0B,EAC1B,QAAgB,EAChB,EAAE,WAAW,EAAE,wBAAwB,EAAE,0BAA0B,EAAyB;QAlG9F;;;WAGG;QACc,eAAU,GAAW,IAAA,wBAAa,EAAC,QAAQ,CAAC,CAAC;QAgD9D;;;WAGG;QACK,iBAAY,GAAY,KAAK,CAAC;QA4CpC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC;QAC5D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC;QACzB,IAAI,CAAC,GAAG,GAAG,QAAQ,CAAC;QACpB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;QAC9D,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,qBAAqB,GAAG,wBAAwB,CAAC;QACtD,IAAI,CAAC,8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IAClD,CAAC;SAAM,CAAC;QACN,iFAAiF;QACjF,8DAA8D;QAC9D,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,KAAK,CAAC,wBAAwB,GAAG,KAAK,CAAC,6CAA8B,CAAC,CAAC;YACvE,OAAO,KAAK,CAAC,6CAA8B,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,iCAAiC,CACxC,MAAuE;IAEvE,IAAI,IAAA,oCAAgB,EAAC,MAAM,CAAC,EAAE,CAAC;QAC7B,yBAAyB;IAC3B,CAAC;SAAM,CAAC;QACN,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,OAAO,KAAK,CAAC,6CAA8B,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n AmqpError,\n AwaitableSender,\n AwaitableSenderOptions,\n EventContext,\n OnAmqpEvent,\n Message as RheaMessage,\n} from \"rhea-promise\";\nimport { message, types } from \"rhea-promise\";\nimport type { RetryConfig, RetryOptions } from \"@azure/core-amqp\";\nimport {\n ErrorNameConditionMapper,\n RetryOperationType,\n defaultCancellableLock,\n delay,\n retry,\n translate,\n} from \"@azure/core-amqp\";\nimport type { EventData, EventDataInternal } from \"./eventData.js\";\nimport { populateIdempotentMessageAnnotations, toRheaMessage } from \"./eventData.js\";\nimport type { EventDataBatch, EventDataBatchImpl } from \"./eventDataBatch.js\";\nimport { isEventDataBatch } from \"./eventDataBatch.js\";\nimport type { SimpleLogger } from \"./logger.js\";\nimport { logErrorStackTrace, createSimpleLogger, logger, createSenderLogPrefix } from \"./logger.js\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type { ConnectionContext } from \"./connectionContext.js\";\nimport type { EventHubProducerOptions, IdempotentLinkProperties } from \"./models/private.js\";\nimport type { SendOptions } from \"./models/public.js\";\nimport type {\n PartitionPublishingOptions,\n PartitionPublishingProperties,\n} from \"./models/private.js\";\nimport { getRetryAttemptTimeoutInMs } from \"./util/retries.js\";\nimport {\n idempotentProducerAmqpPropertyNames,\n PENDING_PUBLISH_SEQ_NUM_SYMBOL,\n geoReplication,\n} from \"./util/constants.js\";\nimport { isDefined } from \"@azure/core-util\";\nimport { translateError } from \"./util/error.js\";\nimport type { TimerLoop } from \"./util/timerLoop.js\";\nimport { withAuth } from \"./withAuth.js\";\nimport { getRandomName } from \"./util/utils.js\";\n\n/**\n * @internal\n */\nexport interface EventHubSenderOptions {\n /**\n * Indicates whether or not the sender should enable idempotent publishing to Event Hub partitions.\n */\n enableIdempotentProducer: boolean;\n /**\n * The EventHub partition id to which the sender wants to send the event data.\n */\n partitionId?: string;\n /**\n * The set of options that can be specified to influence publishing behavior\n * specific to a partition.\n */\n partitionPublishingOptions?: PartitionPublishingOptions;\n}\n\n/**\n * Describes the EventHubSender that will send event data to EventHub.\n * @internal\n */\nexport class EventHubSender {\n /**\n * The unique lock name per connection that is used to acquire the\n * lock for establishing a sender link by an entity on that connection.\n */\n private readonly senderLock: string = getRandomName(\"sender\");\n /**\n * The handler function to handle errors that happen on the\n * underlying sender.\n */\n private readonly _onAmqpError: OnAmqpEvent;\n /**\n * The handler function to handle \"sender_close\" event\n * that happens on the underlying sender.\n */\n private readonly _onAmqpClose: OnAmqpEvent;\n /**\n * The message handler that will be set as the handler on\n * the underlying rhea sender's session for the \"session_error\" event.\n */\n private _onSessionError: OnAmqpEvent;\n /**\n * The message handler that will be set as the handler on\n * the underlying rhea sender's session for the \"session_close\" event.\n */\n private _onSessionClose: OnAmqpEvent;\n /**\n * The AMQP sender link.\n */\n private _sender?: AwaitableSender;\n /**\n * The partition ID.\n */\n private readonly partitionId?: string;\n /**\n * Indicates whether the sender is configured for idempotent publishing.\n */\n private _isIdempotentProducer: boolean;\n /**\n * Indicates whether the sender has an in-flight send while idempotent\n * publishing is enabled.\n */\n private _hasPendingSend?: boolean;\n /**\n * A local copy of the PartitionPublishingProperties that can be mutated to\n * keep track of the lastSequenceNumber used.\n */\n private _localPublishingProperties?: PartitionPublishingProperties;\n /**\n * The user-provided set of options that can be specified to influence\n * publishing behavior specific to a partition.\n */\n private _userProvidedPublishingOptions?: PartitionPublishingOptions;\n /**\n * Indicates whether the link is in the process of connecting\n * (establishing) itself. Default value: `false`.\n */\n private isConnecting: boolean = false;\n /**\n * The unique name for the entity (mostly a guid).\n */\n private readonly name: string;\n /**\n * The address in the following form:\n * - `\"<hubName>\"`\n * - `\"<hubName>/Partitions/<partitionId>\"`.\n */\n private readonly address: string;\n /**\n * The token audience in the following form:\n * - `\"sb://<yournamespace>.servicebus.windows.net/<hubName>\"`\n * - `\"sb://<yournamespace>.servicebus.windows.net/<hubName>/Partitions/<partitionId>\"`.\n */\n private readonly audience: string;\n /**\n * Provides relevant information about the amqp connection,\n * cbs and $management sessions, token provider, sender and receivers.\n */\n private readonly _context: ConnectionContext;\n /**\n * The auth loop.\n */\n private authLoop?: TimerLoop;\n /**\n * The logger.\n */\n private readonly logger: SimpleLogger;\n\n /** The client identifier */\n private _id: string;\n\n /**\n * Creates a new EventHubSender instance.\n * @param context - The connection context.\n * @param options - Options used to configure the EventHubSender.\n */\n constructor(\n context: ConnectionContext,\n senderId: string,\n { partitionId, enableIdempotentProducer, partitionPublishingOptions }: EventHubSenderOptions,\n ) {\n this.address = context.config.getSenderAddress(partitionId);\n this.name = this.address;\n this._id = senderId;\n this.audience = context.config.getSenderAudience(partitionId);\n this._context = context;\n this.partitionId = partitionId;\n this._isIdempotentProducer = enableIdempotentProducer;\n this._userProvidedPublishingOptions = partitionPublishingOptions;\n const logPrefix = createSenderLogPrefix(this.name, this._context.connectionId);\n this.logger = createSimpleLogger(logger, logPrefix);\n\n this._onAmqpError = (eventContext: EventContext) => {\n const senderError = eventContext.sender && eventContext.sender.error;\n this.logger.verbose(\n \"'sender_error' event occurred. The associated error is: %O\",\n senderError,\n );\n // TODO: Consider rejecting promise in trySendBatch() or createBatch()\n };\n\n this._onSessionError = (eventContext: EventContext) => {\n const sessionError = eventContext.session && eventContext.session.error;\n this.logger.verbose(\n \"'session_error' event occurred. The associated error is: %O\",\n sessionError,\n );\n // TODO: Consider rejecting promise in trySendBatch() or createBatch()\n };\n\n this._onAmqpClose = async (eventContext: EventContext) => {\n const sender = this._sender || eventContext.sender!;\n this.logger.verbose(\n \"'sender_close' event occurred. Value for isItselfClosed on the receiver is: '%s' \" +\n \"Value for isConnecting on the session is: '%s'.\",\n sender?.isItselfClosed().toString(),\n this.isConnecting,\n );\n if (sender && !this.isConnecting) {\n // Call close to clean up timers & other resources\n await sender.close().catch((err) => {\n this.logger.verbose(\"error when closing after 'sender_close' event: %O\", err);\n });\n }\n };\n\n this._onSessionClose = async (eventContext: EventContext) => {\n const sender = this._sender || eventContext.sender!;\n this.logger.verbose(\n \"'session_close' event occurred. Value for isSessionItselfClosed on the session is: '%s' \" +\n \"Value for isConnecting on the session is: '%s'.\",\n sender?.isSessionItselfClosed().toString(),\n this.isConnecting,\n );\n if (sender && !this.isConnecting) {\n // Call close to clean up timers & other resources\n await sender.close().catch((err) => {\n this.logger.verbose(\"error when closing after 'session_close' event: %O\", err);\n });\n }\n };\n }\n\n /**\n * Deletes the sender from the context. Clears the token renewal timer. Closes the sender link.\n */\n async close(): Promise<void> {\n try {\n if (this._sender) {\n this.logger.info(\"closing\");\n const senderLink = this._sender;\n this._deleteFromCache();\n await senderLink.close();\n this.authLoop?.stop();\n this.logger.verbose(\"closed.\");\n }\n } catch (err: any) {\n const msg = `an error occurred while closing: ${err?.name}: ${err?.message}`;\n this.logger.warning(msg);\n logErrorStackTrace(err);\n throw err;\n }\n }\n\n /**\n * Determines whether the AMQP sender link is open. If open then returns true else returns false.\n * @returns boolean\n */\n isOpen(): boolean {\n const result = Boolean(this._sender && this._sender.isOpen());\n this.logger.verbose(\"is open? -> %s\", result);\n return result;\n }\n /**\n * Returns maximum message size on the AMQP sender link.\n * @param abortSignal - An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.\n * For example, use the &commat;azure/abort-controller to create an `AbortSignal`.\n * @returns Promise<number>\n * @throws AbortError if the operation is cancelled via the abortSignal.\n */\n async getMaxMessageSize(\n options: {\n retryOptions?: RetryOptions;\n abortSignal?: AbortSignalLike;\n } = {},\n ): Promise<number> {\n const sender = await this._getLink(options);\n\n return sender.maxMessageSize;\n }\n\n /**\n * Get the information about the state of publishing for a partition as observed by the `EventHubSender`.\n * This data can always be read, but will only be populated with information relevant to the active features\n * for the producer client.\n */\n async getPartitionPublishingProperties(\n options: {\n retryOptions?: RetryOptions;\n abortSignal?: AbortSignalLike;\n } = {},\n ): Promise<PartitionPublishingProperties> {\n if (this._localPublishingProperties) {\n // Send a copy of the properties so it can't be mutated downstream.\n return { ...this._localPublishingProperties };\n }\n\n const properties: PartitionPublishingProperties = {\n isIdempotentPublishingEnabled: this._isIdempotentProducer,\n partitionId: this.partitionId ?? \"\",\n };\n\n if (this._isIdempotentProducer) {\n this._sender = await this._getLink(options);\n // await this._createLinkIfNotOpen(options);\n if (!this._sender) {\n // createLinkIfNotOpen should throw if `this._sender` can't be created, but just in case it gets\n // deleted while setting up token refreshing, make sure it exists.\n throw new Error(\n `Failed to retrieve partition publishing properties for partition \"${this.partitionId}\".`,\n );\n }\n\n const {\n [idempotentProducerAmqpPropertyNames.epoch]: ownerLevel,\n [idempotentProducerAmqpPropertyNames.producerId]: producerGroupId,\n [idempotentProducerAmqpPropertyNames.producerSequenceNumber]: lastPublishedSequenceNumber,\n } = this._sender.properties ?? {};\n\n properties.ownerLevel = parseInt(ownerLevel, 10);\n properties.producerGroupId = parseInt(producerGroupId, 10);\n properties.lastPublishedSequenceNumber = parseInt(lastPublishedSequenceNumber, 10);\n }\n\n this._localPublishingProperties = properties;\n\n // Send a copy of the properties so it can't be mutated downstream.\n return { ...properties };\n }\n\n /**\n * Send a batch of EventData to the EventHub. The \"message_annotations\",\n * \"application_properties\" and \"properties\" of the first message will be set as that\n * of the envelope (batch message).\n * @param events - An array of EventData objects to be sent in a Batch message.\n * @param options - Options to control the way the events are batched along with request options\n */\n async send(\n events: EventData[] | EventDataBatch,\n options?: SendOptions &\n EventHubProducerOptions & { tracingProperties?: Array<EventData[\"properties\"]> },\n ): Promise<void> {\n try {\n this.logger.info(\"trying to send EventData[].\");\n if (this._isIdempotentProducer && this._hasPendingSend) {\n throw new Error(\n `There can only be 1 \"sendBatch\" call in-flight per partition while \"enableIdempotentRetries\" is set to true.`,\n );\n }\n\n const eventCount = isEventDataBatch(events) ? events.count : events.length;\n if (eventCount === 0) {\n this.logger.info(`no events were passed to sendBatch.`);\n return;\n }\n\n if (this._isIdempotentProducer) {\n this._hasPendingSend = true;\n }\n\n this.logger.info(\"sending encoded batch message.\");\n await this._trySendBatch(events, options);\n if (this._isIdempotentProducer) {\n commitIdempotentSequenceNumbers(events);\n if (this._localPublishingProperties) {\n const { lastPublishedSequenceNumber = 0 } = this._localPublishingProperties;\n // Increment the lastPublishedSequenceNumber based on the number of events published.\n this._localPublishingProperties.lastPublishedSequenceNumber =\n lastPublishedSequenceNumber + eventCount;\n }\n }\n return;\n } catch (err: any) {\n rollbackIdempotentSequenceNumbers(events);\n this.logger.warning(\n `an error occurred while sending the batch message ${err?.name}: ${err?.message}`,\n );\n logErrorStackTrace(err);\n throw err;\n } finally {\n if (this._isIdempotentProducer) {\n this._hasPendingSend = false;\n }\n }\n }\n\n /**\n * @param sender - The rhea sender that contains the idempotent producer properties.\n */\n private _populateLocalPublishingProperties(sender: AwaitableSender): void {\n const {\n [idempotentProducerAmqpPropertyNames.epoch]: ownerLevel,\n [idempotentProducerAmqpPropertyNames.producerId]: producerGroupId,\n [idempotentProducerAmqpPropertyNames.producerSequenceNumber]: lastPublishedSequenceNumber,\n } = sender.properties ?? {};\n\n this._localPublishingProperties = {\n isIdempotentPublishingEnabled: this._isIdempotentProducer,\n partitionId: this.partitionId ?? \"\",\n lastPublishedSequenceNumber,\n ownerLevel,\n producerGroupId,\n };\n }\n\n private _deleteFromCache(): void {\n this._sender = undefined;\n delete this._context.senders[this.name];\n this.logger.verbose(\"deleted from the client cache.\");\n }\n\n private _createSenderOptions(): AwaitableSenderOptions {\n const srOptions: AwaitableSenderOptions = {\n name: this.name,\n source: this._id,\n target: {\n address: this.address,\n },\n onError: this._onAmqpError,\n onClose: this._onAmqpClose,\n onSessionError: this._onSessionError,\n onSessionClose: this._onSessionClose,\n };\n\n srOptions.desired_capabilities = [geoReplication];\n if (this._isIdempotentProducer) {\n srOptions.desired_capabilities.push(idempotentProducerAmqpPropertyNames.capability);\n const idempotentProperties = generateIdempotentLinkProperties(\n this._userProvidedPublishingOptions,\n this._localPublishingProperties,\n );\n srOptions.properties = idempotentProperties;\n }\n this.logger.verbose(\"being created with options: %O\", srOptions);\n return srOptions;\n }\n\n /**\n * Tries to send the message to EventHub if there is enough credit to send them\n * and the circular buffer has available space to settle the message after sending them.\n *\n * We have implemented a synchronous send over here in the sense that we shall be waiting\n * for the message to be accepted or rejected and accordingly resolve or reject the promise.\n * @param rheaMessage - The message to be sent to EventHub.\n * @returns Promise<void>\n */\n private async _trySendBatch(\n events: EventData[] | EventDataBatch,\n options: SendOptions &\n EventHubProducerOptions & {\n /**\n * Tracing properties that are associated with EventData.\n */\n tracingProperties?: Array<EventData[\"properties\"]>;\n } = {},\n ): Promise<void> {\n const abortSignal: AbortSignalLike | undefined = options.abortSignal;\n const retryOptions = options.retryOptions || {};\n const timeoutInMs = getRetryAttemptTimeoutInMs(retryOptions);\n retryOptions.timeoutInMs = timeoutInMs;\n\n const sendEventPromise = async (): Promise<void> => {\n const initStartTime = Date.now();\n // TODO: (jeremymeng) A or B\n // variant A:\n const sender = await this._getLink(options);\n // variant B\n // await this._createLinkIfNotOpen(options);\n const publishingProps = await this.getPartitionPublishingProperties(options);\n const timeTakenByInit = Date.now() - initStartTime;\n\n this.logger.verbose(\n \"credit: %d available: %d\",\n sender.credit,\n sender.session.outgoing.available(),\n );\n\n let waitTimeForSendable = 1000;\n if (!sender.sendable() && timeoutInMs - timeTakenByInit > waitTimeForSendable) {\n this.logger.verbose(\"waiting for 1 second for sender to become sendable\");\n\n await delay(waitTimeForSendable);\n\n this.logger.verbose(\n \"after waiting for a second, credit: %d available: %d\",\n sender.credit,\n sender.session?.outgoing?.available(),\n );\n } else {\n waitTimeForSendable = 0;\n }\n\n if (!sender.sendable()) {\n // let us retry to send the message after some time.\n const msg = `cannot send the message right now. Please try later.`;\n this.logger.warning(msg);\n const amqpError: AmqpError = {\n condition: ErrorNameConditionMapper.SenderBusyError,\n description: msg,\n };\n throw translate(amqpError);\n }\n\n if (timeoutInMs <= timeTakenByInit + waitTimeForSendable) {\n const desc: string =\n `was not able to send the message right now, due ` + `to operation timeout.`;\n this.logger.warning(desc);\n const e: AmqpError = {\n condition: ErrorNameConditionMapper.ServiceUnavailableError,\n description: desc,\n };\n throw translate(e);\n }\n\n try {\n const encodedMessage = transformEventsForSend(events, publishingProps, options);\n const delivery = await sender.send(encodedMessage, {\n format: 0x80013700,\n timeoutInSeconds: (timeoutInMs - timeTakenByInit - waitTimeForSendable) / 1000,\n abortSignal,\n });\n this.logger.info(\"sent message with delivery id: %d\", delivery.id);\n } catch (err: any) {\n const error = err.innerError || err;\n const translatedError = translateError(error);\n throw translatedError;\n }\n };\n\n const config: RetryConfig<void> = {\n operation: sendEventPromise,\n connectionId: this._context.connectionId,\n operationType: RetryOperationType.sendMessage,\n abortSignal: abortSignal,\n retryOptions: retryOptions,\n };\n\n try {\n await retry<void>(config);\n } catch (err: any) {\n const translatedError = translate(err);\n this.logger.warning(\n \"an error occurred while sending the message %s\",\n `${translatedError?.name}: ${translatedError?.message}`,\n );\n logErrorStackTrace(translatedError);\n throw translatedError;\n }\n }\n\n private async _getLink(\n options: {\n retryOptions?: RetryOptions;\n abortSignal?: AbortSignalLike;\n } = {},\n ): Promise<AwaitableSender> {\n if (this.isOpen() && this._sender) {\n return this._sender;\n }\n const retryOptions = options.retryOptions || {};\n const timeoutInMs = getRetryAttemptTimeoutInMs(retryOptions);\n retryOptions.timeoutInMs = timeoutInMs;\n const senderOptions = this._createSenderOptions();\n\n const startTime = Date.now();\n const createLinkPromise = async (): Promise<AwaitableSender> => {\n return defaultCancellableLock.acquire(\n this.senderLock,\n () => {\n const taskStartTime = Date.now();\n const taskTimeoutInMs = timeoutInMs - (taskStartTime - startTime);\n return this._init({\n ...senderOptions,\n abortSignal: options.abortSignal,\n timeoutInMs: taskTimeoutInMs,\n });\n },\n { abortSignal: options.abortSignal, timeoutInMs: timeoutInMs },\n );\n };\n\n const config: RetryConfig<AwaitableSender> = {\n operation: createLinkPromise,\n connectionId: this._context.connectionId,\n operationType: RetryOperationType.senderLink,\n abortSignal: options.abortSignal,\n retryOptions: retryOptions,\n };\n\n try {\n return await retry<AwaitableSender>(config);\n } catch (err: any) {\n const translatedError = translate(err);\n this.logger.warning(\n \"an error occurred while creating: %s\",\n `${translatedError?.name}: ${translatedError?.message}`,\n );\n logErrorStackTrace(translatedError);\n throw translatedError;\n }\n }\n\n /**\n * Initializes the sender session on the connection.\n * Should only be called from _createLinkIfNotOpen\n */\n private async _init(\n options: AwaitableSenderOptions & {\n abortSignal: AbortSignalLike | undefined;\n timeoutInMs: number;\n },\n ): Promise<AwaitableSender> {\n const createSender = async () => {\n this.logger.verbose(\"trying to be created...\");\n\n const sender = await this._context.connection.createAwaitableSender(options);\n this._sender = sender;\n this._populateLocalPublishingProperties(this._sender);\n this.isConnecting = false;\n this.logger.verbose(\"created with options: %O\", options);\n\n // It is possible for someone to close the sender and then start it again.\n // Thus make sure that the sender is present in the client cache.\n if (!this._context.senders[this.name]) this._context.senders[this.name] = this;\n };\n try {\n if (!this.isOpen() || !this._sender) {\n await this._context.readyToOpenLink();\n this.authLoop = await withAuth(\n createSender,\n this._context,\n this.audience,\n options.timeoutInMs,\n this.logger,\n { abortSignal: options.abortSignal },\n );\n // it is guaranteed to be defined at this point, otherwise, an error would\n // have been thrown.\n return this._sender!;\n } else {\n this.logger.verbose(\"is open -> %s. Hence not reconnecting.\", this.isOpen());\n return this._sender;\n }\n } catch (err) {\n const translatedError = translate(err);\n this.logger.warning(\n \"an error occurred while being created: %s\",\n `${translatedError?.name}: ${translatedError?.message}`,\n );\n logErrorStackTrace(translatedError);\n throw translatedError;\n }\n }\n\n /**\n * Creates a new sender to the given event hub, and optionally to a given partition if it is\n * not present in the context or returns the one present in the context.\n * @hidden\n * @param options - Options used to configure the EventHubSender.\n */\n static create(\n context: ConnectionContext,\n senderId: string,\n options: EventHubSenderOptions,\n ): EventHubSender {\n const ehSender: EventHubSender = new EventHubSender(context, senderId, options);\n if (!context.senders[ehSender.name]) {\n context.senders[ehSender.name] = ehSender;\n }\n return context.senders[ehSender.name];\n }\n}\n\n/**\n * Generates the link properties for an indemopotent sender given\n * based on the user-provided and locally-cached publishing options.\n *\n * Note: The set of idempotent properties a user specifies at EventHubProducerClient instantiation-time\n * is slightly different than what the service returns and the EventHubSender keeps track of locally.\n *\n * The difference is that the user specifies the `startingSequenceNumber`, whereas the local options\n * (those returned by getPartitionPublishingProperties) specifies `lastPublishedSequenceNumber`.\n *\n * These _can_ be the same, but the user is technically free to set any `startingSequenceNumber` they want.\n * @internal\n */\nexport function generateIdempotentLinkProperties(\n userProvidedPublishingOptions: PartitionPublishingOptions | undefined,\n localPublishingOptions: PartitionPublishingProperties | undefined,\n): IdempotentLinkProperties | Record<string, never> {\n let ownerLevel: number | undefined;\n let producerGroupId: number | undefined;\n let sequenceNumber: number | undefined;\n\n // Prefer local publishing options since this is the up-to-date state of the sender.\n // Only use user-provided publishing options the first time we create the link.\n if (localPublishingOptions) {\n ownerLevel = localPublishingOptions.ownerLevel;\n producerGroupId = localPublishingOptions.producerGroupId;\n sequenceNumber = localPublishingOptions.lastPublishedSequenceNumber;\n } else if (userProvidedPublishingOptions) {\n ownerLevel = userProvidedPublishingOptions.ownerLevel;\n producerGroupId = userProvidedPublishingOptions.producerGroupId;\n sequenceNumber = userProvidedPublishingOptions.startingSequenceNumber;\n } else {\n // If we don't have any properties at all, send an empty object.\n // This will cause the service to generate a new producer-id for our client.\n return {};\n }\n\n // The service requires that if ANY_ of these properties are defined,\n // they _ALL_ have to be defined.\n // If we don't have one of the required values, use `null` and the\n // service will provide it.\n const idempotentLinkProperties: IdempotentLinkProperties = {\n [idempotentProducerAmqpPropertyNames.epoch]: isDefined(ownerLevel)\n ? types.wrap_short(ownerLevel)\n : null,\n [idempotentProducerAmqpPropertyNames.producerId]: isDefined(producerGroupId)\n ? types.wrap_long(producerGroupId)\n : null,\n [idempotentProducerAmqpPropertyNames.producerSequenceNumber]: isDefined(sequenceNumber)\n ? types.wrap_int(sequenceNumber)\n : null,\n };\n\n return idempotentLinkProperties;\n}\n\n/**\n * Encodes a list or batch of events into a single binary message that can be sent to the service.\n *\n * Prior to encoding, any special properties not specified by the user, such as tracing or idempotent\n * properties, are assigned to the list or batch of events as needed.\n *\n * @internal\n * @param events - Events to transform for sending to the service.\n * @param publishingProps - Describes the current publishing state for the partition.\n * @param options - Options used to configure this function.\n */\nexport function transformEventsForSend(\n events: EventData[] | EventDataBatch,\n publishingProps: PartitionPublishingProperties,\n options: SendOptions & {\n /**\n * A list containing the `Diagnostic-Id` tracing property that is associated with each EventData.\n * The index of tracingProperties corresponds to the same index in `events` when `events` is EventData[].\n */\n tracingProperties?: Array<EventData[\"properties\"]>;\n } = {},\n): Buffer {\n if (isEventDataBatch(events)) {\n return (events as EventDataBatchImpl)._generateMessage(publishingProps);\n } else {\n const eventCount = events.length;\n // convert events to rhea messages\n const rheaMessages: RheaMessage[] = [];\n const tracingProperties = options.tracingProperties ?? [];\n for (let i = 0; i < eventCount; i++) {\n const originalEvent = events[i];\n const tracingProperty = tracingProperties[i];\n // Create a copy of the user's event so we can add the tracing property.\n const event: EventData = {\n ...originalEvent,\n properties: { ...originalEvent.properties, ...tracingProperty },\n };\n const rheaMessage = toRheaMessage(event, options.partitionKey);\n\n // populate idempotent message annotations\n const { lastPublishedSequenceNumber = 0 } = publishingProps;\n const startingSequenceNumber = lastPublishedSequenceNumber + 1;\n const pendingPublishSequenceNumber = startingSequenceNumber + i;\n populateIdempotentMessageAnnotations(rheaMessage, {\n ...publishingProps,\n publishSequenceNumber: pendingPublishSequenceNumber,\n });\n\n if (publishingProps.isIdempotentPublishingEnabled) {\n // Set pending seq number on user's event.\n (originalEvent as EventDataInternal)[PENDING_PUBLISH_SEQ_NUM_SYMBOL] =\n pendingPublishSequenceNumber;\n }\n\n rheaMessages.push(rheaMessage);\n }\n\n // Encode every amqp message and then convert every encoded message to amqp data section\n const batchMessage: RheaMessage = {\n body: message.data_sections(rheaMessages.map(message.encode)),\n };\n\n // Set message_annotations of the first message as\n // that of the envelope (batch message).\n if (rheaMessages[0].message_annotations) {\n batchMessage.message_annotations = { ...rheaMessages[0].message_annotations };\n }\n\n // Finally encode the envelope (batch message).\n return message.encode(batchMessage);\n }\n}\n\n/**\n * Commits the pending publish sequence number events.\n * EventDataBatch exposes this as `startingPublishSequenceNumber`,\n * EventData not in a batch exposes this as `publishedSequenceNumber`.\n */\nfunction commitIdempotentSequenceNumbers(\n events: Omit<EventDataInternal, \"getRawAmqpMessage\">[] | EventDataBatch,\n): void {\n if (isEventDataBatch(events)) {\n (events as EventDataBatchImpl)._commitPublish();\n } else {\n // For each event, set the `publishedSequenceNumber` equal to the sequence number\n // we set when we attempted to send the events to the service.\n for (const event of events) {\n event._publishedSequenceNumber = event[PENDING_PUBLISH_SEQ_NUM_SYMBOL];\n delete event[PENDING_PUBLISH_SEQ_NUM_SYMBOL];\n }\n }\n}\n\n/**\n * Rolls back any pending publish sequence number in the events.\n */\nfunction rollbackIdempotentSequenceNumbers(\n events: Omit<EventDataInternal, \"getRawAmqpMessage\">[] | EventDataBatch,\n): void {\n if (isEventDataBatch(events)) {\n /* No action required. */\n } else {\n for (const event of events) {\n delete event[PENDING_PUBLISH_SEQ_NUM_SYMBOL];\n }\n }\n}\n"]}
1
+ {"version":3,"file":"eventHubSender.js","sourceRoot":"","sources":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B,CAAC,cAAc,EAAE,CAAC;IAClD,CAAC;SAAM,CAAC;QACN,iFAAiF;QACjF,8DAA8D;QAC9D,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,KAAK,CAAC,wBAAwB,GAAG,KAAK,CAAC,6CAA8B,CAAC,CAAC;YACvE,OAAO,KAAK,CAAC,6CAA8B,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,iCAAiC,CACxC,MAAuE;IAEvE,IAAI,IAAA,oCAAgB,EAAC,MAAM,CAAC,EAAE,CAAC;QAC7B,yBAAyB;IAC3B,CAAC;SAAM,CAAC;QACN,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,OAAO,KAAK,CAAC,6CAA8B,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n AmqpError,\n AwaitableSender,\n AwaitableSenderOptions,\n EventContext,\n OnAmqpEvent,\n Message as RheaMessage,\n} from \"rhea-promise\";\nimport { message, types } from \"rhea-promise\";\nimport type { RetryConfig, RetryOptions } from \"@azure/core-amqp\";\nimport {\n ErrorNameConditionMapper,\n RetryOperationType,\n defaultCancellableLock,\n delay,\n retry,\n translate,\n} from \"@azure/core-amqp\";\nimport type { EventData, EventDataInternal } from \"./eventData.js\";\nimport { populateIdempotentMessageAnnotations, toRheaMessage } from \"./eventData.js\";\nimport type { EventDataBatch, EventDataBatchImpl } from \"./eventDataBatch.js\";\nimport { isEventDataBatch } from \"./eventDataBatch.js\";\nimport type { SimpleLogger } from \"./logger.js\";\nimport { logErrorStackTrace, createSimpleLogger, logger, createSenderLogPrefix } from \"./logger.js\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type { ConnectionContext } from \"./connectionContext.js\";\nimport type { EventHubProducerOptions, IdempotentLinkProperties } from \"./models/private.js\";\nimport type { SendOptions } from \"./models/public.js\";\nimport type {\n PartitionPublishingOptions,\n PartitionPublishingProperties,\n} from \"./models/private.js\";\nimport { getRetryAttemptTimeoutInMs } from \"./util/retries.js\";\nimport {\n idempotentProducerAmqpPropertyNames,\n PENDING_PUBLISH_SEQ_NUM_SYMBOL,\n geoReplication,\n} from \"./util/constants.js\";\nimport { isDefined } from \"@azure/core-util\";\nimport { translateError } from \"./util/error.js\";\nimport type { TimerLoop } from \"./util/timerLoop.js\";\nimport { withAuth } from \"./withAuth.js\";\nimport { getRandomName } from \"./util/utils.js\";\n\n/**\n * @internal\n */\nexport interface EventHubSenderOptions {\n /**\n * Indicates whether or not the sender should enable idempotent publishing to Event Hub partitions.\n */\n enableIdempotentProducer: boolean;\n /**\n * The EventHub partition id to which the sender wants to send the event data.\n */\n partitionId?: string;\n /**\n * The set of options that can be specified to influence publishing behavior\n * specific to a partition.\n */\n partitionPublishingOptions?: PartitionPublishingOptions;\n}\n\n/**\n * Describes the EventHubSender that will send event data to EventHub.\n * @internal\n */\nexport class EventHubSender {\n /**\n * The unique lock name per connection that is used to acquire the\n * lock for establishing a sender link by an entity on that connection.\n */\n private readonly senderLock: string = getRandomName(\"sender\");\n /**\n * The handler function to handle errors that happen on the\n * underlying sender.\n */\n private readonly _onAmqpError: OnAmqpEvent;\n /**\n * The handler function to handle \"sender_close\" event\n * that happens on the underlying sender.\n */\n private readonly _onAmqpClose: OnAmqpEvent;\n /**\n * The message handler that will be set as the handler on\n * the underlying rhea sender's session for the \"session_error\" event.\n */\n private _onSessionError: OnAmqpEvent;\n /**\n * The message handler that will be set as the handler on\n * the underlying rhea sender's session for the \"session_close\" event.\n */\n private _onSessionClose: OnAmqpEvent;\n /**\n * The AMQP sender link.\n */\n private _sender?: AwaitableSender;\n /**\n * The partition ID.\n */\n private readonly partitionId?: string;\n /**\n * Indicates whether the sender is configured for idempotent publishing.\n */\n private _isIdempotentProducer: boolean;\n /**\n * Indicates whether the sender has an in-flight send while idempotent\n * publishing is enabled.\n */\n private _hasPendingSend?: boolean;\n /**\n * A local copy of the PartitionPublishingProperties that can be mutated to\n * keep track of the lastSequenceNumber used.\n */\n private _localPublishingProperties?: PartitionPublishingProperties;\n /**\n * The user-provided set of options that can be specified to influence\n * publishing behavior specific to a partition.\n */\n private _userProvidedPublishingOptions?: PartitionPublishingOptions;\n /**\n * Indicates whether the link is in the process of connecting\n * (establishing) itself. Default value: `false`.\n */\n private isConnecting: boolean = false;\n /**\n * The unique name for the entity (mostly a guid).\n */\n private readonly name: string;\n /**\n * The address in the following form:\n * - `\"<hubName>\"`\n * - `\"<hubName>/Partitions/<partitionId>\"`.\n */\n private readonly address: string;\n /**\n * The token audience in the following form:\n * - `\"sb://<yournamespace>.servicebus.windows.net/<hubName>\"`\n * - `\"sb://<yournamespace>.servicebus.windows.net/<hubName>/Partitions/<partitionId>\"`.\n */\n private readonly audience: string;\n /**\n * Provides relevant information about the amqp connection,\n * cbs and $management sessions, token provider, sender and receivers.\n */\n private readonly _context: ConnectionContext;\n /**\n * The auth loop.\n */\n private authLoop?: TimerLoop;\n /**\n * The logger.\n */\n private readonly logger: SimpleLogger;\n\n /** The client identifier */\n private _id: string;\n\n /**\n * Creates a new EventHubSender instance.\n * @param context - The connection context.\n * @param options - Options used to configure the EventHubSender.\n */\n constructor(\n context: ConnectionContext,\n senderId: string,\n { partitionId, enableIdempotentProducer, partitionPublishingOptions }: EventHubSenderOptions,\n ) {\n this.address = context.config.getSenderAddress(partitionId);\n this.name = this.address;\n this._id = senderId;\n this.audience = context.config.getSenderAudience(partitionId);\n this._context = context;\n this.partitionId = partitionId;\n this._isIdempotentProducer = enableIdempotentProducer;\n this._userProvidedPublishingOptions = partitionPublishingOptions;\n const logPrefix = createSenderLogPrefix(this.name, this._context.connectionId);\n this.logger = createSimpleLogger(logger, logPrefix);\n\n this._onAmqpError = (eventContext: EventContext) => {\n const senderError = eventContext.sender && eventContext.sender.error;\n this.logger.verbose(\n \"'sender_error' event occurred. The associated error is: %O\",\n senderError,\n );\n // TODO: Consider rejecting promise in trySendBatch() or createBatch()\n };\n\n this._onSessionError = (eventContext: EventContext) => {\n const sessionError = eventContext.session && eventContext.session.error;\n this.logger.verbose(\n \"'session_error' event occurred. The associated error is: %O\",\n sessionError,\n );\n // TODO: Consider rejecting promise in trySendBatch() or createBatch()\n };\n\n this._onAmqpClose = async (eventContext: EventContext) => {\n const sender = this._sender || eventContext.sender!;\n this.logger.verbose(\n \"'sender_close' event occurred. Value for isItselfClosed on the receiver is: '%s' \" +\n \"Value for isConnecting on the session is: '%s'.\",\n sender?.isItselfClosed().toString(),\n this.isConnecting,\n );\n if (sender && !this.isConnecting) {\n // Call close to clean up timers & other resources\n await sender.close().catch((err) => {\n this.logger.verbose(\"error when closing after 'sender_close' event: %O\", err);\n });\n }\n };\n\n this._onSessionClose = async (eventContext: EventContext) => {\n const sender = this._sender || eventContext.sender!;\n this.logger.verbose(\n \"'session_close' event occurred. Value for isSessionItselfClosed on the session is: '%s' \" +\n \"Value for isConnecting on the session is: '%s'.\",\n sender?.isSessionItselfClosed().toString(),\n this.isConnecting,\n );\n if (sender && !this.isConnecting) {\n // Call close to clean up timers & other resources\n await sender.close().catch((err) => {\n this.logger.verbose(\"error when closing after 'session_close' event: %O\", err);\n });\n }\n };\n }\n\n /**\n * Deletes the sender from the context. Clears the token renewal timer. Closes the sender link.\n */\n async close(): Promise<void> {\n try {\n if (this._sender) {\n this.logger.info(\"closing\");\n const senderLink = this._sender;\n this._deleteFromCache();\n await senderLink.close();\n this.authLoop?.stop();\n this.logger.verbose(\"closed.\");\n }\n } catch (err: any) {\n const msg = `an error occurred while closing: ${err?.name}: ${err?.message}`;\n this.logger.warning(msg);\n logErrorStackTrace(err);\n throw err;\n }\n }\n\n /**\n * Determines whether the AMQP sender link is open. If open then returns true else returns false.\n * @returns boolean\n */\n isOpen(): boolean {\n const result = Boolean(this._sender && this._sender.isOpen());\n this.logger.verbose(\"is open? -> %s\", result);\n return result;\n }\n /**\n * Returns maximum message size on the AMQP sender link.\n * @param abortSignal - An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.\n * For example, use the &commat;azure/abort-controller to create an `AbortSignal`.\n * @returns Promise<number>\n * @throws AbortError if the operation is cancelled via the abortSignal.\n */\n async getMaxMessageSize(\n options: {\n retryOptions?: RetryOptions;\n abortSignal?: AbortSignalLike;\n } = {},\n ): Promise<number> {\n const sender = await this._getLink(options);\n\n return sender.maxMessageSize;\n }\n\n /**\n * Get the information about the state of publishing for a partition as observed by the `EventHubSender`.\n * This data can always be read, but will only be populated with information relevant to the active features\n * for the producer client.\n */\n async getPartitionPublishingProperties(\n options: {\n retryOptions?: RetryOptions;\n abortSignal?: AbortSignalLike;\n } = {},\n ): Promise<PartitionPublishingProperties> {\n if (this._localPublishingProperties) {\n // Send a copy of the properties so it can't be mutated downstream.\n return { ...this._localPublishingProperties };\n }\n\n const properties: PartitionPublishingProperties = {\n isIdempotentPublishingEnabled: this._isIdempotentProducer,\n partitionId: this.partitionId ?? \"\",\n };\n\n if (this._isIdempotentProducer) {\n this._sender = await this._getLink(options);\n // await this._createLinkIfNotOpen(options);\n if (!this._sender) {\n // createLinkIfNotOpen should throw if `this._sender` can't be created, but just in case it gets\n // deleted while setting up token refreshing, make sure it exists.\n throw new Error(\n `Failed to retrieve partition publishing properties for partition \"${this.partitionId}\".`,\n );\n }\n\n const {\n [idempotentProducerAmqpPropertyNames.epoch]: ownerLevel,\n [idempotentProducerAmqpPropertyNames.producerId]: producerGroupId,\n [idempotentProducerAmqpPropertyNames.producerSequenceNumber]: lastPublishedSequenceNumber,\n } = this._sender.properties ?? {};\n\n properties.ownerLevel = parseInt(ownerLevel, 10);\n properties.producerGroupId = parseInt(producerGroupId, 10);\n properties.lastPublishedSequenceNumber = parseInt(lastPublishedSequenceNumber, 10);\n }\n\n this._localPublishingProperties = properties;\n\n // Send a copy of the properties so it can't be mutated downstream.\n return { ...properties };\n }\n\n /**\n * Send a batch of EventData to the EventHub. The \"message_annotations\",\n * \"application_properties\" and \"properties\" of the first message will be set as that\n * of the envelope (batch message).\n * @param events - An array of EventData objects to be sent in a Batch message.\n * @param options - Options to control the way the events are batched along with request options\n */\n async send(\n events: EventData[] | EventDataBatch,\n options?: SendOptions &\n EventHubProducerOptions & { tracingProperties?: Array<EventData[\"properties\"]> },\n ): Promise<void> {\n try {\n this.logger.info(\"trying to send EventData[].\");\n if (this._isIdempotentProducer && this._hasPendingSend) {\n throw new Error(\n `There can only be 1 \"sendBatch\" call in-flight per partition while \"enableIdempotentRetries\" is set to true.`,\n );\n }\n\n const eventCount = isEventDataBatch(events) ? events.count : events.length;\n if (eventCount === 0) {\n this.logger.info(`no events were passed to sendBatch.`);\n return;\n }\n\n if (this._isIdempotentProducer) {\n this._hasPendingSend = true;\n }\n\n this.logger.info(\"sending encoded batch message.\");\n await this._trySendBatch(events, options);\n if (this._isIdempotentProducer) {\n commitIdempotentSequenceNumbers(events);\n if (this._localPublishingProperties) {\n const { lastPublishedSequenceNumber = 0 } = this._localPublishingProperties;\n // Increment the lastPublishedSequenceNumber based on the number of events published.\n this._localPublishingProperties.lastPublishedSequenceNumber =\n lastPublishedSequenceNumber + eventCount;\n }\n }\n return;\n } catch (err: any) {\n rollbackIdempotentSequenceNumbers(events);\n this.logger.warning(\n `an error occurred while sending the batch message ${err?.name}: ${err?.message}`,\n );\n logErrorStackTrace(err);\n throw err;\n } finally {\n if (this._isIdempotentProducer) {\n this._hasPendingSend = false;\n }\n }\n }\n\n /**\n * @param sender - The rhea sender that contains the idempotent producer properties.\n */\n private _populateLocalPublishingProperties(sender: AwaitableSender): void {\n const {\n [idempotentProducerAmqpPropertyNames.epoch]: ownerLevel,\n [idempotentProducerAmqpPropertyNames.producerId]: producerGroupId,\n [idempotentProducerAmqpPropertyNames.producerSequenceNumber]: lastPublishedSequenceNumber,\n } = sender.properties ?? {};\n\n this._localPublishingProperties = {\n isIdempotentPublishingEnabled: this._isIdempotentProducer,\n partitionId: this.partitionId ?? \"\",\n lastPublishedSequenceNumber,\n ownerLevel,\n producerGroupId,\n };\n }\n\n private _deleteFromCache(): void {\n this._sender = undefined;\n delete this._context.senders[this.name];\n this.logger.verbose(\"deleted from the client cache.\");\n }\n\n private _createSenderOptions(): AwaitableSenderOptions {\n const srOptions: AwaitableSenderOptions = {\n name: this.name,\n source: this._id,\n target: {\n address: this.address,\n },\n onError: this._onAmqpError,\n onClose: this._onAmqpClose,\n onSessionError: this._onSessionError,\n onSessionClose: this._onSessionClose,\n };\n\n srOptions.desired_capabilities = [geoReplication];\n if (this._isIdempotentProducer) {\n srOptions.desired_capabilities.push(idempotentProducerAmqpPropertyNames.capability);\n const idempotentProperties = generateIdempotentLinkProperties(\n this._userProvidedPublishingOptions,\n this._localPublishingProperties,\n );\n srOptions.properties = idempotentProperties;\n }\n this.logger.verbose(\"being created with options: %O\", srOptions);\n return srOptions;\n }\n\n /**\n * Tries to send the message to EventHub if there is enough credit to send them\n * and the circular buffer has available space to settle the message after sending them.\n *\n * We have implemented a synchronous send over here in the sense that we shall be waiting\n * for the message to be accepted or rejected and accordingly resolve or reject the promise.\n * @param rheaMessage - The message to be sent to EventHub.\n * @returns Promise<void>\n */\n private async _trySendBatch(\n events: EventData[] | EventDataBatch,\n options: SendOptions &\n EventHubProducerOptions & {\n /**\n * Tracing properties that are associated with EventData.\n */\n tracingProperties?: Array<EventData[\"properties\"]>;\n } = {},\n ): Promise<void> {\n const abortSignal: AbortSignalLike | undefined = options.abortSignal;\n const retryOptions = options.retryOptions || {};\n const timeoutInMs = getRetryAttemptTimeoutInMs(retryOptions);\n retryOptions.timeoutInMs = timeoutInMs;\n\n const sendEventPromise = async (): Promise<void> => {\n const initStartTime = Date.now();\n // TODO: (jeremymeng) A or B\n // variant A:\n const sender = await this._getLink(options);\n // variant B\n // await this._createLinkIfNotOpen(options);\n const publishingProps = await this.getPartitionPublishingProperties(options);\n const timeTakenByInit = Date.now() - initStartTime;\n\n this.logger.verbose(\n \"credit: %d available: %d\",\n sender.credit,\n sender.session.outgoing.available(),\n );\n\n let waitTimeForSendable = 1000;\n if (!sender.sendable() && timeoutInMs - timeTakenByInit > waitTimeForSendable) {\n this.logger.verbose(\"waiting for 1 second for sender to become sendable\");\n\n await delay(waitTimeForSendable);\n\n this.logger.verbose(\n \"after waiting for a second, credit: %d available: %d\",\n sender.credit,\n sender.session?.outgoing?.available(),\n );\n } else {\n waitTimeForSendable = 0;\n }\n\n if (!sender.sendable()) {\n // let us retry to send the message after some time.\n const msg = `cannot send the message right now. Please try later.`;\n this.logger.warning(msg);\n const amqpError: AmqpError = {\n condition: ErrorNameConditionMapper.SenderBusyError,\n description: msg,\n };\n throw translate(amqpError);\n }\n\n if (timeoutInMs <= timeTakenByInit + waitTimeForSendable) {\n const desc: string =\n `was not able to send the message right now, due ` + `to operation timeout.`;\n this.logger.warning(desc);\n const e: AmqpError = {\n condition: ErrorNameConditionMapper.ServiceUnavailableError,\n description: desc,\n };\n throw translate(e);\n }\n\n try {\n const encodedMessage = transformEventsForSend(events, publishingProps, options);\n const delivery = await sender.send(encodedMessage, {\n format: 0x80013700,\n timeoutInSeconds: (timeoutInMs - timeTakenByInit - waitTimeForSendable) / 1000,\n abortSignal,\n });\n this.logger.info(\"sent message with delivery id: %d\", delivery.id);\n } catch (err: any) {\n const error = err.innerError || err;\n const translatedError = translateError(error);\n throw translatedError;\n }\n };\n\n const config: RetryConfig<void> = {\n operation: sendEventPromise,\n connectionId: this._context.connectionId,\n operationType: RetryOperationType.sendMessage,\n abortSignal: abortSignal,\n retryOptions: retryOptions,\n };\n\n try {\n await retry<void>(config);\n } catch (err: any) {\n const translatedError = translate(err);\n this.logger.warning(\n \"an error occurred while sending the message %s\",\n `${translatedError?.name}: ${translatedError?.message}`,\n );\n logErrorStackTrace(translatedError);\n throw translatedError;\n }\n }\n\n private async _getLink(\n options: {\n retryOptions?: RetryOptions;\n abortSignal?: AbortSignalLike;\n } = {},\n ): Promise<AwaitableSender> {\n if (this.isOpen() && this._sender) {\n return this._sender;\n }\n const retryOptions = options.retryOptions || {};\n const timeoutInMs = getRetryAttemptTimeoutInMs(retryOptions);\n retryOptions.timeoutInMs = timeoutInMs;\n const senderOptions = this._createSenderOptions();\n\n const startTime = Date.now();\n const createLinkPromise = async (): Promise<AwaitableSender> => {\n return defaultCancellableLock.acquire(\n this.senderLock,\n () => {\n const taskStartTime = Date.now();\n const taskTimeoutInMs = timeoutInMs - (taskStartTime - startTime);\n return this._init({\n ...senderOptions,\n abortSignal: options.abortSignal,\n timeoutInMs: taskTimeoutInMs,\n });\n },\n { abortSignal: options.abortSignal, timeoutInMs: timeoutInMs },\n );\n };\n\n const config: RetryConfig<AwaitableSender> = {\n operation: createLinkPromise,\n connectionId: this._context.connectionId,\n operationType: RetryOperationType.senderLink,\n abortSignal: options.abortSignal,\n retryOptions: retryOptions,\n };\n\n try {\n return await retry<AwaitableSender>(config);\n } catch (err: any) {\n const translatedError = translate(err);\n this.logger.warning(\n \"an error occurred while creating: %s\",\n `${translatedError?.name}: ${translatedError?.message}`,\n );\n logErrorStackTrace(translatedError);\n throw translatedError;\n }\n }\n\n /**\n * Initializes the sender session on the connection.\n * Should only be called from _createLinkIfNotOpen\n */\n private async _init(\n options: AwaitableSenderOptions & {\n abortSignal: AbortSignalLike | undefined;\n timeoutInMs: number;\n },\n ): Promise<AwaitableSender> {\n const createSender = async () => {\n this.logger.verbose(\"trying to be created...\");\n\n const sender = await this._context.connection.createAwaitableSender(options);\n this._sender = sender;\n this._populateLocalPublishingProperties(this._sender);\n this.isConnecting = false;\n this.logger.verbose(\"created with options: %O\", options);\n\n // It is possible for someone to close the sender and then start it again.\n // Thus make sure that the sender is present in the client cache.\n if (!this._context.senders[this.name]) this._context.senders[this.name] = this;\n };\n try {\n if (!this.isOpen() || !this._sender) {\n await this._context.readyToOpenLink();\n this.authLoop = await withAuth(\n createSender,\n this._context,\n this.audience,\n options.timeoutInMs,\n this.logger,\n { abortSignal: options.abortSignal },\n );\n // it is guaranteed to be defined at this point, otherwise, an error would\n // have been thrown.\n return this._sender!;\n } else {\n this.logger.verbose(\"is open -> %s. Hence not reconnecting.\", this.isOpen());\n return this._sender;\n }\n } catch (err) {\n const translatedError = translate(err);\n this.logger.warning(\n \"an error occurred while being created: %s\",\n `${translatedError?.name}: ${translatedError?.message}`,\n );\n logErrorStackTrace(translatedError);\n throw translatedError;\n }\n }\n\n /**\n * Creates a new sender to the given event hub, and optionally to a given partition if it is\n * not present in the context or returns the one present in the context.\n * @hidden\n * @param options - Options used to configure the EventHubSender.\n */\n static create(\n context: ConnectionContext,\n senderId: string,\n options: EventHubSenderOptions,\n ): EventHubSender {\n const ehSender: EventHubSender = new EventHubSender(context, senderId, options);\n if (!context.senders[ehSender.name]) {\n context.senders[ehSender.name] = ehSender;\n }\n return context.senders[ehSender.name];\n }\n}\n\n/**\n * Generates the link properties for an indemopotent sender given\n * based on the user-provided and locally-cached publishing options.\n *\n * Note: The set of idempotent properties a user specifies at EventHubProducerClient instantiation-time\n * is slightly different than what the service returns and the EventHubSender keeps track of locally.\n *\n * The difference is that the user specifies the `startingSequenceNumber`, whereas the local options\n * (those returned by getPartitionPublishingProperties) specifies `lastPublishedSequenceNumber`.\n *\n * These _can_ be the same, but the user is technically free to set any `startingSequenceNumber` they want.\n * @internal\n */\nexport function generateIdempotentLinkProperties(\n userProvidedPublishingOptions: PartitionPublishingOptions | undefined,\n localPublishingOptions: PartitionPublishingProperties | undefined,\n): IdempotentLinkProperties | Record<string, never> {\n let ownerLevel: number | undefined;\n let producerGroupId: number | undefined;\n let sequenceNumber: number | undefined;\n\n // Prefer local publishing options since this is the up-to-date state of the sender.\n // Only use user-provided publishing options the first time we create the link.\n if (localPublishingOptions) {\n ownerLevel = localPublishingOptions.ownerLevel;\n producerGroupId = localPublishingOptions.producerGroupId;\n sequenceNumber = localPublishingOptions.lastPublishedSequenceNumber;\n } else if (userProvidedPublishingOptions) {\n ownerLevel = userProvidedPublishingOptions.ownerLevel;\n producerGroupId = userProvidedPublishingOptions.producerGroupId;\n sequenceNumber = userProvidedPublishingOptions.startingSequenceNumber;\n } else {\n // If we don't have any properties at all, send an empty object.\n // This will cause the service to generate a new producer-id for our client.\n return {};\n }\n\n // The service requires that if ANY_ of these properties are defined,\n // they _ALL_ have to be defined.\n // If we don't have one of the required values, use `null` and the\n // service will provide it.\n const idempotentLinkProperties: IdempotentLinkProperties = {\n [idempotentProducerAmqpPropertyNames.epoch]: isDefined(ownerLevel)\n ? types.wrap_short(ownerLevel)\n : null,\n [idempotentProducerAmqpPropertyNames.producerId]: isDefined(producerGroupId)\n ? types.wrap_long(producerGroupId)\n : null,\n [idempotentProducerAmqpPropertyNames.producerSequenceNumber]: isDefined(sequenceNumber)\n ? types.wrap_int(sequenceNumber)\n : null,\n };\n\n return idempotentLinkProperties;\n}\n\n/**\n * Encodes a list or batch of events into a single binary message that can be sent to the service.\n *\n * Prior to encoding, any special properties not specified by the user, such as tracing or idempotent\n * properties, are assigned to the list or batch of events as needed.\n *\n * @internal\n * @param events - Events to transform for sending to the service.\n * @param publishingProps - Describes the current publishing state for the partition.\n * @param options - Options used to configure this function.\n */\nexport function transformEventsForSend(\n events: EventData[] | EventDataBatch,\n publishingProps: PartitionPublishingProperties,\n options: SendOptions & {\n /**\n * A list containing the `Diagnostic-Id` tracing property that is associated with each EventData.\n * The index of tracingProperties corresponds to the same index in `events` when `events` is EventData[].\n */\n tracingProperties?: Array<EventData[\"properties\"]>;\n } = {},\n): Buffer {\n if (isEventDataBatch(events)) {\n return (events as EventDataBatchImpl)._generateMessage(publishingProps);\n } else {\n const eventCount = events.length;\n // convert events to rhea messages\n const rheaMessages: RheaMessage[] = [];\n const tracingProperties = options.tracingProperties ?? [];\n for (let i = 0; i < eventCount; i++) {\n const originalEvent = events[i];\n const tracingProperty = tracingProperties[i];\n // Create a copy of the user's event so we can add the tracing property.\n const event: EventData = {\n ...originalEvent,\n properties: { ...originalEvent.properties, ...tracingProperty },\n };\n const rheaMessage = toRheaMessage(event, options.partitionKey);\n\n // populate idempotent message annotations\n const { lastPublishedSequenceNumber = 0 } = publishingProps;\n const startingSequenceNumber = lastPublishedSequenceNumber + 1;\n const pendingPublishSequenceNumber = startingSequenceNumber + i;\n populateIdempotentMessageAnnotations(rheaMessage, {\n ...publishingProps,\n publishSequenceNumber: pendingPublishSequenceNumber,\n });\n\n if (publishingProps.isIdempotentPublishingEnabled) {\n // Set pending seq number on user's event.\n (originalEvent as EventDataInternal)[PENDING_PUBLISH_SEQ_NUM_SYMBOL] =\n pendingPublishSequenceNumber;\n }\n\n rheaMessages.push(rheaMessage);\n }\n\n // Encode every amqp message and then convert every encoded message to amqp data section\n const batchMessage: RheaMessage = {\n body: message.data_sections(rheaMessages.map(message.encode)),\n };\n\n // Set message_annotations of the first message as\n // that of the envelope (batch message).\n if (rheaMessages[0].message_annotations) {\n batchMessage.message_annotations = { ...rheaMessages[0].message_annotations };\n }\n\n // Finally encode the envelope (batch message).\n return message.encode(batchMessage);\n }\n}\n\n/**\n * Commits the pending publish sequence number events.\n * EventDataBatch exposes this as `startingPublishSequenceNumber`,\n * EventData not in a batch exposes this as `publishedSequenceNumber`.\n */\nfunction commitIdempotentSequenceNumbers(\n events: Omit<EventDataInternal, \"getRawAmqpMessage\">[] | EventDataBatch,\n): void {\n if (isEventDataBatch(events)) {\n (events as EventDataBatchImpl)._commitPublish();\n } else {\n // For each event, set the `publishedSequenceNumber` equal to the sequence number\n // we set when we attempted to send the events to the service.\n for (const event of events) {\n event._publishedSequenceNumber = event[PENDING_PUBLISH_SEQ_NUM_SYMBOL];\n delete event[PENDING_PUBLISH_SEQ_NUM_SYMBOL];\n }\n }\n}\n\n/**\n * Rolls back any pending publish sequence number in the events.\n */\nfunction rollbackIdempotentSequenceNumbers(\n events: Omit<EventDataInternal, \"getRawAmqpMessage\">[] | EventDataBatch,\n): void {\n if (isEventDataBatch(events)) {\n /* No action required. */\n } else {\n for (const event of events) {\n delete event[PENDING_PUBLISH_SEQ_NUM_SYMBOL];\n }\n }\n}\n"]}
@@ -24,6 +24,30 @@ const core_amqp_1 = require("@azure/core-amqp");
24
24
  * @internal
25
25
  */
26
26
  class EventProcessor {
27
+ _consumerGroup;
28
+ _context;
29
+ _subscriptionEventHandlers;
30
+ _checkpointStore;
31
+ _processorOptions;
32
+ _pumpManager;
33
+ _id;
34
+ _isRunning = false;
35
+ _loopTask;
36
+ _abortController;
37
+ /**
38
+ * A specific partition to target.
39
+ */
40
+ _processingTarget;
41
+ /**
42
+ * Determines which partitions to claim as part of load balancing.
43
+ */
44
+ _loadBalancingStrategy;
45
+ /**
46
+ * The amount of time between load balancing attempts.
47
+ */
48
+ _loopIntervalInMs;
49
+ _eventHubName;
50
+ _fullyQualifiedNamespace;
27
51
  /**
28
52
  * @param consumerGroup - The name of the consumer group from which you want to process events.
29
53
  * @param eventHubClient - An instance of `EventHubClient` that was created for the Event Hub instance.
@@ -41,7 +65,6 @@ class EventProcessor {
41
65
  this._context = _context;
42
66
  this._subscriptionEventHandlers = _subscriptionEventHandlers;
43
67
  this._checkpointStore = _checkpointStore;
44
- this._isRunning = false;
45
68
  if (options.ownerId) {
46
69
  this._id = options.ownerId;
47
70
  logger_js_1.logger.verbose(`Starting event processor with ID ${this._id}`);
@@ -138,7 +161,7 @@ class EventProcessor {
138
161
  await this._startPump(partitionId, abortSignal);
139
162
  }
140
163
  catch (err) {
141
- logger_js_1.logger.warning(`[${this._id}] An error occurred within the EventProcessor loop: ${err === null || err === void 0 ? void 0 : err.name}: ${err === null || err === void 0 ? void 0 : err.message}`);
164
+ logger_js_1.logger.warning(`[${this._id}] An error occurred within the EventProcessor loop: ${err?.name}: ${err?.message}`);
142
165
  (0, logger_js_1.logErrorStackTrace)(err);
143
166
  await this._handleSubscriptionError(err);
144
167
  }
@@ -183,7 +206,7 @@ class EventProcessor {
183
206
  await this._performLoadBalancing(loadBalancingStrategy, partitionIds, abortSignal);
184
207
  }
185
208
  catch (err) {
186
- logger_js_1.logger.warning(`[${this._id}] An error occurred within the EventProcessor loop: ${err === null || err === void 0 ? void 0 : err.name}: ${err === null || err === void 0 ? void 0 : err.message}`);
209
+ logger_js_1.logger.warning(`[${this._id}] An error occurred within the EventProcessor loop: ${err?.name}: ${err?.message}`);
187
210
  (0, logger_js_1.logErrorStackTrace)(err);
188
211
  // Protect against the scenario where the user awaits on subscription.close() from inside processError.
189
212
  await Promise.race([this._handleSubscriptionError(err), cancelLoopPromise]);
@@ -284,10 +307,9 @@ class EventProcessor {
284
307
  *
285
308
  */
286
309
  async stop() {
287
- var _a;
288
310
  logger_js_1.logger.verbose(`[${this._id}] Stopping an EventProcessor.`);
289
311
  // cancel the event processor loop
290
- (_a = this._abortController) === null || _a === void 0 ? void 0 : _a.abort();
312
+ this._abortController?.abort();
291
313
  try {
292
314
  // remove all existing pumps
293
315
  await this._pumpManager.removeAllPumps(public_js_1.CloseReason.Shutdown);