@azure/event-hubs 6.0.1-alpha.20250618.1 → 6.0.1-alpha.20250730.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.
- package/dist/browser/batchingPartitionChannel.js +23 -17
- package/dist/browser/batchingPartitionChannel.js.map +1 -1
- package/dist/browser/connectionContext.js +18 -32
- package/dist/browser/connectionContext.js.map +1 -1
- package/dist/browser/diagnostics/instrumentEventData.js +6 -7
- package/dist/browser/diagnostics/instrumentEventData.js.map +1 -1
- package/dist/browser/eventData.js +6 -4
- package/dist/browser/eventData.js.map +1 -1
- package/dist/browser/eventDataAdapter.js +5 -2
- package/dist/browser/eventDataAdapter.js.map +1 -1
- package/dist/browser/eventDataBatch.js +61 -9
- package/dist/browser/eventDataBatch.js.map +1 -1
- package/dist/browser/eventHubBufferedProducerClient.js +65 -50
- package/dist/browser/eventHubBufferedProducerClient.js.map +1 -1
- package/dist/browser/eventHubConsumerClient.js +70 -24
- package/dist/browser/eventHubConsumerClient.js.map +1 -1
- package/dist/browser/eventHubProducerClient.js +58 -15
- package/dist/browser/eventHubProducerClient.js.map +1 -1
- package/dist/browser/eventHubSender.js +118 -35
- package/dist/browser/eventHubSender.js.map +1 -1
- package/dist/browser/eventProcessor.js +27 -5
- package/dist/browser/eventProcessor.js.map +1 -1
- package/dist/browser/impl/awaitableQueue.js +6 -2
- package/dist/browser/impl/awaitableQueue.js.map +1 -1
- package/dist/browser/impl/partitionAssigner.js +2 -4
- package/dist/browser/impl/partitionAssigner.js.map +1 -1
- package/dist/browser/impl/partitionGate.js +1 -3
- package/dist/browser/impl/partitionGate.js.map +1 -1
- package/dist/browser/inMemoryCheckpointStore.js +10 -8
- package/dist/browser/inMemoryCheckpointStore.js.map +1 -1
- package/dist/browser/loadBalancerStrategies/balancedStrategy.js +1 -0
- package/dist/browser/loadBalancerStrategies/balancedStrategy.js.map +1 -1
- package/dist/browser/loadBalancerStrategies/greedyStrategy.js +1 -0
- package/dist/browser/loadBalancerStrategies/greedyStrategy.js.map +1 -1
- package/dist/browser/managementClient.js +53 -19
- package/dist/browser/managementClient.js.map +1 -1
- package/dist/browser/partitionProcessor.js +5 -2
- package/dist/browser/partitionProcessor.js.map +1 -1
- package/dist/browser/partitionPump.js +15 -6
- package/dist/browser/partitionPump.js.map +1 -1
- package/dist/browser/partitionReceiver.js +30 -25
- package/dist/browser/partitionReceiver.js.map +1 -1
- package/dist/browser/pumpManager.js +3 -1
- package/dist/browser/pumpManager.js.map +1 -1
- package/dist/browser/util/delayWithoutThrow.js +1 -1
- package/dist/browser/util/delayWithoutThrow.js.map +1 -1
- package/dist/commonjs/batchingPartitionChannel.js +23 -17
- package/dist/commonjs/batchingPartitionChannel.js.map +1 -1
- package/dist/commonjs/connectionContext.js +18 -32
- package/dist/commonjs/connectionContext.js.map +1 -1
- package/dist/commonjs/diagnostics/instrumentEventData.js +6 -7
- package/dist/commonjs/diagnostics/instrumentEventData.js.map +1 -1
- package/dist/commonjs/eventData.js +6 -4
- package/dist/commonjs/eventData.js.map +1 -1
- package/dist/commonjs/eventDataAdapter.js +5 -2
- package/dist/commonjs/eventDataAdapter.js.map +1 -1
- package/dist/commonjs/eventDataBatch.js +61 -9
- package/dist/commonjs/eventDataBatch.js.map +1 -1
- package/dist/commonjs/eventHubBufferedProducerClient.js +65 -50
- package/dist/commonjs/eventHubBufferedProducerClient.js.map +1 -1
- package/dist/commonjs/eventHubConsumerClient.js +70 -24
- package/dist/commonjs/eventHubConsumerClient.js.map +1 -1
- package/dist/commonjs/eventHubProducerClient.js +58 -15
- package/dist/commonjs/eventHubProducerClient.js.map +1 -1
- package/dist/commonjs/eventHubSender.js +118 -35
- package/dist/commonjs/eventHubSender.js.map +1 -1
- package/dist/commonjs/eventProcessor.js +27 -5
- package/dist/commonjs/eventProcessor.js.map +1 -1
- package/dist/commonjs/impl/awaitableQueue.js +6 -2
- package/dist/commonjs/impl/awaitableQueue.js.map +1 -1
- package/dist/commonjs/impl/partitionAssigner.js +2 -4
- package/dist/commonjs/impl/partitionAssigner.js.map +1 -1
- package/dist/commonjs/impl/partitionGate.js +1 -3
- package/dist/commonjs/impl/partitionGate.js.map +1 -1
- package/dist/commonjs/inMemoryCheckpointStore.js +10 -8
- package/dist/commonjs/inMemoryCheckpointStore.js.map +1 -1
- package/dist/commonjs/loadBalancerStrategies/balancedStrategy.js +1 -0
- package/dist/commonjs/loadBalancerStrategies/balancedStrategy.js.map +1 -1
- package/dist/commonjs/loadBalancerStrategies/greedyStrategy.js +1 -0
- package/dist/commonjs/loadBalancerStrategies/greedyStrategy.js.map +1 -1
- package/dist/commonjs/managementClient.js +53 -19
- package/dist/commonjs/managementClient.js.map +1 -1
- package/dist/commonjs/partitionProcessor.js +5 -2
- package/dist/commonjs/partitionProcessor.js.map +1 -1
- package/dist/commonjs/partitionPump.js +15 -6
- package/dist/commonjs/partitionPump.js.map +1 -1
- package/dist/commonjs/partitionReceiver.js +30 -25
- package/dist/commonjs/partitionReceiver.js.map +1 -1
- package/dist/commonjs/pumpManager.js +3 -1
- package/dist/commonjs/pumpManager.js.map +1 -1
- package/dist/commonjs/tsdoc-metadata.json +11 -11
- package/dist/commonjs/util/delayWithoutThrow.js +1 -1
- package/dist/commonjs/util/delayWithoutThrow.js.map +1 -1
- package/dist/esm/batchingPartitionChannel.js +23 -17
- package/dist/esm/batchingPartitionChannel.js.map +1 -1
- package/dist/esm/connectionContext.js +18 -32
- package/dist/esm/connectionContext.js.map +1 -1
- package/dist/esm/diagnostics/instrumentEventData.js +6 -7
- package/dist/esm/diagnostics/instrumentEventData.js.map +1 -1
- package/dist/esm/eventData.js +6 -4
- package/dist/esm/eventData.js.map +1 -1
- package/dist/esm/eventDataAdapter.js +5 -2
- package/dist/esm/eventDataAdapter.js.map +1 -1
- package/dist/esm/eventDataBatch.js +61 -9
- package/dist/esm/eventDataBatch.js.map +1 -1
- package/dist/esm/eventHubBufferedProducerClient.js +65 -50
- package/dist/esm/eventHubBufferedProducerClient.js.map +1 -1
- package/dist/esm/eventHubConsumerClient.js +70 -24
- package/dist/esm/eventHubConsumerClient.js.map +1 -1
- package/dist/esm/eventHubProducerClient.js +58 -15
- package/dist/esm/eventHubProducerClient.js.map +1 -1
- package/dist/esm/eventHubSender.js +118 -35
- package/dist/esm/eventHubSender.js.map +1 -1
- package/dist/esm/eventProcessor.js +27 -5
- package/dist/esm/eventProcessor.js.map +1 -1
- package/dist/esm/impl/awaitableQueue.js +6 -2
- package/dist/esm/impl/awaitableQueue.js.map +1 -1
- package/dist/esm/impl/partitionAssigner.js +2 -4
- package/dist/esm/impl/partitionAssigner.js.map +1 -1
- package/dist/esm/impl/partitionGate.js +1 -3
- package/dist/esm/impl/partitionGate.js.map +1 -1
- package/dist/esm/inMemoryCheckpointStore.js +10 -8
- package/dist/esm/inMemoryCheckpointStore.js.map +1 -1
- package/dist/esm/loadBalancerStrategies/balancedStrategy.js +1 -0
- package/dist/esm/loadBalancerStrategies/balancedStrategy.js.map +1 -1
- package/dist/esm/loadBalancerStrategies/greedyStrategy.js +1 -0
- package/dist/esm/loadBalancerStrategies/greedyStrategy.js.map +1 -1
- package/dist/esm/managementClient.js +53 -19
- package/dist/esm/managementClient.js.map +1 -1
- package/dist/esm/partitionProcessor.js +5 -2
- package/dist/esm/partitionProcessor.js.map +1 -1
- package/dist/esm/partitionPump.js +15 -6
- package/dist/esm/partitionPump.js.map +1 -1
- package/dist/esm/partitionReceiver.js +30 -25
- package/dist/esm/partitionReceiver.js.map +1 -1
- package/dist/esm/pumpManager.js +3 -1
- package/dist/esm/pumpManager.js.map +1 -1
- package/dist/esm/util/delayWithoutThrow.js +1 -1
- package/dist/esm/util/delayWithoutThrow.js.map +1 -1
- package/package.json +1 -1
|
@@ -16,22 +16,100 @@ import { getRandomName } from "./util/utils.js";
|
|
|
16
16
|
* @internal
|
|
17
17
|
*/
|
|
18
18
|
export class EventHubSender {
|
|
19
|
+
/**
|
|
20
|
+
* The unique lock name per connection that is used to acquire the
|
|
21
|
+
* lock for establishing a sender link by an entity on that connection.
|
|
22
|
+
*/
|
|
23
|
+
senderLock = getRandomName("sender");
|
|
24
|
+
/**
|
|
25
|
+
* The handler function to handle errors that happen on the
|
|
26
|
+
* underlying sender.
|
|
27
|
+
*/
|
|
28
|
+
_onAmqpError;
|
|
29
|
+
/**
|
|
30
|
+
* The handler function to handle "sender_close" event
|
|
31
|
+
* that happens on the underlying sender.
|
|
32
|
+
*/
|
|
33
|
+
_onAmqpClose;
|
|
34
|
+
/**
|
|
35
|
+
* The message handler that will be set as the handler on
|
|
36
|
+
* the underlying rhea sender's session for the "session_error" event.
|
|
37
|
+
*/
|
|
38
|
+
_onSessionError;
|
|
39
|
+
/**
|
|
40
|
+
* The message handler that will be set as the handler on
|
|
41
|
+
* the underlying rhea sender's session for the "session_close" event.
|
|
42
|
+
*/
|
|
43
|
+
_onSessionClose;
|
|
44
|
+
/**
|
|
45
|
+
* The AMQP sender link.
|
|
46
|
+
*/
|
|
47
|
+
_sender;
|
|
48
|
+
/**
|
|
49
|
+
* The partition ID.
|
|
50
|
+
*/
|
|
51
|
+
partitionId;
|
|
52
|
+
/**
|
|
53
|
+
* Indicates whether the sender is configured for idempotent publishing.
|
|
54
|
+
*/
|
|
55
|
+
_isIdempotentProducer;
|
|
56
|
+
/**
|
|
57
|
+
* Indicates whether the sender has an in-flight send while idempotent
|
|
58
|
+
* publishing is enabled.
|
|
59
|
+
*/
|
|
60
|
+
_hasPendingSend;
|
|
61
|
+
/**
|
|
62
|
+
* A local copy of the PartitionPublishingProperties that can be mutated to
|
|
63
|
+
* keep track of the lastSequenceNumber used.
|
|
64
|
+
*/
|
|
65
|
+
_localPublishingProperties;
|
|
66
|
+
/**
|
|
67
|
+
* The user-provided set of options that can be specified to influence
|
|
68
|
+
* publishing behavior specific to a partition.
|
|
69
|
+
*/
|
|
70
|
+
_userProvidedPublishingOptions;
|
|
71
|
+
/**
|
|
72
|
+
* Indicates whether the link is in the process of connecting
|
|
73
|
+
* (establishing) itself. Default value: `false`.
|
|
74
|
+
*/
|
|
75
|
+
isConnecting = false;
|
|
76
|
+
/**
|
|
77
|
+
* The unique name for the entity (mostly a guid).
|
|
78
|
+
*/
|
|
79
|
+
name;
|
|
80
|
+
/**
|
|
81
|
+
* The address in the following form:
|
|
82
|
+
* - `"<hubName>"`
|
|
83
|
+
* - `"<hubName>/Partitions/<partitionId>"`.
|
|
84
|
+
*/
|
|
85
|
+
address;
|
|
86
|
+
/**
|
|
87
|
+
* The token audience in the following form:
|
|
88
|
+
* - `"sb://<yournamespace>.servicebus.windows.net/<hubName>"`
|
|
89
|
+
* - `"sb://<yournamespace>.servicebus.windows.net/<hubName>/Partitions/<partitionId>"`.
|
|
90
|
+
*/
|
|
91
|
+
audience;
|
|
92
|
+
/**
|
|
93
|
+
* Provides relevant information about the amqp connection,
|
|
94
|
+
* cbs and $management sessions, token provider, sender and receivers.
|
|
95
|
+
*/
|
|
96
|
+
_context;
|
|
97
|
+
/**
|
|
98
|
+
* The auth loop.
|
|
99
|
+
*/
|
|
100
|
+
authLoop;
|
|
101
|
+
/**
|
|
102
|
+
* The logger.
|
|
103
|
+
*/
|
|
104
|
+
logger;
|
|
105
|
+
/** The client identifier */
|
|
106
|
+
_id;
|
|
19
107
|
/**
|
|
20
108
|
* Creates a new EventHubSender instance.
|
|
21
109
|
* @param context - The connection context.
|
|
22
110
|
* @param options - Options used to configure the EventHubSender.
|
|
23
111
|
*/
|
|
24
112
|
constructor(context, senderId, { partitionId, enableIdempotentProducer, partitionPublishingOptions }) {
|
|
25
|
-
/**
|
|
26
|
-
* The unique lock name per connection that is used to acquire the
|
|
27
|
-
* lock for establishing a sender link by an entity on that connection.
|
|
28
|
-
*/
|
|
29
|
-
this.senderLock = getRandomName("sender");
|
|
30
|
-
/**
|
|
31
|
-
* Indicates whether the link is in the process of connecting
|
|
32
|
-
* (establishing) itself. Default value: `false`.
|
|
33
|
-
*/
|
|
34
|
-
this.isConnecting = false;
|
|
35
113
|
this.address = context.config.getSenderAddress(partitionId);
|
|
36
114
|
this.name = this.address;
|
|
37
115
|
this._id = senderId;
|
|
@@ -55,7 +133,7 @@ export class EventHubSender {
|
|
|
55
133
|
this._onAmqpClose = async (eventContext) => {
|
|
56
134
|
const sender = this._sender || eventContext.sender;
|
|
57
135
|
this.logger.verbose("'sender_close' event occurred. Value for isItselfClosed on the receiver is: '%s' " +
|
|
58
|
-
"Value for isConnecting on the session is: '%s'.", sender
|
|
136
|
+
"Value for isConnecting on the session is: '%s'.", sender?.isItselfClosed().toString(), this.isConnecting);
|
|
59
137
|
if (sender && !this.isConnecting) {
|
|
60
138
|
// Call close to clean up timers & other resources
|
|
61
139
|
await sender.close().catch((err) => {
|
|
@@ -66,7 +144,7 @@ export class EventHubSender {
|
|
|
66
144
|
this._onSessionClose = async (eventContext) => {
|
|
67
145
|
const sender = this._sender || eventContext.sender;
|
|
68
146
|
this.logger.verbose("'session_close' event occurred. Value for isSessionItselfClosed on the session is: '%s' " +
|
|
69
|
-
"Value for isConnecting on the session is: '%s'.", sender
|
|
147
|
+
"Value for isConnecting on the session is: '%s'.", sender?.isSessionItselfClosed().toString(), this.isConnecting);
|
|
70
148
|
if (sender && !this.isConnecting) {
|
|
71
149
|
// Call close to clean up timers & other resources
|
|
72
150
|
await sender.close().catch((err) => {
|
|
@@ -79,19 +157,18 @@ export class EventHubSender {
|
|
|
79
157
|
* Deletes the sender from the context. Clears the token renewal timer. Closes the sender link.
|
|
80
158
|
*/
|
|
81
159
|
async close() {
|
|
82
|
-
var _a;
|
|
83
160
|
try {
|
|
84
161
|
if (this._sender) {
|
|
85
162
|
this.logger.info("closing");
|
|
86
163
|
const senderLink = this._sender;
|
|
87
164
|
this._deleteFromCache();
|
|
88
165
|
await senderLink.close();
|
|
89
|
-
|
|
166
|
+
this.authLoop?.stop();
|
|
90
167
|
this.logger.verbose("closed.");
|
|
91
168
|
}
|
|
92
169
|
}
|
|
93
170
|
catch (err) {
|
|
94
|
-
const msg = `an error occurred while closing: ${err
|
|
171
|
+
const msg = `an error occurred while closing: ${err?.name}: ${err?.message}`;
|
|
95
172
|
this.logger.warning(msg);
|
|
96
173
|
logErrorStackTrace(err);
|
|
97
174
|
throw err;
|
|
@@ -123,14 +200,13 @@ export class EventHubSender {
|
|
|
123
200
|
* for the producer client.
|
|
124
201
|
*/
|
|
125
202
|
async getPartitionPublishingProperties(options = {}) {
|
|
126
|
-
var _a, _b;
|
|
127
203
|
if (this._localPublishingProperties) {
|
|
128
204
|
// Send a copy of the properties so it can't be mutated downstream.
|
|
129
|
-
return
|
|
205
|
+
return { ...this._localPublishingProperties };
|
|
130
206
|
}
|
|
131
207
|
const properties = {
|
|
132
208
|
isIdempotentPublishingEnabled: this._isIdempotentProducer,
|
|
133
|
-
partitionId:
|
|
209
|
+
partitionId: this.partitionId ?? "",
|
|
134
210
|
};
|
|
135
211
|
if (this._isIdempotentProducer) {
|
|
136
212
|
this._sender = await this._getLink(options);
|
|
@@ -140,14 +216,14 @@ export class EventHubSender {
|
|
|
140
216
|
// deleted while setting up token refreshing, make sure it exists.
|
|
141
217
|
throw new Error(`Failed to retrieve partition publishing properties for partition "${this.partitionId}".`);
|
|
142
218
|
}
|
|
143
|
-
const { [idempotentProducerAmqpPropertyNames.epoch]: ownerLevel, [idempotentProducerAmqpPropertyNames.producerId]: producerGroupId, [idempotentProducerAmqpPropertyNames.producerSequenceNumber]: lastPublishedSequenceNumber, } =
|
|
219
|
+
const { [idempotentProducerAmqpPropertyNames.epoch]: ownerLevel, [idempotentProducerAmqpPropertyNames.producerId]: producerGroupId, [idempotentProducerAmqpPropertyNames.producerSequenceNumber]: lastPublishedSequenceNumber, } = this._sender.properties ?? {};
|
|
144
220
|
properties.ownerLevel = parseInt(ownerLevel, 10);
|
|
145
221
|
properties.producerGroupId = parseInt(producerGroupId, 10);
|
|
146
222
|
properties.lastPublishedSequenceNumber = parseInt(lastPublishedSequenceNumber, 10);
|
|
147
223
|
}
|
|
148
224
|
this._localPublishingProperties = properties;
|
|
149
225
|
// Send a copy of the properties so it can't be mutated downstream.
|
|
150
|
-
return
|
|
226
|
+
return { ...properties };
|
|
151
227
|
}
|
|
152
228
|
/**
|
|
153
229
|
* Send a batch of EventData to the EventHub. The "message_annotations",
|
|
@@ -185,7 +261,7 @@ export class EventHubSender {
|
|
|
185
261
|
}
|
|
186
262
|
catch (err) {
|
|
187
263
|
rollbackIdempotentSequenceNumbers(events);
|
|
188
|
-
this.logger.warning(`an error occurred while sending the batch message ${err
|
|
264
|
+
this.logger.warning(`an error occurred while sending the batch message ${err?.name}: ${err?.message}`);
|
|
189
265
|
logErrorStackTrace(err);
|
|
190
266
|
throw err;
|
|
191
267
|
}
|
|
@@ -199,11 +275,10 @@ export class EventHubSender {
|
|
|
199
275
|
* @param sender - The rhea sender that contains the idempotent producer properties.
|
|
200
276
|
*/
|
|
201
277
|
_populateLocalPublishingProperties(sender) {
|
|
202
|
-
|
|
203
|
-
const { [idempotentProducerAmqpPropertyNames.epoch]: ownerLevel, [idempotentProducerAmqpPropertyNames.producerId]: producerGroupId, [idempotentProducerAmqpPropertyNames.producerSequenceNumber]: lastPublishedSequenceNumber, } = (_a = sender.properties) !== null && _a !== void 0 ? _a : {};
|
|
278
|
+
const { [idempotentProducerAmqpPropertyNames.epoch]: ownerLevel, [idempotentProducerAmqpPropertyNames.producerId]: producerGroupId, [idempotentProducerAmqpPropertyNames.producerSequenceNumber]: lastPublishedSequenceNumber, } = sender.properties ?? {};
|
|
204
279
|
this._localPublishingProperties = {
|
|
205
280
|
isIdempotentPublishingEnabled: this._isIdempotentProducer,
|
|
206
|
-
partitionId:
|
|
281
|
+
partitionId: this.partitionId ?? "",
|
|
207
282
|
lastPublishedSequenceNumber,
|
|
208
283
|
ownerLevel,
|
|
209
284
|
producerGroupId,
|
|
@@ -250,7 +325,6 @@ export class EventHubSender {
|
|
|
250
325
|
const timeoutInMs = getRetryAttemptTimeoutInMs(retryOptions);
|
|
251
326
|
retryOptions.timeoutInMs = timeoutInMs;
|
|
252
327
|
const sendEventPromise = async () => {
|
|
253
|
-
var _a, _b;
|
|
254
328
|
const initStartTime = Date.now();
|
|
255
329
|
// TODO: (jeremymeng) A or B
|
|
256
330
|
// variant A:
|
|
@@ -264,7 +338,7 @@ export class EventHubSender {
|
|
|
264
338
|
if (!sender.sendable() && timeoutInMs - timeTakenByInit > waitTimeForSendable) {
|
|
265
339
|
this.logger.verbose("waiting for 1 second for sender to become sendable");
|
|
266
340
|
await delay(waitTimeForSendable);
|
|
267
|
-
this.logger.verbose("after waiting for a second, credit: %d available: %d", sender.credit,
|
|
341
|
+
this.logger.verbose("after waiting for a second, credit: %d available: %d", sender.credit, sender.session?.outgoing?.available());
|
|
268
342
|
}
|
|
269
343
|
else {
|
|
270
344
|
waitTimeForSendable = 0;
|
|
@@ -315,7 +389,7 @@ export class EventHubSender {
|
|
|
315
389
|
}
|
|
316
390
|
catch (err) {
|
|
317
391
|
const translatedError = translate(err);
|
|
318
|
-
this.logger.warning("an error occurred while sending the message %s", `${translatedError
|
|
392
|
+
this.logger.warning("an error occurred while sending the message %s", `${translatedError?.name}: ${translatedError?.message}`);
|
|
319
393
|
logErrorStackTrace(translatedError);
|
|
320
394
|
throw translatedError;
|
|
321
395
|
}
|
|
@@ -333,7 +407,11 @@ export class EventHubSender {
|
|
|
333
407
|
return defaultCancellableLock.acquire(this.senderLock, () => {
|
|
334
408
|
const taskStartTime = Date.now();
|
|
335
409
|
const taskTimeoutInMs = timeoutInMs - (taskStartTime - startTime);
|
|
336
|
-
return this._init(
|
|
410
|
+
return this._init({
|
|
411
|
+
...senderOptions,
|
|
412
|
+
abortSignal: options.abortSignal,
|
|
413
|
+
timeoutInMs: taskTimeoutInMs,
|
|
414
|
+
});
|
|
337
415
|
}, { abortSignal: options.abortSignal, timeoutInMs: timeoutInMs });
|
|
338
416
|
};
|
|
339
417
|
const config = {
|
|
@@ -348,7 +426,7 @@ export class EventHubSender {
|
|
|
348
426
|
}
|
|
349
427
|
catch (err) {
|
|
350
428
|
const translatedError = translate(err);
|
|
351
|
-
this.logger.warning("an error occurred while creating: %s", `${translatedError
|
|
429
|
+
this.logger.warning("an error occurred while creating: %s", `${translatedError?.name}: ${translatedError?.message}`);
|
|
352
430
|
logErrorStackTrace(translatedError);
|
|
353
431
|
throw translatedError;
|
|
354
432
|
}
|
|
@@ -385,7 +463,7 @@ export class EventHubSender {
|
|
|
385
463
|
}
|
|
386
464
|
catch (err) {
|
|
387
465
|
const translatedError = translate(err);
|
|
388
|
-
this.logger.warning("an error occurred while being created: %s", `${translatedError
|
|
466
|
+
this.logger.warning("an error occurred while being created: %s", `${translatedError?.name}: ${translatedError?.message}`);
|
|
389
467
|
logErrorStackTrace(translatedError);
|
|
390
468
|
throw translatedError;
|
|
391
469
|
}
|
|
@@ -467,7 +545,6 @@ export function generateIdempotentLinkProperties(userProvidedPublishingOptions,
|
|
|
467
545
|
* @param options - Options used to configure this function.
|
|
468
546
|
*/
|
|
469
547
|
export function transformEventsForSend(events, publishingProps, options = {}) {
|
|
470
|
-
var _a;
|
|
471
548
|
if (isEventDataBatch(events)) {
|
|
472
549
|
return events._generateMessage(publishingProps);
|
|
473
550
|
}
|
|
@@ -475,18 +552,24 @@ export function transformEventsForSend(events, publishingProps, options = {}) {
|
|
|
475
552
|
const eventCount = events.length;
|
|
476
553
|
// convert events to rhea messages
|
|
477
554
|
const rheaMessages = [];
|
|
478
|
-
const tracingProperties =
|
|
555
|
+
const tracingProperties = options.tracingProperties ?? [];
|
|
479
556
|
for (let i = 0; i < eventCount; i++) {
|
|
480
557
|
const originalEvent = events[i];
|
|
481
558
|
const tracingProperty = tracingProperties[i];
|
|
482
559
|
// Create a copy of the user's event so we can add the tracing property.
|
|
483
|
-
const event =
|
|
560
|
+
const event = {
|
|
561
|
+
...originalEvent,
|
|
562
|
+
properties: { ...originalEvent.properties, ...tracingProperty },
|
|
563
|
+
};
|
|
484
564
|
const rheaMessage = toRheaMessage(event, options.partitionKey);
|
|
485
565
|
// populate idempotent message annotations
|
|
486
566
|
const { lastPublishedSequenceNumber = 0 } = publishingProps;
|
|
487
567
|
const startingSequenceNumber = lastPublishedSequenceNumber + 1;
|
|
488
568
|
const pendingPublishSequenceNumber = startingSequenceNumber + i;
|
|
489
|
-
populateIdempotentMessageAnnotations(rheaMessage,
|
|
569
|
+
populateIdempotentMessageAnnotations(rheaMessage, {
|
|
570
|
+
...publishingProps,
|
|
571
|
+
publishSequenceNumber: pendingPublishSequenceNumber,
|
|
572
|
+
});
|
|
490
573
|
if (publishingProps.isIdempotentPublishingEnabled) {
|
|
491
574
|
// Set pending seq number on user's event.
|
|
492
575
|
originalEvent[PENDING_PUBLISH_SEQ_NUM_SYMBOL] =
|
|
@@ -501,7 +584,7 @@ export function transformEventsForSend(events, publishingProps, options = {}) {
|
|
|
501
584
|
// Set message_annotations of the first message as
|
|
502
585
|
// that of the envelope (batch message).
|
|
503
586
|
if (rheaMessages[0].message_annotations) {
|
|
504
|
-
batchMessage.message_annotations =
|
|
587
|
+
batchMessage.message_annotations = { ...rheaMessages[0].message_annotations };
|
|
505
588
|
}
|
|
506
589
|
// Finally encode the envelope (batch message).
|
|
507
590
|
return message.encode(batchMessage);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eventHubSender.js","sourceRoot":"","sources":["../../src/eventHubSender.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAUlC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,sBAAsB,EACtB,KAAK,EACL,KAAK,EACL,SAAS,GACV,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,oCAAoC,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAErF,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,EAAE,qBAAqB,EAAE,MAAM,aAAa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,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,OAAO,KAAK,CAAC,8BAA8B,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 @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":["../../src/eventHubSender.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAUlC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,sBAAsB,EACtB,KAAK,EACL,KAAK,EACL,SAAS,GACV,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,oCAAoC,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAErF,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAA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QAC9D,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,KAAK,CAAC,wBAAwB,GAAG,KAAK,CAAC,8BAA8B,CAAC,CAAC;YACvE,OAAO,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,iCAAiC,CACxC,MAAuE;IAEvE,IAAI,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;QAC7B,yBAAyB;IAC3B,CAAC;SAAM,CAAC;QACN,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,OAAO,KAAK,CAAC,8BAA8B,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 @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"]}
|
|
@@ -21,6 +21,30 @@ import { StandardAbortMessage } from "@azure/core-amqp";
|
|
|
21
21
|
* @internal
|
|
22
22
|
*/
|
|
23
23
|
export class EventProcessor {
|
|
24
|
+
_consumerGroup;
|
|
25
|
+
_context;
|
|
26
|
+
_subscriptionEventHandlers;
|
|
27
|
+
_checkpointStore;
|
|
28
|
+
_processorOptions;
|
|
29
|
+
_pumpManager;
|
|
30
|
+
_id;
|
|
31
|
+
_isRunning = false;
|
|
32
|
+
_loopTask;
|
|
33
|
+
_abortController;
|
|
34
|
+
/**
|
|
35
|
+
* A specific partition to target.
|
|
36
|
+
*/
|
|
37
|
+
_processingTarget;
|
|
38
|
+
/**
|
|
39
|
+
* Determines which partitions to claim as part of load balancing.
|
|
40
|
+
*/
|
|
41
|
+
_loadBalancingStrategy;
|
|
42
|
+
/**
|
|
43
|
+
* The amount of time between load balancing attempts.
|
|
44
|
+
*/
|
|
45
|
+
_loopIntervalInMs;
|
|
46
|
+
_eventHubName;
|
|
47
|
+
_fullyQualifiedNamespace;
|
|
24
48
|
/**
|
|
25
49
|
* @param consumerGroup - The name of the consumer group from which you want to process events.
|
|
26
50
|
* @param eventHubClient - An instance of `EventHubClient` that was created for the Event Hub instance.
|
|
@@ -38,7 +62,6 @@ export class EventProcessor {
|
|
|
38
62
|
this._context = _context;
|
|
39
63
|
this._subscriptionEventHandlers = _subscriptionEventHandlers;
|
|
40
64
|
this._checkpointStore = _checkpointStore;
|
|
41
|
-
this._isRunning = false;
|
|
42
65
|
if (options.ownerId) {
|
|
43
66
|
this._id = options.ownerId;
|
|
44
67
|
logger.verbose(`Starting event processor with ID ${this._id}`);
|
|
@@ -135,7 +158,7 @@ export class EventProcessor {
|
|
|
135
158
|
await this._startPump(partitionId, abortSignal);
|
|
136
159
|
}
|
|
137
160
|
catch (err) {
|
|
138
|
-
logger.warning(`[${this._id}] An error occurred within the EventProcessor loop: ${err
|
|
161
|
+
logger.warning(`[${this._id}] An error occurred within the EventProcessor loop: ${err?.name}: ${err?.message}`);
|
|
139
162
|
logErrorStackTrace(err);
|
|
140
163
|
await this._handleSubscriptionError(err);
|
|
141
164
|
}
|
|
@@ -180,7 +203,7 @@ export class EventProcessor {
|
|
|
180
203
|
await this._performLoadBalancing(loadBalancingStrategy, partitionIds, abortSignal);
|
|
181
204
|
}
|
|
182
205
|
catch (err) {
|
|
183
|
-
logger.warning(`[${this._id}] An error occurred within the EventProcessor loop: ${err
|
|
206
|
+
logger.warning(`[${this._id}] An error occurred within the EventProcessor loop: ${err?.name}: ${err?.message}`);
|
|
184
207
|
logErrorStackTrace(err);
|
|
185
208
|
// Protect against the scenario where the user awaits on subscription.close() from inside processError.
|
|
186
209
|
await Promise.race([this._handleSubscriptionError(err), cancelLoopPromise]);
|
|
@@ -281,10 +304,9 @@ export class EventProcessor {
|
|
|
281
304
|
*
|
|
282
305
|
*/
|
|
283
306
|
async stop() {
|
|
284
|
-
var _a;
|
|
285
307
|
logger.verbose(`[${this._id}] Stopping an EventProcessor.`);
|
|
286
308
|
// cancel the event processor loop
|
|
287
|
-
|
|
309
|
+
this._abortController?.abort();
|
|
288
310
|
try {
|
|
289
311
|
// remove all existing pumps
|
|
290
312
|
await this._pumpManager.removeAllPumps(CloseReason.Shutdown);
|