@azure/service-bus 7.10.0-beta.2 → 7.10.0-beta.3
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/connectionContext.js +1 -2
- package/dist/browser/connectionContext.js.map +1 -1
- package/dist/browser/constructorHelpers.js +3 -4
- package/dist/browser/constructorHelpers.js.map +1 -1
- package/dist/browser/core/autoLockRenewer.js +9 -5
- package/dist/browser/core/autoLockRenewer.js.map +1 -1
- package/dist/browser/core/batchingReceiver.js +26 -18
- package/dist/browser/core/batchingReceiver.js.map +1 -1
- package/dist/browser/core/linkEntity.js +74 -13
- package/dist/browser/core/linkEntity.js.map +1 -1
- package/dist/browser/core/managementClient.js +48 -48
- package/dist/browser/core/managementClient.js.map +1 -1
- package/dist/browser/core/messageReceiver.js +41 -14
- package/dist/browser/core/messageReceiver.js.map +1 -1
- package/dist/browser/core/messageSender.js +33 -10
- package/dist/browser/core/messageSender.js.map +1 -1
- package/dist/browser/core/receiverHelper.js +3 -2
- package/dist/browser/core/receiverHelper.js.map +1 -1
- package/dist/browser/core/shared.js +11 -4
- package/dist/browser/core/shared.js.map +1 -1
- package/dist/browser/core/streamingReceiver.js +74 -43
- package/dist/browser/core/streamingReceiver.js.map +1 -1
- package/dist/browser/diagnostics/instrumentServiceBusMessage.js +16 -8
- package/dist/browser/diagnostics/instrumentServiceBusMessage.js.map +1 -1
- package/dist/browser/receivers/receiver.js +68 -23
- package/dist/browser/receivers/receiver.js.map +1 -1
- package/dist/browser/receivers/receiverCommon.js +36 -21
- package/dist/browser/receivers/receiverCommon.js.map +1 -1
- package/dist/browser/receivers/sessionReceiver.js +69 -29
- package/dist/browser/receivers/sessionReceiver.js.map +1 -1
- package/dist/browser/sender.js +33 -11
- package/dist/browser/sender.js.map +1 -1
- package/dist/browser/serializers/queueResourceSerializer.js +9 -1
- package/dist/browser/serializers/queueResourceSerializer.js.map +1 -1
- package/dist/browser/serializers/ruleResourceSerializer.js +1 -2
- package/dist/browser/serializers/ruleResourceSerializer.js.map +1 -1
- package/dist/browser/serviceBusAtomManagementClient.js +181 -228
- package/dist/browser/serviceBusAtomManagementClient.js.map +1 -1
- package/dist/browser/serviceBusClient.js +31 -22
- package/dist/browser/serviceBusClient.js.map +1 -1
- package/dist/browser/serviceBusError.js +21 -1
- package/dist/browser/serviceBusError.js.map +1 -1
- package/dist/browser/serviceBusMessage.js +208 -13
- package/dist/browser/serviceBusMessage.js.map +1 -1
- package/dist/browser/serviceBusMessageBatch.js +32 -8
- package/dist/browser/serviceBusMessageBatch.js.map +1 -1
- package/dist/browser/serviceBusRuleManager.js +39 -15
- package/dist/browser/serviceBusRuleManager.js.map +1 -1
- package/dist/browser/session/messageSession.js +130 -25
- package/dist/browser/session/messageSession.js.map +1 -1
- package/dist/browser/util/atomXmlHelper.js +4 -5
- package/dist/browser/util/atomXmlHelper.js.map +1 -1
- package/dist/browser/util/compat/httpHeaders.js +1 -0
- package/dist/browser/util/compat/httpHeaders.js.map +1 -1
- package/dist/browser/util/constants.js +1 -1
- package/dist/browser/util/constants.js.map +1 -1
- package/dist/browser/util/sasServiceClientCredentials.js +8 -0
- package/dist/browser/util/sasServiceClientCredentials.js.map +1 -1
- package/dist/browser/util/semaphore.js +6 -2
- package/dist/browser/util/semaphore.js.map +1 -1
- package/dist/browser/util/utils.js +5 -7
- package/dist/browser/util/utils.js.map +1 -1
- package/dist/commonjs/connectionContext.js +1 -2
- package/dist/commonjs/connectionContext.js.map +1 -1
- package/dist/commonjs/constructorHelpers.js +3 -4
- package/dist/commonjs/constructorHelpers.js.map +1 -1
- package/dist/commonjs/core/autoLockRenewer.js +9 -5
- package/dist/commonjs/core/autoLockRenewer.js.map +1 -1
- package/dist/commonjs/core/batchingReceiver.js +26 -18
- package/dist/commonjs/core/batchingReceiver.js.map +1 -1
- package/dist/commonjs/core/linkEntity.js +74 -13
- package/dist/commonjs/core/linkEntity.js.map +1 -1
- package/dist/commonjs/core/managementClient.js +48 -48
- package/dist/commonjs/core/managementClient.js.map +1 -1
- package/dist/commonjs/core/messageReceiver.js +41 -14
- package/dist/commonjs/core/messageReceiver.js.map +1 -1
- package/dist/commonjs/core/messageSender.js +33 -10
- package/dist/commonjs/core/messageSender.js.map +1 -1
- package/dist/commonjs/core/receiverHelper.js +3 -2
- package/dist/commonjs/core/receiverHelper.js.map +1 -1
- package/dist/commonjs/core/shared.js +11 -4
- package/dist/commonjs/core/shared.js.map +1 -1
- package/dist/commonjs/core/streamingReceiver.js +74 -43
- package/dist/commonjs/core/streamingReceiver.js.map +1 -1
- package/dist/commonjs/diagnostics/instrumentServiceBusMessage.js +16 -8
- package/dist/commonjs/diagnostics/instrumentServiceBusMessage.js.map +1 -1
- package/dist/commonjs/receivers/receiver.js +68 -23
- package/dist/commonjs/receivers/receiver.js.map +1 -1
- package/dist/commonjs/receivers/receiverCommon.js +36 -21
- package/dist/commonjs/receivers/receiverCommon.js.map +1 -1
- package/dist/commonjs/receivers/sessionReceiver.js +69 -29
- package/dist/commonjs/receivers/sessionReceiver.js.map +1 -1
- package/dist/commonjs/sender.js +33 -11
- package/dist/commonjs/sender.js.map +1 -1
- package/dist/commonjs/serializers/queueResourceSerializer.js +9 -1
- package/dist/commonjs/serializers/queueResourceSerializer.js.map +1 -1
- package/dist/commonjs/serializers/ruleResourceSerializer.js +1 -2
- package/dist/commonjs/serializers/ruleResourceSerializer.js.map +1 -1
- package/dist/commonjs/serviceBusAtomManagementClient.js +181 -227
- package/dist/commonjs/serviceBusAtomManagementClient.js.map +1 -1
- package/dist/commonjs/serviceBusClient.js +31 -22
- package/dist/commonjs/serviceBusClient.js.map +1 -1
- package/dist/commonjs/serviceBusError.js +21 -1
- package/dist/commonjs/serviceBusError.js.map +1 -1
- package/dist/commonjs/serviceBusMessage.js +208 -12
- package/dist/commonjs/serviceBusMessage.js.map +1 -1
- package/dist/commonjs/serviceBusMessageBatch.js +32 -8
- package/dist/commonjs/serviceBusMessageBatch.js.map +1 -1
- package/dist/commonjs/serviceBusRuleManager.js +39 -15
- package/dist/commonjs/serviceBusRuleManager.js.map +1 -1
- package/dist/commonjs/session/messageSession.js +130 -25
- package/dist/commonjs/session/messageSession.js.map +1 -1
- package/dist/commonjs/tsdoc-metadata.json +11 -11
- package/dist/commonjs/util/atomXmlHelper.js +4 -5
- package/dist/commonjs/util/atomXmlHelper.js.map +1 -1
- package/dist/commonjs/util/compat/httpHeaders.js +1 -0
- package/dist/commonjs/util/compat/httpHeaders.js.map +1 -1
- package/dist/commonjs/util/constants.js +1 -1
- package/dist/commonjs/util/constants.js.map +1 -1
- package/dist/commonjs/util/runtimeInfo.js +2 -2
- package/dist/commonjs/util/runtimeInfo.js.map +1 -1
- package/dist/commonjs/util/sasServiceClientCredentials.js +8 -0
- package/dist/commonjs/util/sasServiceClientCredentials.js.map +1 -1
- package/dist/commonjs/util/semaphore.js +6 -2
- package/dist/commonjs/util/semaphore.js.map +1 -1
- package/dist/commonjs/util/utils.js +5 -7
- package/dist/commonjs/util/utils.js.map +1 -1
- package/dist/esm/connectionContext.js +1 -2
- package/dist/esm/connectionContext.js.map +1 -1
- package/dist/esm/constructorHelpers.js +3 -4
- package/dist/esm/constructorHelpers.js.map +1 -1
- package/dist/esm/core/autoLockRenewer.js +9 -5
- package/dist/esm/core/autoLockRenewer.js.map +1 -1
- package/dist/esm/core/batchingReceiver.js +26 -18
- package/dist/esm/core/batchingReceiver.js.map +1 -1
- package/dist/esm/core/linkEntity.js +74 -13
- package/dist/esm/core/linkEntity.js.map +1 -1
- package/dist/esm/core/managementClient.js +48 -48
- package/dist/esm/core/managementClient.js.map +1 -1
- package/dist/esm/core/messageReceiver.js +41 -14
- package/dist/esm/core/messageReceiver.js.map +1 -1
- package/dist/esm/core/messageSender.js +33 -10
- package/dist/esm/core/messageSender.js.map +1 -1
- package/dist/esm/core/receiverHelper.js +3 -2
- package/dist/esm/core/receiverHelper.js.map +1 -1
- package/dist/esm/core/shared.js +11 -4
- package/dist/esm/core/shared.js.map +1 -1
- package/dist/esm/core/streamingReceiver.js +74 -43
- package/dist/esm/core/streamingReceiver.js.map +1 -1
- package/dist/esm/diagnostics/instrumentServiceBusMessage.js +16 -8
- package/dist/esm/diagnostics/instrumentServiceBusMessage.js.map +1 -1
- package/dist/esm/receivers/receiver.js +68 -23
- package/dist/esm/receivers/receiver.js.map +1 -1
- package/dist/esm/receivers/receiverCommon.js +36 -21
- package/dist/esm/receivers/receiverCommon.js.map +1 -1
- package/dist/esm/receivers/sessionReceiver.js +69 -29
- package/dist/esm/receivers/sessionReceiver.js.map +1 -1
- package/dist/esm/sender.js +33 -11
- package/dist/esm/sender.js.map +1 -1
- package/dist/esm/serializers/queueResourceSerializer.js +9 -1
- package/dist/esm/serializers/queueResourceSerializer.js.map +1 -1
- package/dist/esm/serializers/ruleResourceSerializer.js +1 -2
- package/dist/esm/serializers/ruleResourceSerializer.js.map +1 -1
- package/dist/esm/serviceBusAtomManagementClient.js +181 -228
- package/dist/esm/serviceBusAtomManagementClient.js.map +1 -1
- package/dist/esm/serviceBusClient.js +31 -22
- package/dist/esm/serviceBusClient.js.map +1 -1
- package/dist/esm/serviceBusError.js +21 -1
- package/dist/esm/serviceBusError.js.map +1 -1
- package/dist/esm/serviceBusMessage.js +208 -13
- package/dist/esm/serviceBusMessage.js.map +1 -1
- package/dist/esm/serviceBusMessageBatch.js +32 -8
- package/dist/esm/serviceBusMessageBatch.js.map +1 -1
- package/dist/esm/serviceBusRuleManager.js +39 -15
- package/dist/esm/serviceBusRuleManager.js.map +1 -1
- package/dist/esm/session/messageSession.js +130 -25
- package/dist/esm/session/messageSession.js.map +1 -1
- package/dist/esm/util/atomXmlHelper.js +4 -5
- package/dist/esm/util/atomXmlHelper.js.map +1 -1
- package/dist/esm/util/compat/httpHeaders.js +1 -0
- package/dist/esm/util/compat/httpHeaders.js.map +1 -1
- package/dist/esm/util/constants.js +1 -1
- package/dist/esm/util/constants.js.map +1 -1
- package/dist/esm/util/runtimeInfo.js +1 -1
- package/dist/esm/util/runtimeInfo.js.map +1 -1
- package/dist/esm/util/sasServiceClientCredentials.js +8 -0
- package/dist/esm/util/sasServiceClientCredentials.js.map +1 -1
- package/dist/esm/util/semaphore.js +6 -2
- package/dist/esm/util/semaphore.js.map +1 -1
- package/dist/esm/util/utils.js +5 -7
- package/dist/esm/util/utils.js.map +1 -1
- package/dist/react-native/connectionContext.js +1 -2
- package/dist/react-native/connectionContext.js.map +1 -1
- package/dist/react-native/constructorHelpers.js +3 -4
- package/dist/react-native/constructorHelpers.js.map +1 -1
- package/dist/react-native/core/autoLockRenewer.js +9 -5
- package/dist/react-native/core/autoLockRenewer.js.map +1 -1
- package/dist/react-native/core/batchingReceiver.js +26 -18
- package/dist/react-native/core/batchingReceiver.js.map +1 -1
- package/dist/react-native/core/linkEntity.js +74 -13
- package/dist/react-native/core/linkEntity.js.map +1 -1
- package/dist/react-native/core/managementClient.js +48 -48
- package/dist/react-native/core/managementClient.js.map +1 -1
- package/dist/react-native/core/messageReceiver.js +41 -14
- package/dist/react-native/core/messageReceiver.js.map +1 -1
- package/dist/react-native/core/messageSender.js +33 -10
- package/dist/react-native/core/messageSender.js.map +1 -1
- package/dist/react-native/core/receiverHelper.js +3 -2
- package/dist/react-native/core/receiverHelper.js.map +1 -1
- package/dist/react-native/core/shared.js +11 -4
- package/dist/react-native/core/shared.js.map +1 -1
- package/dist/react-native/core/streamingReceiver.js +74 -43
- package/dist/react-native/core/streamingReceiver.js.map +1 -1
- package/dist/react-native/diagnostics/instrumentServiceBusMessage.js +16 -8
- package/dist/react-native/diagnostics/instrumentServiceBusMessage.js.map +1 -1
- package/dist/react-native/receivers/receiver.js +68 -23
- package/dist/react-native/receivers/receiver.js.map +1 -1
- package/dist/react-native/receivers/receiverCommon.js +36 -21
- package/dist/react-native/receivers/receiverCommon.js.map +1 -1
- package/dist/react-native/receivers/sessionReceiver.js +69 -29
- package/dist/react-native/receivers/sessionReceiver.js.map +1 -1
- package/dist/react-native/sender.js +33 -11
- package/dist/react-native/sender.js.map +1 -1
- package/dist/react-native/serializers/queueResourceSerializer.js +9 -1
- package/dist/react-native/serializers/queueResourceSerializer.js.map +1 -1
- package/dist/react-native/serializers/ruleResourceSerializer.js +1 -2
- package/dist/react-native/serializers/ruleResourceSerializer.js.map +1 -1
- package/dist/react-native/serviceBusAtomManagementClient.js +181 -228
- package/dist/react-native/serviceBusAtomManagementClient.js.map +1 -1
- package/dist/react-native/serviceBusClient.js +31 -22
- package/dist/react-native/serviceBusClient.js.map +1 -1
- package/dist/react-native/serviceBusError.js +21 -1
- package/dist/react-native/serviceBusError.js.map +1 -1
- package/dist/react-native/serviceBusMessage.js +208 -13
- package/dist/react-native/serviceBusMessage.js.map +1 -1
- package/dist/react-native/serviceBusMessageBatch.js +32 -8
- package/dist/react-native/serviceBusMessageBatch.js.map +1 -1
- package/dist/react-native/serviceBusRuleManager.js +39 -15
- package/dist/react-native/serviceBusRuleManager.js.map +1 -1
- package/dist/react-native/session/messageSession.js +130 -25
- package/dist/react-native/session/messageSession.js.map +1 -1
- package/dist/react-native/util/atomXmlHelper.js +4 -5
- package/dist/react-native/util/atomXmlHelper.js.map +1 -1
- package/dist/react-native/util/compat/httpHeaders.js +1 -0
- package/dist/react-native/util/compat/httpHeaders.js.map +1 -1
- package/dist/react-native/util/constants.js +1 -1
- package/dist/react-native/util/constants.js.map +1 -1
- package/dist/react-native/util/sasServiceClientCredentials.js +8 -0
- package/dist/react-native/util/sasServiceClientCredentials.js.map +1 -1
- package/dist/react-native/util/semaphore.js +6 -2
- package/dist/react-native/util/semaphore.js.map +1 -1
- package/dist/react-native/util/utils.js +5 -7
- package/dist/react-native/util/utils.js.map +1 -1
- package/package.json +38 -38
|
@@ -29,6 +29,26 @@ export const MaxDeleteMessageCount = 500;
|
|
|
29
29
|
* @internal
|
|
30
30
|
*/
|
|
31
31
|
export class ServiceBusReceiverImpl {
|
|
32
|
+
_context;
|
|
33
|
+
entityPath;
|
|
34
|
+
receiveMode;
|
|
35
|
+
skipParsingBodyAsJson;
|
|
36
|
+
skipConvertingDate;
|
|
37
|
+
identifier;
|
|
38
|
+
_retryOptions;
|
|
39
|
+
/**
|
|
40
|
+
* Denotes if close() was called on this receiver
|
|
41
|
+
*/
|
|
42
|
+
_isClosed = false;
|
|
43
|
+
/**
|
|
44
|
+
* Instance of the BatchingReceiver class to use to receive messages in pull mode.
|
|
45
|
+
*/
|
|
46
|
+
_batchingReceiver;
|
|
47
|
+
/**
|
|
48
|
+
* Instance of the StreamingReceiver class to use to receive messages in push mode.
|
|
49
|
+
*/
|
|
50
|
+
_streamingReceiver;
|
|
51
|
+
_lockRenewer;
|
|
32
52
|
get logPrefix() {
|
|
33
53
|
return `[${this._context.connectionId}|receiver:${this.entityPath}]`;
|
|
34
54
|
}
|
|
@@ -41,10 +61,6 @@ export class ServiceBusReceiverImpl {
|
|
|
41
61
|
this.receiveMode = receiveMode;
|
|
42
62
|
this.skipParsingBodyAsJson = skipParsingBodyAsJson;
|
|
43
63
|
this.skipConvertingDate = skipConvertingDate;
|
|
44
|
-
/**
|
|
45
|
-
* Denotes if close() was called on this receiver
|
|
46
|
-
*/
|
|
47
|
-
this._isClosed = false;
|
|
48
64
|
throwErrorIfConnectionClosed(_context);
|
|
49
65
|
this._retryOptions = retryOptions;
|
|
50
66
|
this._lockRenewer = LockRenewer.create(this._context, maxAutoRenewLockDurationInMs, receiveMode);
|
|
@@ -79,7 +95,6 @@ export class ServiceBusReceiverImpl {
|
|
|
79
95
|
throw new TypeError(InvalidMaxMessageCountError);
|
|
80
96
|
}
|
|
81
97
|
const receiveMessages = async () => {
|
|
82
|
-
var _a;
|
|
83
98
|
if (!this._batchingReceiver || !this._context.messageReceivers[this._batchingReceiver.name]) {
|
|
84
99
|
const receiveOptions = {
|
|
85
100
|
maxConcurrentCalls: 0,
|
|
@@ -90,7 +105,7 @@ export class ServiceBusReceiverImpl {
|
|
|
90
105
|
};
|
|
91
106
|
this._batchingReceiver = this._createBatchingReceiver(this._context, this.entityPath, receiveOptions);
|
|
92
107
|
}
|
|
93
|
-
const receivedMessages = await this._batchingReceiver.receive(maxMessageCount,
|
|
108
|
+
const receivedMessages = await this._batchingReceiver.receive(maxMessageCount, options?.maxWaitTimeInMs ?? Constants.defaultOperationTimeoutInMs, defaultMaxTimeAfterFirstMessageForBatchingMs, options ?? {});
|
|
94
109
|
return receivedMessages;
|
|
95
110
|
};
|
|
96
111
|
const config = {
|
|
@@ -98,7 +113,7 @@ export class ServiceBusReceiverImpl {
|
|
|
98
113
|
connectionId: this._context.connectionId,
|
|
99
114
|
operation: receiveMessages,
|
|
100
115
|
operationType: RetryOperationType.receiveMessage,
|
|
101
|
-
abortSignal: options
|
|
116
|
+
abortSignal: options?.abortSignal,
|
|
102
117
|
retryOptions: this._retryOptions,
|
|
103
118
|
};
|
|
104
119
|
return retry(config).catch((err) => {
|
|
@@ -118,7 +133,14 @@ export class ServiceBusReceiverImpl {
|
|
|
118
133
|
const receiveDeferredMessagesOperationPromise = async () => {
|
|
119
134
|
const deferredMessages = await this._context
|
|
120
135
|
.getManagementClient(this.entityPath)
|
|
121
|
-
.receiveDeferredMessages(deferredSequenceNumbers, this.receiveMode, undefined,
|
|
136
|
+
.receiveDeferredMessages(deferredSequenceNumbers, this.receiveMode, undefined, {
|
|
137
|
+
...options,
|
|
138
|
+
associatedLinkName: this._getAssociatedReceiverName(),
|
|
139
|
+
requestName: "receiveDeferredMessages",
|
|
140
|
+
timeoutInMs: this._retryOptions.timeoutInMs,
|
|
141
|
+
skipParsingBodyAsJson: this.skipParsingBodyAsJson,
|
|
142
|
+
skipConvertingDate: this.skipConvertingDate,
|
|
143
|
+
});
|
|
122
144
|
return deferredMessages;
|
|
123
145
|
};
|
|
124
146
|
const config = {
|
|
@@ -126,7 +148,7 @@ export class ServiceBusReceiverImpl {
|
|
|
126
148
|
connectionId: this._context.connectionId,
|
|
127
149
|
operationType: RetryOperationType.management,
|
|
128
150
|
retryOptions: this._retryOptions,
|
|
129
|
-
abortSignal: options
|
|
151
|
+
abortSignal: options?.abortSignal,
|
|
130
152
|
};
|
|
131
153
|
return retry(config);
|
|
132
154
|
}
|
|
@@ -135,21 +157,26 @@ export class ServiceBusReceiverImpl {
|
|
|
135
157
|
const deleteMessagesOperationPromise = () => {
|
|
136
158
|
return this._context
|
|
137
159
|
.getManagementClient(this.entityPath)
|
|
138
|
-
.deleteMessages(options.maxMessageCount, options
|
|
160
|
+
.deleteMessages(options.maxMessageCount, options?.beforeEnqueueTime, undefined, {
|
|
161
|
+
...options,
|
|
162
|
+
associatedLinkName: this._getAssociatedReceiverName(),
|
|
163
|
+
requestName: "deleteMessages",
|
|
164
|
+
timeoutInMs: this._retryOptions.timeoutInMs,
|
|
165
|
+
});
|
|
139
166
|
};
|
|
140
167
|
const config = {
|
|
141
168
|
operation: deleteMessagesOperationPromise,
|
|
142
169
|
connectionId: this._context.connectionId,
|
|
143
170
|
operationType: RetryOperationType.management,
|
|
144
171
|
retryOptions: this._retryOptions,
|
|
145
|
-
abortSignal: options
|
|
172
|
+
abortSignal: options?.abortSignal,
|
|
146
173
|
};
|
|
147
174
|
return retry(config);
|
|
148
175
|
}
|
|
149
176
|
async purgeMessages(options) {
|
|
150
177
|
let deletedCount = await this.deleteMessages({
|
|
151
178
|
maxMessageCount: MaxDeleteMessageCount,
|
|
152
|
-
beforeEnqueueTime: options
|
|
179
|
+
beforeEnqueueTime: options?.beforeEnqueueTime,
|
|
153
180
|
});
|
|
154
181
|
logger.verbose(`${this.logPrefix} receiver '${this.identifier}' deleted ${deletedCount} messages.`);
|
|
155
182
|
if (deletedCount === MaxDeleteMessageCount) {
|
|
@@ -157,7 +184,7 @@ export class ServiceBusReceiverImpl {
|
|
|
157
184
|
while (batchCount === MaxDeleteMessageCount) {
|
|
158
185
|
batchCount = await this.deleteMessages({
|
|
159
186
|
maxMessageCount: MaxDeleteMessageCount,
|
|
160
|
-
beforeEnqueueTime: options
|
|
187
|
+
beforeEnqueueTime: options?.beforeEnqueueTime,
|
|
161
188
|
});
|
|
162
189
|
logger.verbose(`${this.logPrefix} receiver '${this.identifier}' deleted ${batchCount} messages.`);
|
|
163
190
|
deletedCount += batchCount;
|
|
@@ -168,9 +195,15 @@ export class ServiceBusReceiverImpl {
|
|
|
168
195
|
}
|
|
169
196
|
// ManagementClient methods # Begin
|
|
170
197
|
async peekMessages(maxMessageCount, options = {}) {
|
|
171
|
-
var _a;
|
|
172
198
|
this._throwIfReceiverOrConnectionClosed();
|
|
173
|
-
const managementRequestOptions =
|
|
199
|
+
const managementRequestOptions = {
|
|
200
|
+
...options,
|
|
201
|
+
associatedLinkName: this._getAssociatedReceiverName(),
|
|
202
|
+
requestName: "peekMessages",
|
|
203
|
+
timeoutInMs: this._retryOptions?.timeoutInMs,
|
|
204
|
+
skipParsingBodyAsJson: this.skipParsingBodyAsJson,
|
|
205
|
+
skipConvertingDate: this.skipConvertingDate,
|
|
206
|
+
};
|
|
174
207
|
// omitMessageBody is available at runtime, but only exported in experimental subpath
|
|
175
208
|
const { fromSequenceNumber, omitMessageBody } = options;
|
|
176
209
|
const peekOperationPromise = async () => {
|
|
@@ -190,17 +223,19 @@ export class ServiceBusReceiverImpl {
|
|
|
190
223
|
connectionId: this._context.connectionId,
|
|
191
224
|
operationType: RetryOperationType.management,
|
|
192
225
|
retryOptions: this._retryOptions,
|
|
193
|
-
abortSignal: options
|
|
226
|
+
abortSignal: options?.abortSignal,
|
|
194
227
|
};
|
|
195
228
|
return retry(config);
|
|
196
229
|
}
|
|
197
230
|
subscribe(handlers, options) {
|
|
198
|
-
var _a, _b;
|
|
199
231
|
assertValidMessageHandlers(handlers);
|
|
200
232
|
throwErrorIfConnectionClosed(this._context);
|
|
201
233
|
this._throwIfReceiverOrConnectionClosed();
|
|
202
234
|
this._throwIfAlreadyReceiving();
|
|
203
|
-
options =
|
|
235
|
+
options = {
|
|
236
|
+
...(options ?? {}),
|
|
237
|
+
autoCompleteMessages: options?.autoCompleteMessages ?? true,
|
|
238
|
+
};
|
|
204
239
|
// When the user "stops" a streaming receiver (via the returned instance from 'subscribe' we just suspend
|
|
205
240
|
// it, leaving the link open). This allows users to stop the flow of messages but still be able to settle messages
|
|
206
241
|
// since the link itself hasn't been shut down.
|
|
@@ -211,7 +246,15 @@ export class ServiceBusReceiverImpl {
|
|
|
211
246
|
// 2. subscription.stop()
|
|
212
247
|
// 3. receiver.subscribe()
|
|
213
248
|
this._streamingReceiver =
|
|
214
|
-
|
|
249
|
+
this._streamingReceiver ??
|
|
250
|
+
new StreamingReceiver(this.identifier, this._context, this.entityPath, {
|
|
251
|
+
...options,
|
|
252
|
+
receiveMode: this.receiveMode,
|
|
253
|
+
retryOptions: this._retryOptions,
|
|
254
|
+
lockRenewer: this._lockRenewer,
|
|
255
|
+
skipParsingBodyAsJson: this.skipParsingBodyAsJson,
|
|
256
|
+
skipConvertingDate: this.skipConvertingDate,
|
|
257
|
+
});
|
|
215
258
|
// this ensures that if the outer service bus client is closed that this receiver is cleaned up.
|
|
216
259
|
// this mostly affects us if we're in the middle of init() - the connection (and receiver) are not yet
|
|
217
260
|
// open but we do need to close the receiver to exit the init() loop.
|
|
@@ -224,8 +267,7 @@ export class ServiceBusReceiverImpl {
|
|
|
224
267
|
});
|
|
225
268
|
return {
|
|
226
269
|
close: async () => {
|
|
227
|
-
|
|
228
|
-
return (_a = this._streamingReceiver) === null || _a === void 0 ? void 0 : _a.stopReceivingMessages();
|
|
270
|
+
return this._streamingReceiver?.stopReceivingMessages();
|
|
229
271
|
},
|
|
230
272
|
};
|
|
231
273
|
}
|
|
@@ -263,7 +305,7 @@ export class ServiceBusReceiverImpl {
|
|
|
263
305
|
let associatedLinkName;
|
|
264
306
|
if (msgImpl.delivery.link) {
|
|
265
307
|
const associatedReceiver = this._context.getReceiverFromCache(msgImpl.delivery.link.name);
|
|
266
|
-
associatedLinkName = associatedReceiver
|
|
308
|
+
associatedLinkName = associatedReceiver?.name;
|
|
267
309
|
}
|
|
268
310
|
return this._context
|
|
269
311
|
.getManagementClient(this.entityPath)
|
|
@@ -272,7 +314,10 @@ export class ServiceBusReceiverImpl {
|
|
|
272
314
|
message.lockedUntilUtc = lockedUntil;
|
|
273
315
|
return lockedUntil;
|
|
274
316
|
});
|
|
275
|
-
},
|
|
317
|
+
}, {
|
|
318
|
+
spanLinks,
|
|
319
|
+
...toSpanOptions({ entityPath: this.entityPath, host: this._context.config.host }, "receive", "client"),
|
|
320
|
+
});
|
|
276
321
|
}
|
|
277
322
|
async close() {
|
|
278
323
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"receiver.js","sourceRoot":"","sources":["../../../src/receivers/receiver.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAclC,OAAO,EACL,2BAA2B,EAC3B,yBAAyB,EACzB,2BAA2B,EAC3B,4BAA4B,EAC5B,gCAAgC,EAChC,gCAAgC,EAChC,qCAAqC,EACrC,qCAAqC,GACtC,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EACL,cAAc,EACd,0BAA0B,EAC1B,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAI7B,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,cAAc,IAAI,MAAM,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,EAAE,uCAAuC,EAAE,MAAM,+CAA+C,CAAC;AAGxG;;;;;;;GAOG;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C,iBAAiB,CAAC,IAAI,CAAC;QACrC,CAAC;QACD,OAAO;IACT,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n PeekMessagesOptions,\n GetMessageIteratorOptions,\n MessageHandlers,\n ReceiveMessagesOptions,\n SubscribeOptions,\n DeleteMessagesOptions,\n PurgeMessagesOptions,\n} from \"../models.js\";\nimport type { OperationOptionsBase } from \"../modelsToBeSharedWithEventHubs.js\";\nimport type { ServiceBusReceivedMessage } from \"../serviceBusMessage.js\";\nimport type { ConnectionContext } from \"../connectionContext.js\";\nimport {\n getAlreadyReceivingErrorMsg,\n getReceiverClosedErrorMsg,\n InvalidMaxMessageCountError,\n throwErrorIfConnectionClosed,\n throwTypeErrorIfParameterMissing,\n throwTypeErrorIfParameterNotLong,\n throwErrorIfInvalidOperationOnMessage,\n throwTypeErrorIfParameterTypeMismatch,\n} from \"../util/errors.js\";\nimport type { ReceiveOptions } from \"../core/messageReceiver.js\";\nimport { StreamingReceiver } from \"../core/streamingReceiver.js\";\nimport { BatchingReceiver } from \"../core/batchingReceiver.js\";\nimport {\n abandonMessage,\n assertValidMessageHandlers,\n completeMessage,\n deadLetterMessage,\n deferMessage,\n getMessageIterator,\n} from \"./receiverCommon.js\";\nimport type Long from \"long\";\nimport type { ServiceBusMessageImpl, DeadLetterOptions } from \"../serviceBusMessage.js\";\nimport type { RetryConfig, RetryOptions } from \"@azure/core-amqp\";\nimport { Constants, RetryOperationType, retry } from \"@azure/core-amqp\";\nimport { LockRenewer } from \"../core/autoLockRenewer.js\";\nimport { receiverLogger as logger } from \"../log.js\";\nimport { translateServiceBusError } from \"../serviceBusError.js\";\nimport { ensureValidIdentifier } from \"../util/utils.js\";\nimport { toSpanOptions, tracingClient } from \"../diagnostics/tracing.js\";\nimport { extractSpanContextFromServiceBusMessage } from \"../diagnostics/instrumentServiceBusMessage.js\";\nimport type { TracingSpanLink } from \"@azure/core-tracing\";\n\n/**\n * The default time to wait for messages _after_ the first message\n * has been received.\n *\n * This timeout only applies to receiveMessages()\n *\n * @internal\n */\nexport const defaultMaxTimeAfterFirstMessageForBatchingMs = 1000;\n\n/**\n * The maximum number of messages to delete in a single batch. This cap is established and enforced by the service.\n * @internal\n */\nexport const MaxDeleteMessageCount = 500;\n\n/**\n * A receiver that does not handle sessions.\n */\nexport interface ServiceBusReceiver {\n /**\n * A name used to identify the receiver. This can be used to correlate logs and exceptions.\n * If not specified or empty, a random unique one will be generated.\n */\n identifier: string;\n\n /**\n * Streams messages to message handlers.\n * @param handlers - A handler that gets called for messages and errors.\n * @param options - Options for subscribe.\n * @returns An object that can be closed, sending any remaining messages to `handlers` and\n * stopping new messages from arriving.\n */\n subscribe(\n handlers: MessageHandlers,\n options?: SubscribeOptions,\n ): {\n /**\n * Causes the subscriber to stop receiving new messages.\n */\n close(): Promise<void>;\n };\n\n /**\n * Returns an iterator that can be used to receive messages from Service Bus.\n *\n * @param options - A set of options to control the receive operation.\n * - `abortSignal`: The signal to use to abort the ongoing operation.\n *\n * @throws Error if the underlying connection, client or receiver is closed.\n * @throws Error if current receiver is already in state of receiving messages.\n * @throws `ServiceBusError` if the service returns an error while receiving messages.\n */\n getMessageIterator(\n options?: GetMessageIteratorOptions,\n ): AsyncIterableIterator<ServiceBusReceivedMessage>;\n\n /**\n * Returns a promise that resolves to an array of messages received from Service Bus.\n *\n * @param maxMessageCount - The maximum number of messages to receive.\n * @param options - A set of options to control the receive operation.\n * - `maxWaitTimeInMs`: The maximum time to wait for the first message before returning an empty array if no messages are available.\n * - `abortSignal`: The signal to use to abort the ongoing operation.\n * @returns A promise that resolves with an array of messages.\n * @throws Error if the underlying connection, client or receiver is closed.\n * @throws Error if current receiver is already in state of receiving messages.\n * @throws `ServiceBusError` if the service returns an error while receiving messages.\n */\n receiveMessages(\n maxMessageCount: number,\n options?: ReceiveMessagesOptions,\n ): Promise<ServiceBusReceivedMessage[]>;\n\n /**\n * Returns a promise that resolves to an array of deferred messages identified by given `sequenceNumbers`.\n * @param sequenceNumbers - The sequence number or an array of sequence numbers for the messages that need to be received.\n * @param options - Options bag to pass an abort signal or tracing options.\n * @returns A list of messages identified by the given sequenceNumbers or an empty list if no messages are found.\n * @throws Error if the underlying connection or receiver is closed.\n * @throws `ServiceBusError` if the service returns an error while receiving deferred messages.\n */\n receiveDeferredMessages(\n sequenceNumbers: Long | Long[],\n options?: OperationOptionsBase,\n ): Promise<ServiceBusReceivedMessage[]>;\n\n /**\n * Peek the next batch of active messages (including deferred but not deadlettered messages) on the\n * queue or subscription without modifying them.\n * - The first call to `peekMessages()` fetches the first active message. Each subsequent call fetches the\n * subsequent message.\n * - Unlike a \"received\" message, \"peeked\" message is a read-only version of the message.\n * It cannot be `Completed/Abandoned/Deferred/Deadlettered`.\n * @param maxMessageCount - The maximum number of messages to peek.\n * @param options - Options that allow to specify the maximum number of messages to peek,\n * the sequenceNumber to start peeking from or an abortSignal to abort the operation.\n */\n peekMessages(\n maxMessageCount: number,\n options?: PeekMessagesOptions,\n ): Promise<ServiceBusReceivedMessage[]>;\n\n /**\n * Delete messages. If no option is specified, all messages will be deleted.\n *\n * @param options - Options to configure the operation.\n * @returns number of messages that have been deleted.\n */\n deleteMessages(options: DeleteMessagesOptions): Promise<number>;\n\n /**\n * Attempts to purge all messages from an entity. Locked messages are not eligible for removal and\n * will remain in the entity.\n *\n * @param options - Options that allow to specify the cutoff time for deletion. Only messages that were enqueued\n * before this time will be deleted. If not specified, current time will be used.\n * @returns number of messages deleted.\n */\n purgeMessages(options?: PurgeMessagesOptions): Promise<number>;\n\n /**\n * Path of the entity for which the receiver has been created.\n */\n entityPath: string;\n /**\n * The receive mode used to create the receiver.\n */\n receiveMode: \"peekLock\" | \"receiveAndDelete\";\n /**\n * Returns `true` if either the receiver or the client that created it has been closed.\n * @readonly\n */\n isClosed: boolean;\n /**\n * Closes the receiver.\n * Once closed, the receiver cannot be used for any further operations.\n * Use the `createReceiver()` method on the ServiceBusClient to create a new Receiver.\n */\n close(): Promise<void>;\n /**\n * Removes the message from Service Bus.\n *\n * @throws Error with name `SessionLockLostError` (for messages from a Queue/Subscription with sessions enabled)\n * if the AMQP link with which the message was received is no longer alive. This can\n * happen either because the lock on the session expired or the receiver was explicitly closed by\n * the user or the AMQP link is closed by the library due to network loss or service error.\n * @throws Error with name `MessageLockLostError` (for messages from a Queue/Subscription with sessions not enabled)\n * if the lock on the message has expired or the AMQP link with which the message was received is\n * no longer alive. The latter can happen if the receiver was explicitly closed by the user or the\n * AMQP link got closed by the library due to network loss or service error.\n * @throws Error if the message is already settled.\n * property on the message if you are not sure whether the message is settled.\n * @throws Error if used in `receiveAndDelete` mode because all messages received in this mode\n * are pre-settled. To avoid this error, update your code to not settle a message which is received\n * in this mode.\n * @throws Error with name `ServiceUnavailableError` if Service Bus does not acknowledge the request to settle\n * the message in time. The message may or may not have been settled successfully.\n */\n completeMessage(message: ServiceBusReceivedMessage): Promise<void>;\n /**\n * The lock held on the message by the receiver is let go, making the message available again in\n * Service Bus for another receive operation.\n *\n * @throws `ServiceBusError` with the code `SessionLockLost` (for messages from a Queue/Subscription with sessions enabled)\n * if the AMQP link with which the message was received is no longer alive. This can\n * happen either because the lock on the session expired or the receiver was explicitly closed by\n * the user or the AMQP link is closed by the library due to network loss or service error.\n * @throws `ServiceBusError` with the code `MessageLockLost` (for messages from a Queue/Subscription with sessions not enabled)\n * if the lock on the message has expired or the AMQP link with which the message was received is\n * no longer alive. The latter can happen if the receiver was explicitly closed by the user or the\n * AMQP link got closed by the library due to network loss or service error.\n * @throws Error if the message is already settled.\n * property on the message if you are not sure whether the message is settled.\n * @throws Error if used in `receiveAndDelete` mode because all messages received in this mode\n * are pre-settled. To avoid this error, update your code to not settle a message which is received\n * in this mode.\n * @throws `ServiceBusError` with the code `ServiceTimeout` if Service Bus does not acknowledge the request to settle\n * the message in time. The message may or may not have been settled successfully.\n *\n * @param propertiesToModify - The properties of the message to modify while abandoning the message.\n */\n abandonMessage(\n message: ServiceBusReceivedMessage,\n propertiesToModify?: { [key: string]: number | boolean | string | Date | null },\n ): Promise<void>;\n /**\n * Defers the processing of the message. Save the `sequenceNumber` of the message, in order to\n * receive it message again in the future using the `receiveDeferredMessage` method.\n *\n * @throws `ServiceBusError` with the code `SessionLockLost` (for messages from a Queue/Subscription with sessions enabled)\n * if the AMQP link with which the message was received is no longer alive. This can\n * happen either because the lock on the session expired or the receiver was explicitly closed by\n * the user or the AMQP link is closed by the library due to network loss or service error.\n * @throws `ServiceBusError` with the code `MessageLockLost` (for messages from a Queue/Subscription with sessions not enabled)\n * if the lock on the message has expired or the AMQP link with which the message was received is\n * no longer alive. The latter can happen if the receiver was explicitly closed by the user or the\n * AMQP link got closed by the library due to network loss or service error.\n * @throws Error if the message is already settled.\n * property on the message if you are not sure whether the message is settled.\n * @throws Error if used in `receiveAndDelete` mode because all messages received in this mode\n * are pre-settled. To avoid this error, update your code to not settle a message which is received\n * in this mode.\n * @throws `ServiceBusError` with the code `ServiceTimeout` if Service Bus does not acknowledge the request to settle\n * the message in time. The message may or may not have been settled successfully.\n *\n * @param propertiesToModify - The properties of the message to modify while deferring the message\n */\n deferMessage(\n message: ServiceBusReceivedMessage,\n propertiesToModify?: { [key: string]: number | boolean | string | Date | null },\n ): Promise<void>;\n /**\n * Moves the message to the deadletter sub-queue. To receive a deadletted message, create a new\n * QueueClient/SubscriptionClient using the path for the deadletter sub-queue.\n *\n * @throws `ServiceBusError` with the code `SessionLockLost` (for messages from a Queue/Subscription with sessions enabled)\n * if the AMQP link with which the message was received is no longer alive. This can\n * happen either because the lock on the session expired or the receiver was explicitly closed by\n * the user or the AMQP link is closed by the library due to network loss or service error.\n * @throws `ServiceBusError` with the code `MessageLockLost` (for messages from a Queue/Subscription with sessions not enabled)\n * if the lock on the message has expired or the AMQP link with which the message was received is\n * no longer alive. The latter can happen if the receiver was explicitly closed by the user or the\n * AMQP link got closed by the library due to network loss or service error.\n * @throws Error if the message is already settled.\n * property on the message if you are not sure whether the message is settled.\n * @throws Error if used in `receiveAndDelete` mode because all messages received in this mode\n * are pre-settled. To avoid this error, update your code to not settle a message which is received\n * in this mode.\n * @throws `ServiceBusError` with the code `ServiceTimeout` if Service Bus does not acknowledge the request to settle\n * the message in time. The message may or may not have been settled successfully.\n *\n * @param options - The DeadLetter options that can be provided while\n * rejecting the message.\n */\n deadLetterMessage(\n message: ServiceBusReceivedMessage,\n options?: DeadLetterOptions & { [key: string]: number | boolean | string | Date | null },\n ): Promise<void>;\n /**\n * Renews the lock on the message for the duration as specified during the Queue/Subscription\n * creation.\n * - Check the `lockedUntilUtc` property on the message for the time when the lock expires.\n * - If a message is not settled (using either `complete()`, `defer()` or `deadletter()`,\n * before its lock expires, then the message lands back in the Queue/Subscription for the next\n * receive operation.\n *\n * @returns New lock token expiry date and time in UTC format.\n * @throws Error if the underlying connection, client or receiver is closed.\n * @throws ServiceBusError if the service returns an error while renewing message lock.\n */\n renewMessageLock(message: ServiceBusReceivedMessage): Promise<Date>;\n}\n\n/**\n * @internal\n */\nexport class ServiceBusReceiverImpl implements ServiceBusReceiver {\n public identifier: string;\n private _retryOptions: RetryOptions;\n /**\n * Denotes if close() was called on this receiver\n */\n private _isClosed: boolean = false;\n\n /**\n * Instance of the BatchingReceiver class to use to receive messages in pull mode.\n */\n private _batchingReceiver?: BatchingReceiver;\n\n /**\n * Instance of the StreamingReceiver class to use to receive messages in push mode.\n */\n private _streamingReceiver?: StreamingReceiver;\n private _lockRenewer: LockRenewer | undefined;\n\n private get logPrefix(): string {\n return `[${this._context.connectionId}|receiver:${this.entityPath}]`;\n }\n\n /**\n * @throws Error if the underlying connection is closed.\n */\n constructor(\n private _context: ConnectionContext,\n public entityPath: string,\n public receiveMode: \"peekLock\" | \"receiveAndDelete\",\n maxAutoRenewLockDurationInMs: number,\n private skipParsingBodyAsJson: boolean,\n private skipConvertingDate: boolean = false,\n retryOptions: RetryOptions = {},\n identifier?: string,\n ) {\n throwErrorIfConnectionClosed(_context);\n this._retryOptions = retryOptions;\n this._lockRenewer = LockRenewer.create(\n this._context,\n maxAutoRenewLockDurationInMs,\n receiveMode,\n );\n this.identifier = ensureValidIdentifier(this.entityPath, identifier);\n }\n\n private _throwIfAlreadyReceiving(): void {\n if (this._isReceivingMessages()) {\n const errorMessage = getAlreadyReceivingErrorMsg(this.entityPath);\n const error = new Error(errorMessage);\n logger.logError(error, `${this.logPrefix} is already receiving`);\n throw error;\n }\n }\n\n private _throwIfReceiverOrConnectionClosed(): void {\n throwErrorIfConnectionClosed(this._context);\n if (this.isClosed) {\n const errorMessage = getReceiverClosedErrorMsg(this.entityPath);\n const error = new Error(errorMessage);\n logger.logError(error, `${this.logPrefix} is closed`);\n throw error;\n }\n }\n\n public get isClosed(): boolean {\n return this._isClosed || this._context.wasConnectionCloseCalled;\n }\n\n async receiveMessages(\n maxMessageCount: number,\n options?: ReceiveMessagesOptions,\n ): Promise<ServiceBusReceivedMessage[]> {\n this._throwIfReceiverOrConnectionClosed();\n this._throwIfAlreadyReceiving();\n throwTypeErrorIfParameterMissing(\n this._context.connectionId,\n \"maxMessageCount\",\n maxMessageCount,\n );\n throwTypeErrorIfParameterTypeMismatch(\n this._context.connectionId,\n \"maxMessageCount\",\n maxMessageCount,\n \"number\",\n );\n\n if (isNaN(maxMessageCount) || maxMessageCount < 1) {\n throw new TypeError(InvalidMaxMessageCountError);\n }\n\n const receiveMessages = async (): Promise<ServiceBusReceivedMessage[]> => {\n if (!this._batchingReceiver || !this._context.messageReceivers[this._batchingReceiver.name]) {\n const receiveOptions: ReceiveOptions = {\n maxConcurrentCalls: 0,\n receiveMode: this.receiveMode,\n lockRenewer: this._lockRenewer,\n skipParsingBodyAsJson: this.skipParsingBodyAsJson,\n skipConvertingDate: this.skipConvertingDate,\n };\n this._batchingReceiver = this._createBatchingReceiver(\n this._context,\n this.entityPath,\n receiveOptions,\n );\n }\n\n const receivedMessages = await this._batchingReceiver.receive(\n maxMessageCount,\n options?.maxWaitTimeInMs ?? Constants.defaultOperationTimeoutInMs,\n defaultMaxTimeAfterFirstMessageForBatchingMs,\n options ?? {},\n );\n\n return receivedMessages;\n };\n const config: RetryConfig<ServiceBusReceivedMessage[]> = {\n connectionHost: this._context.config.host,\n connectionId: this._context.connectionId,\n operation: receiveMessages,\n operationType: RetryOperationType.receiveMessage,\n abortSignal: options?.abortSignal,\n retryOptions: this._retryOptions,\n };\n return retry<ServiceBusReceivedMessage[]>(config).catch((err) => {\n throw translateServiceBusError(err);\n });\n }\n\n getMessageIterator(\n options?: GetMessageIteratorOptions,\n ): AsyncIterableIterator<ServiceBusReceivedMessage> {\n return getMessageIterator(this, options);\n }\n\n async receiveDeferredMessages(\n sequenceNumbers: Long | Long[],\n options: OperationOptionsBase = {},\n ): Promise<ServiceBusReceivedMessage[]> {\n this._throwIfReceiverOrConnectionClosed();\n throwTypeErrorIfParameterMissing(\n this._context.connectionId,\n \"sequenceNumbers\",\n sequenceNumbers,\n );\n throwTypeErrorIfParameterNotLong(\n this._context.connectionId,\n \"sequenceNumbers\",\n sequenceNumbers,\n );\n\n const deferredSequenceNumbers = Array.isArray(sequenceNumbers)\n ? sequenceNumbers\n : [sequenceNumbers];\n const receiveDeferredMessagesOperationPromise = async (): Promise<\n ServiceBusReceivedMessage[]\n > => {\n const deferredMessages = await this._context\n .getManagementClient(this.entityPath)\n .receiveDeferredMessages(deferredSequenceNumbers, this.receiveMode, undefined, {\n ...options,\n associatedLinkName: this._getAssociatedReceiverName(),\n requestName: \"receiveDeferredMessages\",\n timeoutInMs: this._retryOptions.timeoutInMs,\n skipParsingBodyAsJson: this.skipParsingBodyAsJson,\n skipConvertingDate: this.skipConvertingDate,\n });\n return deferredMessages;\n };\n const config: RetryConfig<ServiceBusReceivedMessage[]> = {\n operation: receiveDeferredMessagesOperationPromise,\n connectionId: this._context.connectionId,\n operationType: RetryOperationType.management,\n retryOptions: this._retryOptions,\n abortSignal: options?.abortSignal,\n };\n return retry<ServiceBusReceivedMessage[]>(config);\n }\n\n async deleteMessages(options: DeleteMessagesOptions): Promise<number> {\n this._throwIfReceiverOrConnectionClosed();\n\n const deleteMessagesOperationPromise = (): Promise<number> => {\n return this._context\n .getManagementClient(this.entityPath)\n .deleteMessages(options.maxMessageCount, options?.beforeEnqueueTime, undefined, {\n ...options,\n associatedLinkName: this._getAssociatedReceiverName(),\n requestName: \"deleteMessages\",\n timeoutInMs: this._retryOptions.timeoutInMs,\n });\n };\n const config: RetryConfig<number> = {\n operation: deleteMessagesOperationPromise,\n connectionId: this._context.connectionId,\n operationType: RetryOperationType.management,\n retryOptions: this._retryOptions,\n abortSignal: options?.abortSignal,\n };\n return retry<number>(config);\n }\n\n async purgeMessages(options?: PurgeMessagesOptions): Promise<number> {\n let deletedCount = await this.deleteMessages({\n maxMessageCount: MaxDeleteMessageCount,\n beforeEnqueueTime: options?.beforeEnqueueTime,\n });\n logger.verbose(\n `${this.logPrefix} receiver '${this.identifier}' deleted ${deletedCount} messages.`,\n );\n if (deletedCount === MaxDeleteMessageCount) {\n let batchCount = MaxDeleteMessageCount;\n while (batchCount === MaxDeleteMessageCount) {\n batchCount = await this.deleteMessages({\n maxMessageCount: MaxDeleteMessageCount,\n beforeEnqueueTime: options?.beforeEnqueueTime,\n });\n logger.verbose(\n `${this.logPrefix} receiver '${this.identifier}' deleted ${batchCount} messages.`,\n );\n deletedCount += batchCount;\n }\n }\n logger.verbose(\n `${this.logPrefix} receiver '${this.identifier}' purged ${deletedCount} messages.`,\n );\n return deletedCount;\n }\n\n // ManagementClient methods # Begin\n\n async peekMessages(\n maxMessageCount: number,\n options: PeekMessagesOptions = {},\n ): Promise<ServiceBusReceivedMessage[]> {\n this._throwIfReceiverOrConnectionClosed();\n\n const managementRequestOptions = {\n ...options,\n associatedLinkName: this._getAssociatedReceiverName(),\n requestName: \"peekMessages\",\n timeoutInMs: this._retryOptions?.timeoutInMs,\n skipParsingBodyAsJson: this.skipParsingBodyAsJson,\n skipConvertingDate: this.skipConvertingDate,\n };\n // omitMessageBody is available at runtime, but only exported in experimental subpath\n const { fromSequenceNumber, omitMessageBody } = options as PeekMessagesOptions & {\n omitMessageBody: boolean;\n };\n const peekOperationPromise = async (): Promise<ServiceBusReceivedMessage[]> => {\n if (fromSequenceNumber !== undefined) {\n return this._context\n .getManagementClient(this.entityPath)\n .peekBySequenceNumber(\n fromSequenceNumber,\n maxMessageCount,\n undefined,\n omitMessageBody,\n managementRequestOptions,\n );\n } else {\n return this._context\n .getManagementClient(this.entityPath)\n .peek(maxMessageCount, omitMessageBody, managementRequestOptions);\n }\n };\n\n const config: RetryConfig<ServiceBusReceivedMessage[]> = {\n operation: peekOperationPromise,\n connectionId: this._context.connectionId,\n operationType: RetryOperationType.management,\n retryOptions: this._retryOptions,\n abortSignal: options?.abortSignal,\n };\n return retry<ServiceBusReceivedMessage[]>(config);\n }\n\n subscribe(\n handlers: MessageHandlers,\n options?: SubscribeOptions,\n ): {\n close(): Promise<void>;\n } {\n assertValidMessageHandlers(handlers);\n throwErrorIfConnectionClosed(this._context);\n this._throwIfReceiverOrConnectionClosed();\n this._throwIfAlreadyReceiving();\n\n options = {\n ...(options ?? {}),\n autoCompleteMessages: options?.autoCompleteMessages ?? true,\n };\n\n // When the user \"stops\" a streaming receiver (via the returned instance from 'subscribe' we just suspend\n // it, leaving the link open). This allows users to stop the flow of messages but still be able to settle messages\n // since the link itself hasn't been shut down.\n //\n // Users can, if they want, restart their subscription (since we've got a link already established).\n // So you'll have an instance here if the user has done:\n // 1. const subscription = receiver.subscribe()\n // 2. subscription.stop()\n // 3. receiver.subscribe()\n\n this._streamingReceiver =\n this._streamingReceiver ??\n new StreamingReceiver(this.identifier, this._context, this.entityPath, {\n ...options,\n receiveMode: this.receiveMode,\n retryOptions: this._retryOptions,\n lockRenewer: this._lockRenewer,\n skipParsingBodyAsJson: this.skipParsingBodyAsJson,\n skipConvertingDate: this.skipConvertingDate,\n });\n\n // this ensures that if the outer service bus client is closed that this receiver is cleaned up.\n // this mostly affects us if we're in the middle of init() - the connection (and receiver) are not yet\n // open but we do need to close the receiver to exit the init() loop.\n this._context.messageReceivers[this._streamingReceiver.name] = this._streamingReceiver;\n\n this._streamingReceiver.subscribe(handlers, options).catch((_) => {\n // (the error will already have been reported to the user)\n if (this._streamingReceiver) {\n delete this._context.messageReceivers[this._streamingReceiver.name];\n }\n });\n\n return {\n close: async (): Promise<void> => {\n return this._streamingReceiver?.stopReceivingMessages();\n },\n };\n }\n\n async completeMessage(message: ServiceBusReceivedMessage): Promise<void> {\n this._throwIfReceiverOrConnectionClosed();\n throwErrorIfInvalidOperationOnMessage(message, this.receiveMode, this._context.connectionId);\n const msgImpl = message as ServiceBusMessageImpl;\n return completeMessage(msgImpl, this._context, this.entityPath, this._retryOptions);\n }\n\n async abandonMessage(\n message: ServiceBusReceivedMessage,\n propertiesToModify?: { [key: string]: number | boolean | string | Date | null },\n ): Promise<void> {\n this._throwIfReceiverOrConnectionClosed();\n throwErrorIfInvalidOperationOnMessage(message, this.receiveMode, this._context.connectionId);\n const msgImpl = message as ServiceBusMessageImpl;\n return abandonMessage(\n msgImpl,\n this._context,\n this.entityPath,\n propertiesToModify,\n this._retryOptions,\n );\n }\n\n async deferMessage(\n message: ServiceBusReceivedMessage,\n propertiesToModify?: { [key: string]: number | boolean | string | Date | null },\n ): Promise<void> {\n this._throwIfReceiverOrConnectionClosed();\n throwErrorIfInvalidOperationOnMessage(message, this.receiveMode, this._context.connectionId);\n const msgImpl = message as ServiceBusMessageImpl;\n return deferMessage(\n msgImpl,\n this._context,\n this.entityPath,\n propertiesToModify,\n this._retryOptions,\n );\n }\n\n async deadLetterMessage(\n message: ServiceBusReceivedMessage,\n options?: DeadLetterOptions & { [key: string]: number | boolean | string | Date | null },\n ): Promise<void> {\n this._throwIfReceiverOrConnectionClosed();\n throwErrorIfInvalidOperationOnMessage(message, this.receiveMode, this._context.connectionId);\n const msgImpl = message as ServiceBusMessageImpl;\n return deadLetterMessage(msgImpl, this._context, this.entityPath, options, this._retryOptions);\n }\n\n async renewMessageLock(message: ServiceBusReceivedMessage): Promise<Date> {\n this._throwIfReceiverOrConnectionClosed();\n throwErrorIfInvalidOperationOnMessage(message, this.receiveMode, this._context.connectionId);\n\n const tracingContext = extractSpanContextFromServiceBusMessage(message);\n const spanLinks: TracingSpanLink[] = tracingContext ? [{ tracingContext }] : [];\n\n return tracingClient.withSpan(\n \"ServiceBusReceiver.renewMessageLock\",\n {},\n () => {\n const msgImpl = message as ServiceBusMessageImpl;\n\n let associatedLinkName: string | undefined;\n if (msgImpl.delivery.link) {\n const associatedReceiver = this._context.getReceiverFromCache(msgImpl.delivery.link.name);\n associatedLinkName = associatedReceiver?.name;\n }\n return this._context\n .getManagementClient(this.entityPath)\n .renewLock(message.lockToken!, { associatedLinkName })\n .then((lockedUntil) => {\n message.lockedUntilUtc = lockedUntil;\n return lockedUntil;\n });\n },\n {\n spanLinks,\n ...toSpanOptions(\n { entityPath: this.entityPath, host: this._context.config.host },\n \"receive\",\n \"client\",\n ),\n },\n );\n }\n\n async close(): Promise<void> {\n try {\n this._isClosed = true;\n if (this._context.connection && this._context.connection.isOpen()) {\n // Close the streaming receiver.\n if (this._streamingReceiver) {\n await this._streamingReceiver.close();\n }\n\n // Close the batching receiver.\n if (this._batchingReceiver) {\n await this._batchingReceiver.close();\n }\n }\n } catch (err: any) {\n logger.logError(err, `${this.logPrefix} An error occurred while closing the Receiver`);\n throw err;\n }\n }\n\n /**\n * Indicates whether the receiver is currently receiving messages or not.\n * When this returns true, new `registerMessageHandler()` or `receiveMessages()` calls cannot be made.\n */\n private _isReceivingMessages(): boolean {\n if (\n this._streamingReceiver &&\n this._streamingReceiver.isOpen() &&\n this._streamingReceiver.isSubscribeActive\n ) {\n return true;\n }\n if (\n this._batchingReceiver &&\n this._batchingReceiver.isOpen() &&\n this._batchingReceiver.isReceivingMessages\n ) {\n return true;\n }\n return false;\n }\n\n private _createBatchingReceiver(\n context: ConnectionContext,\n entityPath: string,\n options: ReceiveOptions,\n ): BatchingReceiver {\n const receiver = BatchingReceiver.create(this.identifier, context, entityPath, options);\n logger.verbose(\n `[${this.logPrefix}] receiver '${receiver.name}' created, with maxConcurrentCalls set to ${options.maxConcurrentCalls}.`,\n );\n\n return receiver;\n }\n\n /**\n * Helper function to retrieve any active receiver name, regardless of streaming or\n * batching if it exists. This is used for optimization on the service side\n */\n private _getAssociatedReceiverName(): string | undefined {\n if (this._streamingReceiver && this._streamingReceiver.isOpen()) {\n return this._streamingReceiver.name;\n }\n if (\n this._batchingReceiver &&\n this._batchingReceiver.isOpen() &&\n this._batchingReceiver.isReceivingMessages\n ) {\n return this._batchingReceiver.name;\n }\n return;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"receiver.js","sourceRoot":"","sources":["../../../src/receivers/receiver.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAclC,OAAO,EACL,2BAA2B,EAC3B,yBAAyB,EACzB,2BAA2B,EAC3B,4BAA4B,EAC5B,gCAAgC,EAChC,gCAAgC,EAChC,qCAAqC,EACrC,qCAAqC,GACtC,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EACL,cAAc,EACd,0BAA0B,EAC1B,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAI7B,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,cAAc,IAAI,MAAM,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AACzE,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CAAC;QACrC,CAAC;QACD,OAAO;IACT,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n PeekMessagesOptions,\n GetMessageIteratorOptions,\n MessageHandlers,\n ReceiveMessagesOptions,\n SubscribeOptions,\n DeleteMessagesOptions,\n PurgeMessagesOptions,\n} from \"../models.js\";\nimport type { OperationOptionsBase } from \"../modelsToBeSharedWithEventHubs.js\";\nimport type { ServiceBusReceivedMessage } from \"../serviceBusMessage.js\";\nimport type { ConnectionContext } from \"../connectionContext.js\";\nimport {\n getAlreadyReceivingErrorMsg,\n getReceiverClosedErrorMsg,\n InvalidMaxMessageCountError,\n throwErrorIfConnectionClosed,\n throwTypeErrorIfParameterMissing,\n throwTypeErrorIfParameterNotLong,\n throwErrorIfInvalidOperationOnMessage,\n throwTypeErrorIfParameterTypeMismatch,\n} from \"../util/errors.js\";\nimport type { ReceiveOptions } from \"../core/messageReceiver.js\";\nimport { StreamingReceiver } from \"../core/streamingReceiver.js\";\nimport { BatchingReceiver } from \"../core/batchingReceiver.js\";\nimport {\n abandonMessage,\n assertValidMessageHandlers,\n completeMessage,\n deadLetterMessage,\n deferMessage,\n getMessageIterator,\n} from \"./receiverCommon.js\";\nimport type Long from \"long\";\nimport type { ServiceBusMessageImpl, DeadLetterOptions } from \"../serviceBusMessage.js\";\nimport type { RetryConfig, RetryOptions } from \"@azure/core-amqp\";\nimport { Constants, RetryOperationType, retry } from \"@azure/core-amqp\";\nimport { LockRenewer } from \"../core/autoLockRenewer.js\";\nimport { receiverLogger as logger } from \"../log.js\";\nimport { translateServiceBusError } from \"../serviceBusError.js\";\nimport { ensureValidIdentifier } from \"../util/utils.js\";\nimport { toSpanOptions, tracingClient } from \"../diagnostics/tracing.js\";\nimport { extractSpanContextFromServiceBusMessage } from \"../diagnostics/instrumentServiceBusMessage.js\";\nimport type { TracingSpanLink } from \"@azure/core-tracing\";\n\n/**\n * The default time to wait for messages _after_ the first message\n * has been received.\n *\n * This timeout only applies to receiveMessages()\n *\n * @internal\n */\nexport const defaultMaxTimeAfterFirstMessageForBatchingMs = 1000;\n\n/**\n * The maximum number of messages to delete in a single batch. This cap is established and enforced by the service.\n * @internal\n */\nexport const MaxDeleteMessageCount = 500;\n\n/**\n * A receiver that does not handle sessions.\n */\nexport interface ServiceBusReceiver {\n /**\n * A name used to identify the receiver. This can be used to correlate logs and exceptions.\n * If not specified or empty, a random unique one will be generated.\n */\n identifier: string;\n\n /**\n * Streams messages to message handlers.\n * @param handlers - A handler that gets called for messages and errors.\n * @param options - Options for subscribe.\n * @returns An object that can be closed, sending any remaining messages to `handlers` and\n * stopping new messages from arriving.\n */\n subscribe(\n handlers: MessageHandlers,\n options?: SubscribeOptions,\n ): {\n /**\n * Causes the subscriber to stop receiving new messages.\n */\n close(): Promise<void>;\n };\n\n /**\n * Returns an iterator that can be used to receive messages from Service Bus.\n *\n * @param options - A set of options to control the receive operation.\n * - `abortSignal`: The signal to use to abort the ongoing operation.\n *\n * @throws Error if the underlying connection, client or receiver is closed.\n * @throws Error if current receiver is already in state of receiving messages.\n * @throws `ServiceBusError` if the service returns an error while receiving messages.\n */\n getMessageIterator(\n options?: GetMessageIteratorOptions,\n ): AsyncIterableIterator<ServiceBusReceivedMessage>;\n\n /**\n * Returns a promise that resolves to an array of messages received from Service Bus.\n *\n * @param maxMessageCount - The maximum number of messages to receive.\n * @param options - A set of options to control the receive operation.\n * - `maxWaitTimeInMs`: The maximum time to wait for the first message before returning an empty array if no messages are available.\n * - `abortSignal`: The signal to use to abort the ongoing operation.\n * @returns A promise that resolves with an array of messages.\n * @throws Error if the underlying connection, client or receiver is closed.\n * @throws Error if current receiver is already in state of receiving messages.\n * @throws `ServiceBusError` if the service returns an error while receiving messages.\n */\n receiveMessages(\n maxMessageCount: number,\n options?: ReceiveMessagesOptions,\n ): Promise<ServiceBusReceivedMessage[]>;\n\n /**\n * Returns a promise that resolves to an array of deferred messages identified by given `sequenceNumbers`.\n * @param sequenceNumbers - The sequence number or an array of sequence numbers for the messages that need to be received.\n * @param options - Options bag to pass an abort signal or tracing options.\n * @returns A list of messages identified by the given sequenceNumbers or an empty list if no messages are found.\n * @throws Error if the underlying connection or receiver is closed.\n * @throws `ServiceBusError` if the service returns an error while receiving deferred messages.\n */\n receiveDeferredMessages(\n sequenceNumbers: Long | Long[],\n options?: OperationOptionsBase,\n ): Promise<ServiceBusReceivedMessage[]>;\n\n /**\n * Peek the next batch of active messages (including deferred but not deadlettered messages) on the\n * queue or subscription without modifying them.\n * - The first call to `peekMessages()` fetches the first active message. Each subsequent call fetches the\n * subsequent message.\n * - Unlike a \"received\" message, \"peeked\" message is a read-only version of the message.\n * It cannot be `Completed/Abandoned/Deferred/Deadlettered`.\n * @param maxMessageCount - The maximum number of messages to peek.\n * @param options - Options that allow to specify the maximum number of messages to peek,\n * the sequenceNumber to start peeking from or an abortSignal to abort the operation.\n */\n peekMessages(\n maxMessageCount: number,\n options?: PeekMessagesOptions,\n ): Promise<ServiceBusReceivedMessage[]>;\n\n /**\n * Delete messages. If no option is specified, all messages will be deleted.\n *\n * @param options - Options to configure the operation.\n * @returns number of messages that have been deleted.\n */\n deleteMessages(options: DeleteMessagesOptions): Promise<number>;\n\n /**\n * Attempts to purge all messages from an entity. Locked messages are not eligible for removal and\n * will remain in the entity.\n *\n * @param options - Options that allow to specify the cutoff time for deletion. Only messages that were enqueued\n * before this time will be deleted. If not specified, current time will be used.\n * @returns number of messages deleted.\n */\n purgeMessages(options?: PurgeMessagesOptions): Promise<number>;\n\n /**\n * Path of the entity for which the receiver has been created.\n */\n entityPath: string;\n /**\n * The receive mode used to create the receiver.\n */\n receiveMode: \"peekLock\" | \"receiveAndDelete\";\n /**\n * Returns `true` if either the receiver or the client that created it has been closed.\n * @readonly\n */\n isClosed: boolean;\n /**\n * Closes the receiver.\n * Once closed, the receiver cannot be used for any further operations.\n * Use the `createReceiver()` method on the ServiceBusClient to create a new Receiver.\n */\n close(): Promise<void>;\n /**\n * Removes the message from Service Bus.\n *\n * @throws Error with name `SessionLockLostError` (for messages from a Queue/Subscription with sessions enabled)\n * if the AMQP link with which the message was received is no longer alive. This can\n * happen either because the lock on the session expired or the receiver was explicitly closed by\n * the user or the AMQP link is closed by the library due to network loss or service error.\n * @throws Error with name `MessageLockLostError` (for messages from a Queue/Subscription with sessions not enabled)\n * if the lock on the message has expired or the AMQP link with which the message was received is\n * no longer alive. The latter can happen if the receiver was explicitly closed by the user or the\n * AMQP link got closed by the library due to network loss or service error.\n * @throws Error if the message is already settled.\n * property on the message if you are not sure whether the message is settled.\n * @throws Error if used in `receiveAndDelete` mode because all messages received in this mode\n * are pre-settled. To avoid this error, update your code to not settle a message which is received\n * in this mode.\n * @throws Error with name `ServiceUnavailableError` if Service Bus does not acknowledge the request to settle\n * the message in time. The message may or may not have been settled successfully.\n */\n completeMessage(message: ServiceBusReceivedMessage): Promise<void>;\n /**\n * The lock held on the message by the receiver is let go, making the message available again in\n * Service Bus for another receive operation.\n *\n * @throws `ServiceBusError` with the code `SessionLockLost` (for messages from a Queue/Subscription with sessions enabled)\n * if the AMQP link with which the message was received is no longer alive. This can\n * happen either because the lock on the session expired or the receiver was explicitly closed by\n * the user or the AMQP link is closed by the library due to network loss or service error.\n * @throws `ServiceBusError` with the code `MessageLockLost` (for messages from a Queue/Subscription with sessions not enabled)\n * if the lock on the message has expired or the AMQP link with which the message was received is\n * no longer alive. The latter can happen if the receiver was explicitly closed by the user or the\n * AMQP link got closed by the library due to network loss or service error.\n * @throws Error if the message is already settled.\n * property on the message if you are not sure whether the message is settled.\n * @throws Error if used in `receiveAndDelete` mode because all messages received in this mode\n * are pre-settled. To avoid this error, update your code to not settle a message which is received\n * in this mode.\n * @throws `ServiceBusError` with the code `ServiceTimeout` if Service Bus does not acknowledge the request to settle\n * the message in time. The message may or may not have been settled successfully.\n *\n * @param propertiesToModify - The properties of the message to modify while abandoning the message.\n */\n abandonMessage(\n message: ServiceBusReceivedMessage,\n propertiesToModify?: { [key: string]: number | boolean | string | Date | null },\n ): Promise<void>;\n /**\n * Defers the processing of the message. Save the `sequenceNumber` of the message, in order to\n * receive it message again in the future using the `receiveDeferredMessage` method.\n *\n * @throws `ServiceBusError` with the code `SessionLockLost` (for messages from a Queue/Subscription with sessions enabled)\n * if the AMQP link with which the message was received is no longer alive. This can\n * happen either because the lock on the session expired or the receiver was explicitly closed by\n * the user or the AMQP link is closed by the library due to network loss or service error.\n * @throws `ServiceBusError` with the code `MessageLockLost` (for messages from a Queue/Subscription with sessions not enabled)\n * if the lock on the message has expired or the AMQP link with which the message was received is\n * no longer alive. The latter can happen if the receiver was explicitly closed by the user or the\n * AMQP link got closed by the library due to network loss or service error.\n * @throws Error if the message is already settled.\n * property on the message if you are not sure whether the message is settled.\n * @throws Error if used in `receiveAndDelete` mode because all messages received in this mode\n * are pre-settled. To avoid this error, update your code to not settle a message which is received\n * in this mode.\n * @throws `ServiceBusError` with the code `ServiceTimeout` if Service Bus does not acknowledge the request to settle\n * the message in time. The message may or may not have been settled successfully.\n *\n * @param propertiesToModify - The properties of the message to modify while deferring the message\n */\n deferMessage(\n message: ServiceBusReceivedMessage,\n propertiesToModify?: { [key: string]: number | boolean | string | Date | null },\n ): Promise<void>;\n /**\n * Moves the message to the deadletter sub-queue. To receive a deadletted message, create a new\n * QueueClient/SubscriptionClient using the path for the deadletter sub-queue.\n *\n * @throws `ServiceBusError` with the code `SessionLockLost` (for messages from a Queue/Subscription with sessions enabled)\n * if the AMQP link with which the message was received is no longer alive. This can\n * happen either because the lock on the session expired or the receiver was explicitly closed by\n * the user or the AMQP link is closed by the library due to network loss or service error.\n * @throws `ServiceBusError` with the code `MessageLockLost` (for messages from a Queue/Subscription with sessions not enabled)\n * if the lock on the message has expired or the AMQP link with which the message was received is\n * no longer alive. The latter can happen if the receiver was explicitly closed by the user or the\n * AMQP link got closed by the library due to network loss or service error.\n * @throws Error if the message is already settled.\n * property on the message if you are not sure whether the message is settled.\n * @throws Error if used in `receiveAndDelete` mode because all messages received in this mode\n * are pre-settled. To avoid this error, update your code to not settle a message which is received\n * in this mode.\n * @throws `ServiceBusError` with the code `ServiceTimeout` if Service Bus does not acknowledge the request to settle\n * the message in time. The message may or may not have been settled successfully.\n *\n * @param options - The DeadLetter options that can be provided while\n * rejecting the message.\n */\n deadLetterMessage(\n message: ServiceBusReceivedMessage,\n options?: DeadLetterOptions & { [key: string]: number | boolean | string | Date | null },\n ): Promise<void>;\n /**\n * Renews the lock on the message for the duration as specified during the Queue/Subscription\n * creation.\n * - Check the `lockedUntilUtc` property on the message for the time when the lock expires.\n * - If a message is not settled (using either `complete()`, `defer()` or `deadletter()`,\n * before its lock expires, then the message lands back in the Queue/Subscription for the next\n * receive operation.\n *\n * @returns New lock token expiry date and time in UTC format.\n * @throws Error if the underlying connection, client or receiver is closed.\n * @throws ServiceBusError if the service returns an error while renewing message lock.\n */\n renewMessageLock(message: ServiceBusReceivedMessage): Promise<Date>;\n}\n\n/**\n * @internal\n */\nexport class ServiceBusReceiverImpl implements ServiceBusReceiver {\n public identifier: string;\n private _retryOptions: RetryOptions;\n /**\n * Denotes if close() was called on this receiver\n */\n private _isClosed: boolean = false;\n\n /**\n * Instance of the BatchingReceiver class to use to receive messages in pull mode.\n */\n private _batchingReceiver?: BatchingReceiver;\n\n /**\n * Instance of the StreamingReceiver class to use to receive messages in push mode.\n */\n private _streamingReceiver?: StreamingReceiver;\n private _lockRenewer: LockRenewer | undefined;\n\n private get logPrefix(): string {\n return `[${this._context.connectionId}|receiver:${this.entityPath}]`;\n }\n\n /**\n * @throws Error if the underlying connection is closed.\n */\n constructor(\n private _context: ConnectionContext,\n public entityPath: string,\n public receiveMode: \"peekLock\" | \"receiveAndDelete\",\n maxAutoRenewLockDurationInMs: number,\n private skipParsingBodyAsJson: boolean,\n private skipConvertingDate: boolean = false,\n retryOptions: RetryOptions = {},\n identifier?: string,\n ) {\n throwErrorIfConnectionClosed(_context);\n this._retryOptions = retryOptions;\n this._lockRenewer = LockRenewer.create(\n this._context,\n maxAutoRenewLockDurationInMs,\n receiveMode,\n );\n this.identifier = ensureValidIdentifier(this.entityPath, identifier);\n }\n\n private _throwIfAlreadyReceiving(): void {\n if (this._isReceivingMessages()) {\n const errorMessage = getAlreadyReceivingErrorMsg(this.entityPath);\n const error = new Error(errorMessage);\n logger.logError(error, `${this.logPrefix} is already receiving`);\n throw error;\n }\n }\n\n private _throwIfReceiverOrConnectionClosed(): void {\n throwErrorIfConnectionClosed(this._context);\n if (this.isClosed) {\n const errorMessage = getReceiverClosedErrorMsg(this.entityPath);\n const error = new Error(errorMessage);\n logger.logError(error, `${this.logPrefix} is closed`);\n throw error;\n }\n }\n\n public get isClosed(): boolean {\n return this._isClosed || this._context.wasConnectionCloseCalled;\n }\n\n async receiveMessages(\n maxMessageCount: number,\n options?: ReceiveMessagesOptions,\n ): Promise<ServiceBusReceivedMessage[]> {\n this._throwIfReceiverOrConnectionClosed();\n this._throwIfAlreadyReceiving();\n throwTypeErrorIfParameterMissing(\n this._context.connectionId,\n \"maxMessageCount\",\n maxMessageCount,\n );\n throwTypeErrorIfParameterTypeMismatch(\n this._context.connectionId,\n \"maxMessageCount\",\n maxMessageCount,\n \"number\",\n );\n\n if (isNaN(maxMessageCount) || maxMessageCount < 1) {\n throw new TypeError(InvalidMaxMessageCountError);\n }\n\n const receiveMessages = async (): Promise<ServiceBusReceivedMessage[]> => {\n if (!this._batchingReceiver || !this._context.messageReceivers[this._batchingReceiver.name]) {\n const receiveOptions: ReceiveOptions = {\n maxConcurrentCalls: 0,\n receiveMode: this.receiveMode,\n lockRenewer: this._lockRenewer,\n skipParsingBodyAsJson: this.skipParsingBodyAsJson,\n skipConvertingDate: this.skipConvertingDate,\n };\n this._batchingReceiver = this._createBatchingReceiver(\n this._context,\n this.entityPath,\n receiveOptions,\n );\n }\n\n const receivedMessages = await this._batchingReceiver.receive(\n maxMessageCount,\n options?.maxWaitTimeInMs ?? Constants.defaultOperationTimeoutInMs,\n defaultMaxTimeAfterFirstMessageForBatchingMs,\n options ?? {},\n );\n\n return receivedMessages;\n };\n const config: RetryConfig<ServiceBusReceivedMessage[]> = {\n connectionHost: this._context.config.host,\n connectionId: this._context.connectionId,\n operation: receiveMessages,\n operationType: RetryOperationType.receiveMessage,\n abortSignal: options?.abortSignal,\n retryOptions: this._retryOptions,\n };\n return retry<ServiceBusReceivedMessage[]>(config).catch((err) => {\n throw translateServiceBusError(err);\n });\n }\n\n getMessageIterator(\n options?: GetMessageIteratorOptions,\n ): AsyncIterableIterator<ServiceBusReceivedMessage> {\n return getMessageIterator(this, options);\n }\n\n async receiveDeferredMessages(\n sequenceNumbers: Long | Long[],\n options: OperationOptionsBase = {},\n ): Promise<ServiceBusReceivedMessage[]> {\n this._throwIfReceiverOrConnectionClosed();\n throwTypeErrorIfParameterMissing(\n this._context.connectionId,\n \"sequenceNumbers\",\n sequenceNumbers,\n );\n throwTypeErrorIfParameterNotLong(\n this._context.connectionId,\n \"sequenceNumbers\",\n sequenceNumbers,\n );\n\n const deferredSequenceNumbers = Array.isArray(sequenceNumbers)\n ? sequenceNumbers\n : [sequenceNumbers];\n const receiveDeferredMessagesOperationPromise = async (): Promise<\n ServiceBusReceivedMessage[]\n > => {\n const deferredMessages = await this._context\n .getManagementClient(this.entityPath)\n .receiveDeferredMessages(deferredSequenceNumbers, this.receiveMode, undefined, {\n ...options,\n associatedLinkName: this._getAssociatedReceiverName(),\n requestName: \"receiveDeferredMessages\",\n timeoutInMs: this._retryOptions.timeoutInMs,\n skipParsingBodyAsJson: this.skipParsingBodyAsJson,\n skipConvertingDate: this.skipConvertingDate,\n });\n return deferredMessages;\n };\n const config: RetryConfig<ServiceBusReceivedMessage[]> = {\n operation: receiveDeferredMessagesOperationPromise,\n connectionId: this._context.connectionId,\n operationType: RetryOperationType.management,\n retryOptions: this._retryOptions,\n abortSignal: options?.abortSignal,\n };\n return retry<ServiceBusReceivedMessage[]>(config);\n }\n\n async deleteMessages(options: DeleteMessagesOptions): Promise<number> {\n this._throwIfReceiverOrConnectionClosed();\n\n const deleteMessagesOperationPromise = (): Promise<number> => {\n return this._context\n .getManagementClient(this.entityPath)\n .deleteMessages(options.maxMessageCount, options?.beforeEnqueueTime, undefined, {\n ...options,\n associatedLinkName: this._getAssociatedReceiverName(),\n requestName: \"deleteMessages\",\n timeoutInMs: this._retryOptions.timeoutInMs,\n });\n };\n const config: RetryConfig<number> = {\n operation: deleteMessagesOperationPromise,\n connectionId: this._context.connectionId,\n operationType: RetryOperationType.management,\n retryOptions: this._retryOptions,\n abortSignal: options?.abortSignal,\n };\n return retry<number>(config);\n }\n\n async purgeMessages(options?: PurgeMessagesOptions): Promise<number> {\n let deletedCount = await this.deleteMessages({\n maxMessageCount: MaxDeleteMessageCount,\n beforeEnqueueTime: options?.beforeEnqueueTime,\n });\n logger.verbose(\n `${this.logPrefix} receiver '${this.identifier}' deleted ${deletedCount} messages.`,\n );\n if (deletedCount === MaxDeleteMessageCount) {\n let batchCount = MaxDeleteMessageCount;\n while (batchCount === MaxDeleteMessageCount) {\n batchCount = await this.deleteMessages({\n maxMessageCount: MaxDeleteMessageCount,\n beforeEnqueueTime: options?.beforeEnqueueTime,\n });\n logger.verbose(\n `${this.logPrefix} receiver '${this.identifier}' deleted ${batchCount} messages.`,\n );\n deletedCount += batchCount;\n }\n }\n logger.verbose(\n `${this.logPrefix} receiver '${this.identifier}' purged ${deletedCount} messages.`,\n );\n return deletedCount;\n }\n\n // ManagementClient methods # Begin\n\n async peekMessages(\n maxMessageCount: number,\n options: PeekMessagesOptions = {},\n ): Promise<ServiceBusReceivedMessage[]> {\n this._throwIfReceiverOrConnectionClosed();\n\n const managementRequestOptions = {\n ...options,\n associatedLinkName: this._getAssociatedReceiverName(),\n requestName: \"peekMessages\",\n timeoutInMs: this._retryOptions?.timeoutInMs,\n skipParsingBodyAsJson: this.skipParsingBodyAsJson,\n skipConvertingDate: this.skipConvertingDate,\n };\n // omitMessageBody is available at runtime, but only exported in experimental subpath\n const { fromSequenceNumber, omitMessageBody } = options as PeekMessagesOptions & {\n omitMessageBody: boolean;\n };\n const peekOperationPromise = async (): Promise<ServiceBusReceivedMessage[]> => {\n if (fromSequenceNumber !== undefined) {\n return this._context\n .getManagementClient(this.entityPath)\n .peekBySequenceNumber(\n fromSequenceNumber,\n maxMessageCount,\n undefined,\n omitMessageBody,\n managementRequestOptions,\n );\n } else {\n return this._context\n .getManagementClient(this.entityPath)\n .peek(maxMessageCount, omitMessageBody, managementRequestOptions);\n }\n };\n\n const config: RetryConfig<ServiceBusReceivedMessage[]> = {\n operation: peekOperationPromise,\n connectionId: this._context.connectionId,\n operationType: RetryOperationType.management,\n retryOptions: this._retryOptions,\n abortSignal: options?.abortSignal,\n };\n return retry<ServiceBusReceivedMessage[]>(config);\n }\n\n subscribe(\n handlers: MessageHandlers,\n options?: SubscribeOptions,\n ): {\n close(): Promise<void>;\n } {\n assertValidMessageHandlers(handlers);\n throwErrorIfConnectionClosed(this._context);\n this._throwIfReceiverOrConnectionClosed();\n this._throwIfAlreadyReceiving();\n\n options = {\n ...(options ?? {}),\n autoCompleteMessages: options?.autoCompleteMessages ?? true,\n };\n\n // When the user \"stops\" a streaming receiver (via the returned instance from 'subscribe' we just suspend\n // it, leaving the link open). This allows users to stop the flow of messages but still be able to settle messages\n // since the link itself hasn't been shut down.\n //\n // Users can, if they want, restart their subscription (since we've got a link already established).\n // So you'll have an instance here if the user has done:\n // 1. const subscription = receiver.subscribe()\n // 2. subscription.stop()\n // 3. receiver.subscribe()\n\n this._streamingReceiver =\n this._streamingReceiver ??\n new StreamingReceiver(this.identifier, this._context, this.entityPath, {\n ...options,\n receiveMode: this.receiveMode,\n retryOptions: this._retryOptions,\n lockRenewer: this._lockRenewer,\n skipParsingBodyAsJson: this.skipParsingBodyAsJson,\n skipConvertingDate: this.skipConvertingDate,\n });\n\n // this ensures that if the outer service bus client is closed that this receiver is cleaned up.\n // this mostly affects us if we're in the middle of init() - the connection (and receiver) are not yet\n // open but we do need to close the receiver to exit the init() loop.\n this._context.messageReceivers[this._streamingReceiver.name] = this._streamingReceiver;\n\n this._streamingReceiver.subscribe(handlers, options).catch((_) => {\n // (the error will already have been reported to the user)\n if (this._streamingReceiver) {\n delete this._context.messageReceivers[this._streamingReceiver.name];\n }\n });\n\n return {\n close: async (): Promise<void> => {\n return this._streamingReceiver?.stopReceivingMessages();\n },\n };\n }\n\n async completeMessage(message: ServiceBusReceivedMessage): Promise<void> {\n this._throwIfReceiverOrConnectionClosed();\n throwErrorIfInvalidOperationOnMessage(message, this.receiveMode, this._context.connectionId);\n const msgImpl = message as ServiceBusMessageImpl;\n return completeMessage(msgImpl, this._context, this.entityPath, this._retryOptions);\n }\n\n async abandonMessage(\n message: ServiceBusReceivedMessage,\n propertiesToModify?: { [key: string]: number | boolean | string | Date | null },\n ): Promise<void> {\n this._throwIfReceiverOrConnectionClosed();\n throwErrorIfInvalidOperationOnMessage(message, this.receiveMode, this._context.connectionId);\n const msgImpl = message as ServiceBusMessageImpl;\n return abandonMessage(\n msgImpl,\n this._context,\n this.entityPath,\n propertiesToModify,\n this._retryOptions,\n );\n }\n\n async deferMessage(\n message: ServiceBusReceivedMessage,\n propertiesToModify?: { [key: string]: number | boolean | string | Date | null },\n ): Promise<void> {\n this._throwIfReceiverOrConnectionClosed();\n throwErrorIfInvalidOperationOnMessage(message, this.receiveMode, this._context.connectionId);\n const msgImpl = message as ServiceBusMessageImpl;\n return deferMessage(\n msgImpl,\n this._context,\n this.entityPath,\n propertiesToModify,\n this._retryOptions,\n );\n }\n\n async deadLetterMessage(\n message: ServiceBusReceivedMessage,\n options?: DeadLetterOptions & { [key: string]: number | boolean | string | Date | null },\n ): Promise<void> {\n this._throwIfReceiverOrConnectionClosed();\n throwErrorIfInvalidOperationOnMessage(message, this.receiveMode, this._context.connectionId);\n const msgImpl = message as ServiceBusMessageImpl;\n return deadLetterMessage(msgImpl, this._context, this.entityPath, options, this._retryOptions);\n }\n\n async renewMessageLock(message: ServiceBusReceivedMessage): Promise<Date> {\n this._throwIfReceiverOrConnectionClosed();\n throwErrorIfInvalidOperationOnMessage(message, this.receiveMode, this._context.connectionId);\n\n const tracingContext = extractSpanContextFromServiceBusMessage(message);\n const spanLinks: TracingSpanLink[] = tracingContext ? [{ tracingContext }] : [];\n\n return tracingClient.withSpan(\n \"ServiceBusReceiver.renewMessageLock\",\n {},\n () => {\n const msgImpl = message as ServiceBusMessageImpl;\n\n let associatedLinkName: string | undefined;\n if (msgImpl.delivery.link) {\n const associatedReceiver = this._context.getReceiverFromCache(msgImpl.delivery.link.name);\n associatedLinkName = associatedReceiver?.name;\n }\n return this._context\n .getManagementClient(this.entityPath)\n .renewLock(message.lockToken!, { associatedLinkName })\n .then((lockedUntil) => {\n message.lockedUntilUtc = lockedUntil;\n return lockedUntil;\n });\n },\n {\n spanLinks,\n ...toSpanOptions(\n { entityPath: this.entityPath, host: this._context.config.host },\n \"receive\",\n \"client\",\n ),\n },\n );\n }\n\n async close(): Promise<void> {\n try {\n this._isClosed = true;\n if (this._context.connection && this._context.connection.isOpen()) {\n // Close the streaming receiver.\n if (this._streamingReceiver) {\n await this._streamingReceiver.close();\n }\n\n // Close the batching receiver.\n if (this._batchingReceiver) {\n await this._batchingReceiver.close();\n }\n }\n } catch (err: any) {\n logger.logError(err, `${this.logPrefix} An error occurred while closing the Receiver`);\n throw err;\n }\n }\n\n /**\n * Indicates whether the receiver is currently receiving messages or not.\n * When this returns true, new `registerMessageHandler()` or `receiveMessages()` calls cannot be made.\n */\n private _isReceivingMessages(): boolean {\n if (\n this._streamingReceiver &&\n this._streamingReceiver.isOpen() &&\n this._streamingReceiver.isSubscribeActive\n ) {\n return true;\n }\n if (\n this._batchingReceiver &&\n this._batchingReceiver.isOpen() &&\n this._batchingReceiver.isReceivingMessages\n ) {\n return true;\n }\n return false;\n }\n\n private _createBatchingReceiver(\n context: ConnectionContext,\n entityPath: string,\n options: ReceiveOptions,\n ): BatchingReceiver {\n const receiver = BatchingReceiver.create(this.identifier, context, entityPath, options);\n logger.verbose(\n `[${this.logPrefix}] receiver '${receiver.name}' created, with maxConcurrentCalls set to ${options.maxConcurrentCalls}.`,\n );\n\n return receiver;\n }\n\n /**\n * Helper function to retrieve any active receiver name, regardless of streaming or\n * batching if it exists. This is used for optimization on the service side\n */\n private _getAssociatedReceiverName(): string | undefined {\n if (this._streamingReceiver && this._streamingReceiver.isOpen()) {\n return this._streamingReceiver.name;\n }\n if (\n this._batchingReceiver &&\n this._batchingReceiver.isOpen() &&\n this._batchingReceiver.isReceivingMessages\n ) {\n return this._batchingReceiver.name;\n }\n return;\n }\n}\n"]}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
|
-
import { __asyncGenerator, __await } from "tslib";
|
|
4
3
|
import { logger, receiverLogger } from "../log.js";
|
|
5
4
|
import { translateServiceBusError } from "../serviceBusError.js";
|
|
6
5
|
import { DispositionType } from "../serviceBusMessage.js";
|
|
@@ -23,16 +22,14 @@ export function assertValidMessageHandlers(handlers) {
|
|
|
23
22
|
/**
|
|
24
23
|
* @internal
|
|
25
24
|
*/
|
|
26
|
-
export function getMessageIterator(receiver, options) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
yield yield __await(messages[0]);
|
|
25
|
+
export async function* getMessageIterator(receiver, options) {
|
|
26
|
+
while (true) {
|
|
27
|
+
const messages = await receiver.receiveMessages(1, options);
|
|
28
|
+
if (messages.length === 0) {
|
|
29
|
+
continue;
|
|
34
30
|
}
|
|
35
|
-
|
|
31
|
+
yield messages[0];
|
|
32
|
+
}
|
|
36
33
|
}
|
|
37
34
|
/**
|
|
38
35
|
* @internal
|
|
@@ -58,7 +55,10 @@ export function completeMessage(message, context, entityPath, retryOptions) {
|
|
|
58
55
|
const spanLinks = tracingContext ? [{ tracingContext }] : [];
|
|
59
56
|
return tracingClient.withSpan("ServicebusReceiver.complete", {}, () => settleMessage(message, DispositionType.complete, context, entityPath, {
|
|
60
57
|
retryOptions,
|
|
61
|
-
}),
|
|
58
|
+
}), {
|
|
59
|
+
spanLinks,
|
|
60
|
+
...toSpanOptions({ entityPath, host: context.config.host }, "settle", "client"),
|
|
61
|
+
});
|
|
62
62
|
}
|
|
63
63
|
/**
|
|
64
64
|
* @internal
|
|
@@ -71,7 +71,10 @@ export function abandonMessage(message, context, entityPath, propertiesToModify,
|
|
|
71
71
|
return tracingClient.withSpan("ServicebusReceiver.abandon", {}, () => settleMessage(message, DispositionType.abandon, context, entityPath, {
|
|
72
72
|
propertiesToModify,
|
|
73
73
|
retryOptions,
|
|
74
|
-
}),
|
|
74
|
+
}), {
|
|
75
|
+
spanLinks,
|
|
76
|
+
...toSpanOptions({ entityPath, host: context.config.host }, "settle", "client"),
|
|
77
|
+
});
|
|
75
78
|
}
|
|
76
79
|
/**
|
|
77
80
|
* @internal
|
|
@@ -84,7 +87,10 @@ export function deferMessage(message, context, entityPath, propertiesToModify, r
|
|
|
84
87
|
return tracingClient.withSpan("ServiceBusReceiver.defer", {}, () => settleMessage(message, DispositionType.defer, context, entityPath, {
|
|
85
88
|
retryOptions,
|
|
86
89
|
propertiesToModify,
|
|
87
|
-
}),
|
|
90
|
+
}), {
|
|
91
|
+
spanLinks,
|
|
92
|
+
...toSpanOptions({ entityPath, host: context.config.host }, "settle", "client"),
|
|
93
|
+
});
|
|
88
94
|
}
|
|
89
95
|
/**
|
|
90
96
|
* @internal
|
|
@@ -92,19 +98,24 @@ export function deferMessage(message, context, entityPath, propertiesToModify, r
|
|
|
92
98
|
*/
|
|
93
99
|
export function deadLetterMessage(message, context, entityPath, propertiesToModify, retryOptions) {
|
|
94
100
|
receiverLogger.verbose("[%s] Deadlettering the message with id '%s'.", context.connectionId, message.messageId);
|
|
95
|
-
const actualPropertiesToModify =
|
|
101
|
+
const actualPropertiesToModify = {
|
|
102
|
+
...propertiesToModify,
|
|
103
|
+
};
|
|
96
104
|
// these two fields are handled specially and don't need to be in here.
|
|
97
105
|
delete actualPropertiesToModify.deadLetterErrorDescription;
|
|
98
106
|
delete actualPropertiesToModify.deadLetterReason;
|
|
99
107
|
const dispositionStatusOptions = {
|
|
100
108
|
propertiesToModify: actualPropertiesToModify,
|
|
101
|
-
deadLetterReason: propertiesToModify
|
|
102
|
-
deadLetterDescription: propertiesToModify
|
|
109
|
+
deadLetterReason: propertiesToModify?.deadLetterReason,
|
|
110
|
+
deadLetterDescription: propertiesToModify?.deadLetterErrorDescription,
|
|
103
111
|
retryOptions,
|
|
104
112
|
};
|
|
105
113
|
const tracingContext = extractSpanContextFromServiceBusMessage(message);
|
|
106
114
|
const spanLinks = tracingContext ? [{ tracingContext }] : [];
|
|
107
|
-
return tracingClient.withSpan("ServiceBusReceiver.deadLetter", {}, () => settleMessage(message, DispositionType.deadletter, context, entityPath, dispositionStatusOptions),
|
|
115
|
+
return tracingClient.withSpan("ServiceBusReceiver.deadLetter", {}, () => settleMessage(message, DispositionType.deadletter, context, entityPath, dispositionStatusOptions), {
|
|
116
|
+
spanLinks,
|
|
117
|
+
...toSpanOptions({ entityPath, host: context.config.host }, "settle", "client"),
|
|
118
|
+
});
|
|
108
119
|
}
|
|
109
120
|
/**
|
|
110
121
|
* @internal
|
|
@@ -116,8 +127,8 @@ export function settleMessage(message, operation, context, entityPath, options,
|
|
|
116
127
|
return _settleMessageOperation(message, operation, context, entityPath, options);
|
|
117
128
|
},
|
|
118
129
|
operationType: RetryOperationType.messageSettlement,
|
|
119
|
-
abortSignal: options
|
|
120
|
-
retryOptions: options
|
|
130
|
+
abortSignal: options?.abortSignal,
|
|
131
|
+
retryOptions: options?.retryOptions,
|
|
121
132
|
});
|
|
122
133
|
}
|
|
123
134
|
/**
|
|
@@ -132,7 +143,7 @@ export async function settleMessageOperation(message, operation, context, entity
|
|
|
132
143
|
const receiver = isDeferredMessage
|
|
133
144
|
? undefined
|
|
134
145
|
: context.getReceiverFromCache(message.delivery.link.name, message.sessionId);
|
|
135
|
-
const associatedLinkName = receiver
|
|
146
|
+
const associatedLinkName = receiver?.name;
|
|
136
147
|
let error;
|
|
137
148
|
if (message.delivery.remote_settled) {
|
|
138
149
|
error = new Error(MessageAlreadySettled);
|
|
@@ -156,7 +167,11 @@ export async function settleMessageOperation(message, operation, context, entity
|
|
|
156
167
|
if (isDeferredMessage || ((!receiver || !receiver.isOpen()) && !isDefined(message.sessionId))) {
|
|
157
168
|
return context
|
|
158
169
|
.getManagementClient(entityPath)
|
|
159
|
-
.updateDispositionStatus(message.lockToken, operation,
|
|
170
|
+
.updateDispositionStatus(message.lockToken, operation, {
|
|
171
|
+
...options,
|
|
172
|
+
associatedLinkName,
|
|
173
|
+
sessionId: message.sessionId,
|
|
174
|
+
})
|
|
160
175
|
.catch((err) => {
|
|
161
176
|
throw translateServiceBusError(err);
|
|
162
177
|
});
|