@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.
Files changed (254) hide show
  1. package/dist/browser/connectionContext.js +1 -2
  2. package/dist/browser/connectionContext.js.map +1 -1
  3. package/dist/browser/constructorHelpers.js +3 -4
  4. package/dist/browser/constructorHelpers.js.map +1 -1
  5. package/dist/browser/core/autoLockRenewer.js +9 -5
  6. package/dist/browser/core/autoLockRenewer.js.map +1 -1
  7. package/dist/browser/core/batchingReceiver.js +26 -18
  8. package/dist/browser/core/batchingReceiver.js.map +1 -1
  9. package/dist/browser/core/linkEntity.js +74 -13
  10. package/dist/browser/core/linkEntity.js.map +1 -1
  11. package/dist/browser/core/managementClient.js +48 -48
  12. package/dist/browser/core/managementClient.js.map +1 -1
  13. package/dist/browser/core/messageReceiver.js +41 -14
  14. package/dist/browser/core/messageReceiver.js.map +1 -1
  15. package/dist/browser/core/messageSender.js +33 -10
  16. package/dist/browser/core/messageSender.js.map +1 -1
  17. package/dist/browser/core/receiverHelper.js +3 -2
  18. package/dist/browser/core/receiverHelper.js.map +1 -1
  19. package/dist/browser/core/shared.js +11 -4
  20. package/dist/browser/core/shared.js.map +1 -1
  21. package/dist/browser/core/streamingReceiver.js +74 -43
  22. package/dist/browser/core/streamingReceiver.js.map +1 -1
  23. package/dist/browser/diagnostics/instrumentServiceBusMessage.js +16 -8
  24. package/dist/browser/diagnostics/instrumentServiceBusMessage.js.map +1 -1
  25. package/dist/browser/receivers/receiver.js +68 -23
  26. package/dist/browser/receivers/receiver.js.map +1 -1
  27. package/dist/browser/receivers/receiverCommon.js +36 -21
  28. package/dist/browser/receivers/receiverCommon.js.map +1 -1
  29. package/dist/browser/receivers/sessionReceiver.js +69 -29
  30. package/dist/browser/receivers/sessionReceiver.js.map +1 -1
  31. package/dist/browser/sender.js +33 -11
  32. package/dist/browser/sender.js.map +1 -1
  33. package/dist/browser/serializers/queueResourceSerializer.js +9 -1
  34. package/dist/browser/serializers/queueResourceSerializer.js.map +1 -1
  35. package/dist/browser/serializers/ruleResourceSerializer.js +1 -2
  36. package/dist/browser/serializers/ruleResourceSerializer.js.map +1 -1
  37. package/dist/browser/serviceBusAtomManagementClient.js +181 -228
  38. package/dist/browser/serviceBusAtomManagementClient.js.map +1 -1
  39. package/dist/browser/serviceBusClient.js +31 -22
  40. package/dist/browser/serviceBusClient.js.map +1 -1
  41. package/dist/browser/serviceBusError.js +21 -1
  42. package/dist/browser/serviceBusError.js.map +1 -1
  43. package/dist/browser/serviceBusMessage.js +208 -13
  44. package/dist/browser/serviceBusMessage.js.map +1 -1
  45. package/dist/browser/serviceBusMessageBatch.js +32 -8
  46. package/dist/browser/serviceBusMessageBatch.js.map +1 -1
  47. package/dist/browser/serviceBusRuleManager.js +39 -15
  48. package/dist/browser/serviceBusRuleManager.js.map +1 -1
  49. package/dist/browser/session/messageSession.js +130 -25
  50. package/dist/browser/session/messageSession.js.map +1 -1
  51. package/dist/browser/util/atomXmlHelper.js +4 -5
  52. package/dist/browser/util/atomXmlHelper.js.map +1 -1
  53. package/dist/browser/util/compat/httpHeaders.js +1 -0
  54. package/dist/browser/util/compat/httpHeaders.js.map +1 -1
  55. package/dist/browser/util/constants.js +1 -1
  56. package/dist/browser/util/constants.js.map +1 -1
  57. package/dist/browser/util/sasServiceClientCredentials.js +8 -0
  58. package/dist/browser/util/sasServiceClientCredentials.js.map +1 -1
  59. package/dist/browser/util/semaphore.js +6 -2
  60. package/dist/browser/util/semaphore.js.map +1 -1
  61. package/dist/browser/util/utils.js +5 -7
  62. package/dist/browser/util/utils.js.map +1 -1
  63. package/dist/commonjs/connectionContext.js +1 -2
  64. package/dist/commonjs/connectionContext.js.map +1 -1
  65. package/dist/commonjs/constructorHelpers.js +3 -4
  66. package/dist/commonjs/constructorHelpers.js.map +1 -1
  67. package/dist/commonjs/core/autoLockRenewer.js +9 -5
  68. package/dist/commonjs/core/autoLockRenewer.js.map +1 -1
  69. package/dist/commonjs/core/batchingReceiver.js +26 -18
  70. package/dist/commonjs/core/batchingReceiver.js.map +1 -1
  71. package/dist/commonjs/core/linkEntity.js +74 -13
  72. package/dist/commonjs/core/linkEntity.js.map +1 -1
  73. package/dist/commonjs/core/managementClient.js +48 -48
  74. package/dist/commonjs/core/managementClient.js.map +1 -1
  75. package/dist/commonjs/core/messageReceiver.js +41 -14
  76. package/dist/commonjs/core/messageReceiver.js.map +1 -1
  77. package/dist/commonjs/core/messageSender.js +33 -10
  78. package/dist/commonjs/core/messageSender.js.map +1 -1
  79. package/dist/commonjs/core/receiverHelper.js +3 -2
  80. package/dist/commonjs/core/receiverHelper.js.map +1 -1
  81. package/dist/commonjs/core/shared.js +11 -4
  82. package/dist/commonjs/core/shared.js.map +1 -1
  83. package/dist/commonjs/core/streamingReceiver.js +74 -43
  84. package/dist/commonjs/core/streamingReceiver.js.map +1 -1
  85. package/dist/commonjs/diagnostics/instrumentServiceBusMessage.js +16 -8
  86. package/dist/commonjs/diagnostics/instrumentServiceBusMessage.js.map +1 -1
  87. package/dist/commonjs/receivers/receiver.js +68 -23
  88. package/dist/commonjs/receivers/receiver.js.map +1 -1
  89. package/dist/commonjs/receivers/receiverCommon.js +36 -21
  90. package/dist/commonjs/receivers/receiverCommon.js.map +1 -1
  91. package/dist/commonjs/receivers/sessionReceiver.js +69 -29
  92. package/dist/commonjs/receivers/sessionReceiver.js.map +1 -1
  93. package/dist/commonjs/sender.js +33 -11
  94. package/dist/commonjs/sender.js.map +1 -1
  95. package/dist/commonjs/serializers/queueResourceSerializer.js +9 -1
  96. package/dist/commonjs/serializers/queueResourceSerializer.js.map +1 -1
  97. package/dist/commonjs/serializers/ruleResourceSerializer.js +1 -2
  98. package/dist/commonjs/serializers/ruleResourceSerializer.js.map +1 -1
  99. package/dist/commonjs/serviceBusAtomManagementClient.js +181 -227
  100. package/dist/commonjs/serviceBusAtomManagementClient.js.map +1 -1
  101. package/dist/commonjs/serviceBusClient.js +31 -22
  102. package/dist/commonjs/serviceBusClient.js.map +1 -1
  103. package/dist/commonjs/serviceBusError.js +21 -1
  104. package/dist/commonjs/serviceBusError.js.map +1 -1
  105. package/dist/commonjs/serviceBusMessage.js +208 -12
  106. package/dist/commonjs/serviceBusMessage.js.map +1 -1
  107. package/dist/commonjs/serviceBusMessageBatch.js +32 -8
  108. package/dist/commonjs/serviceBusMessageBatch.js.map +1 -1
  109. package/dist/commonjs/serviceBusRuleManager.js +39 -15
  110. package/dist/commonjs/serviceBusRuleManager.js.map +1 -1
  111. package/dist/commonjs/session/messageSession.js +130 -25
  112. package/dist/commonjs/session/messageSession.js.map +1 -1
  113. package/dist/commonjs/tsdoc-metadata.json +11 -11
  114. package/dist/commonjs/util/atomXmlHelper.js +4 -5
  115. package/dist/commonjs/util/atomXmlHelper.js.map +1 -1
  116. package/dist/commonjs/util/compat/httpHeaders.js +1 -0
  117. package/dist/commonjs/util/compat/httpHeaders.js.map +1 -1
  118. package/dist/commonjs/util/constants.js +1 -1
  119. package/dist/commonjs/util/constants.js.map +1 -1
  120. package/dist/commonjs/util/runtimeInfo.js +2 -2
  121. package/dist/commonjs/util/runtimeInfo.js.map +1 -1
  122. package/dist/commonjs/util/sasServiceClientCredentials.js +8 -0
  123. package/dist/commonjs/util/sasServiceClientCredentials.js.map +1 -1
  124. package/dist/commonjs/util/semaphore.js +6 -2
  125. package/dist/commonjs/util/semaphore.js.map +1 -1
  126. package/dist/commonjs/util/utils.js +5 -7
  127. package/dist/commonjs/util/utils.js.map +1 -1
  128. package/dist/esm/connectionContext.js +1 -2
  129. package/dist/esm/connectionContext.js.map +1 -1
  130. package/dist/esm/constructorHelpers.js +3 -4
  131. package/dist/esm/constructorHelpers.js.map +1 -1
  132. package/dist/esm/core/autoLockRenewer.js +9 -5
  133. package/dist/esm/core/autoLockRenewer.js.map +1 -1
  134. package/dist/esm/core/batchingReceiver.js +26 -18
  135. package/dist/esm/core/batchingReceiver.js.map +1 -1
  136. package/dist/esm/core/linkEntity.js +74 -13
  137. package/dist/esm/core/linkEntity.js.map +1 -1
  138. package/dist/esm/core/managementClient.js +48 -48
  139. package/dist/esm/core/managementClient.js.map +1 -1
  140. package/dist/esm/core/messageReceiver.js +41 -14
  141. package/dist/esm/core/messageReceiver.js.map +1 -1
  142. package/dist/esm/core/messageSender.js +33 -10
  143. package/dist/esm/core/messageSender.js.map +1 -1
  144. package/dist/esm/core/receiverHelper.js +3 -2
  145. package/dist/esm/core/receiverHelper.js.map +1 -1
  146. package/dist/esm/core/shared.js +11 -4
  147. package/dist/esm/core/shared.js.map +1 -1
  148. package/dist/esm/core/streamingReceiver.js +74 -43
  149. package/dist/esm/core/streamingReceiver.js.map +1 -1
  150. package/dist/esm/diagnostics/instrumentServiceBusMessage.js +16 -8
  151. package/dist/esm/diagnostics/instrumentServiceBusMessage.js.map +1 -1
  152. package/dist/esm/receivers/receiver.js +68 -23
  153. package/dist/esm/receivers/receiver.js.map +1 -1
  154. package/dist/esm/receivers/receiverCommon.js +36 -21
  155. package/dist/esm/receivers/receiverCommon.js.map +1 -1
  156. package/dist/esm/receivers/sessionReceiver.js +69 -29
  157. package/dist/esm/receivers/sessionReceiver.js.map +1 -1
  158. package/dist/esm/sender.js +33 -11
  159. package/dist/esm/sender.js.map +1 -1
  160. package/dist/esm/serializers/queueResourceSerializer.js +9 -1
  161. package/dist/esm/serializers/queueResourceSerializer.js.map +1 -1
  162. package/dist/esm/serializers/ruleResourceSerializer.js +1 -2
  163. package/dist/esm/serializers/ruleResourceSerializer.js.map +1 -1
  164. package/dist/esm/serviceBusAtomManagementClient.js +181 -228
  165. package/dist/esm/serviceBusAtomManagementClient.js.map +1 -1
  166. package/dist/esm/serviceBusClient.js +31 -22
  167. package/dist/esm/serviceBusClient.js.map +1 -1
  168. package/dist/esm/serviceBusError.js +21 -1
  169. package/dist/esm/serviceBusError.js.map +1 -1
  170. package/dist/esm/serviceBusMessage.js +208 -13
  171. package/dist/esm/serviceBusMessage.js.map +1 -1
  172. package/dist/esm/serviceBusMessageBatch.js +32 -8
  173. package/dist/esm/serviceBusMessageBatch.js.map +1 -1
  174. package/dist/esm/serviceBusRuleManager.js +39 -15
  175. package/dist/esm/serviceBusRuleManager.js.map +1 -1
  176. package/dist/esm/session/messageSession.js +130 -25
  177. package/dist/esm/session/messageSession.js.map +1 -1
  178. package/dist/esm/util/atomXmlHelper.js +4 -5
  179. package/dist/esm/util/atomXmlHelper.js.map +1 -1
  180. package/dist/esm/util/compat/httpHeaders.js +1 -0
  181. package/dist/esm/util/compat/httpHeaders.js.map +1 -1
  182. package/dist/esm/util/constants.js +1 -1
  183. package/dist/esm/util/constants.js.map +1 -1
  184. package/dist/esm/util/runtimeInfo.js +1 -1
  185. package/dist/esm/util/runtimeInfo.js.map +1 -1
  186. package/dist/esm/util/sasServiceClientCredentials.js +8 -0
  187. package/dist/esm/util/sasServiceClientCredentials.js.map +1 -1
  188. package/dist/esm/util/semaphore.js +6 -2
  189. package/dist/esm/util/semaphore.js.map +1 -1
  190. package/dist/esm/util/utils.js +5 -7
  191. package/dist/esm/util/utils.js.map +1 -1
  192. package/dist/react-native/connectionContext.js +1 -2
  193. package/dist/react-native/connectionContext.js.map +1 -1
  194. package/dist/react-native/constructorHelpers.js +3 -4
  195. package/dist/react-native/constructorHelpers.js.map +1 -1
  196. package/dist/react-native/core/autoLockRenewer.js +9 -5
  197. package/dist/react-native/core/autoLockRenewer.js.map +1 -1
  198. package/dist/react-native/core/batchingReceiver.js +26 -18
  199. package/dist/react-native/core/batchingReceiver.js.map +1 -1
  200. package/dist/react-native/core/linkEntity.js +74 -13
  201. package/dist/react-native/core/linkEntity.js.map +1 -1
  202. package/dist/react-native/core/managementClient.js +48 -48
  203. package/dist/react-native/core/managementClient.js.map +1 -1
  204. package/dist/react-native/core/messageReceiver.js +41 -14
  205. package/dist/react-native/core/messageReceiver.js.map +1 -1
  206. package/dist/react-native/core/messageSender.js +33 -10
  207. package/dist/react-native/core/messageSender.js.map +1 -1
  208. package/dist/react-native/core/receiverHelper.js +3 -2
  209. package/dist/react-native/core/receiverHelper.js.map +1 -1
  210. package/dist/react-native/core/shared.js +11 -4
  211. package/dist/react-native/core/shared.js.map +1 -1
  212. package/dist/react-native/core/streamingReceiver.js +74 -43
  213. package/dist/react-native/core/streamingReceiver.js.map +1 -1
  214. package/dist/react-native/diagnostics/instrumentServiceBusMessage.js +16 -8
  215. package/dist/react-native/diagnostics/instrumentServiceBusMessage.js.map +1 -1
  216. package/dist/react-native/receivers/receiver.js +68 -23
  217. package/dist/react-native/receivers/receiver.js.map +1 -1
  218. package/dist/react-native/receivers/receiverCommon.js +36 -21
  219. package/dist/react-native/receivers/receiverCommon.js.map +1 -1
  220. package/dist/react-native/receivers/sessionReceiver.js +69 -29
  221. package/dist/react-native/receivers/sessionReceiver.js.map +1 -1
  222. package/dist/react-native/sender.js +33 -11
  223. package/dist/react-native/sender.js.map +1 -1
  224. package/dist/react-native/serializers/queueResourceSerializer.js +9 -1
  225. package/dist/react-native/serializers/queueResourceSerializer.js.map +1 -1
  226. package/dist/react-native/serializers/ruleResourceSerializer.js +1 -2
  227. package/dist/react-native/serializers/ruleResourceSerializer.js.map +1 -1
  228. package/dist/react-native/serviceBusAtomManagementClient.js +181 -228
  229. package/dist/react-native/serviceBusAtomManagementClient.js.map +1 -1
  230. package/dist/react-native/serviceBusClient.js +31 -22
  231. package/dist/react-native/serviceBusClient.js.map +1 -1
  232. package/dist/react-native/serviceBusError.js +21 -1
  233. package/dist/react-native/serviceBusError.js.map +1 -1
  234. package/dist/react-native/serviceBusMessage.js +208 -13
  235. package/dist/react-native/serviceBusMessage.js.map +1 -1
  236. package/dist/react-native/serviceBusMessageBatch.js +32 -8
  237. package/dist/react-native/serviceBusMessageBatch.js.map +1 -1
  238. package/dist/react-native/serviceBusRuleManager.js +39 -15
  239. package/dist/react-native/serviceBusRuleManager.js.map +1 -1
  240. package/dist/react-native/session/messageSession.js +130 -25
  241. package/dist/react-native/session/messageSession.js.map +1 -1
  242. package/dist/react-native/util/atomXmlHelper.js +4 -5
  243. package/dist/react-native/util/atomXmlHelper.js.map +1 -1
  244. package/dist/react-native/util/compat/httpHeaders.js +1 -0
  245. package/dist/react-native/util/compat/httpHeaders.js.map +1 -1
  246. package/dist/react-native/util/constants.js +1 -1
  247. package/dist/react-native/util/constants.js.map +1 -1
  248. package/dist/react-native/util/sasServiceClientCredentials.js +8 -0
  249. package/dist/react-native/util/sasServiceClientCredentials.js.map +1 -1
  250. package/dist/react-native/util/semaphore.js +6 -2
  251. package/dist/react-native/util/semaphore.js.map +1 -1
  252. package/dist/react-native/util/utils.js +5 -7
  253. package/dist/react-native/util/utils.js.map +1 -1
  254. package/package.json +38 -38
@@ -20,6 +20,67 @@ const tracing_js_1 = require("../diagnostics/tracing.js");
20
20
  * by providing handler functions.
21
21
  */
22
22
  class StreamingReceiver extends messageReceiver_js_1.MessageReceiver {
23
+ /**
24
+ * The maximum number of messages that should be
25
+ * processed concurrently while in streaming mode. Once this limit has been reached, more
26
+ * messages will not be received until the user's message handler has completed processing current message.
27
+ * Default: 1
28
+ */
29
+ maxConcurrentCalls = 1;
30
+ /**
31
+ * Indicates whether the receiver is already actively
32
+ * running `onDetached`.
33
+ * This is expected to be true while the receiver attempts
34
+ * to bring its link back up due to a retryable issue.
35
+ */
36
+ _isDetaching = false;
37
+ /**
38
+ *Retry policy options that determine the mode, number of retries, retry interval etc.
39
+ */
40
+ _retryOptions;
41
+ _receiverHelper;
42
+ /**
43
+ * The user's message handlers, wrapped so any thrown exceptions are properly logged
44
+ * or forwarded to the user's processError handler.
45
+ */
46
+ _messageHandlers = () => {
47
+ throw new Error("messageHandlers are not set.");
48
+ };
49
+ /**
50
+ * The subscribe(options) passed when the subscribe call originally happened. Stored
51
+ * so _subscribeImpl() can re-use them later if we have to restart our subscription
52
+ * when detach/reattaching.
53
+ */
54
+ _subscribeOptions;
55
+ /**
56
+ * Used so we can stub out retry in tests.
57
+ */
58
+ _retryForeverFn = receiverCommon_js_1.retryForever;
59
+ /**
60
+ * The message handler that will be set as the handler on the
61
+ * underlying rhea receiver for the "receiver_close" event.
62
+ */
63
+ _onAmqpClose;
64
+ /**
65
+ * The message handler that will be set as the handler on
66
+ * the underlying rhea receiver's session for the "session_close" event.
67
+ */
68
+ _onSessionClose;
69
+ /**
70
+ * The message handler that will be set as the handler on
71
+ * the underlying rhea receiver's session for the "session_error" event.
72
+ */
73
+ _onSessionError;
74
+ /**
75
+ * The message handler that will be set as the handler on the
76
+ * underlying rhea receiver for the "receiver_error" event.
77
+ */
78
+ _onAmqpError;
79
+ /**
80
+ * The message handler that will be set as the handler on the
81
+ * underlying rhea receiver for the "message" event.
82
+ */
83
+ _onAmqpMessage;
23
84
  /**
24
85
  * Whether we are currently subscribed (or subscribing) for receiving messages.
25
86
  * (this is irrespective of receiver state, etc... - it's just a simple flag to prevent
@@ -37,45 +98,19 @@ class StreamingReceiver extends messageReceiver_js_1.MessageReceiver {
37
98
  */
38
99
  constructor(identifier, connectionContext, entityPath, options) {
39
100
  super(identifier, connectionContext, entityPath, "streaming", options);
40
- /**
41
- * The maximum number of messages that should be
42
- * processed concurrently while in streaming mode. Once this limit has been reached, more
43
- * messages will not be received until the user's message handler has completed processing current message.
44
- * Default: 1
45
- */
46
- this.maxConcurrentCalls = 1;
47
- /**
48
- * Indicates whether the receiver is already actively
49
- * running `onDetached`.
50
- * This is expected to be true while the receiver attempts
51
- * to bring its link back up due to a retryable issue.
52
- */
53
- this._isDetaching = false;
54
- /**
55
- * The user's message handlers, wrapped so any thrown exceptions are properly logged
56
- * or forwarded to the user's processError handler.
57
- */
58
- this._messageHandlers = () => {
59
- throw new Error("messageHandlers are not set.");
60
- };
61
- /**
62
- * Used so we can stub out retry in tests.
63
- */
64
- this._retryForeverFn = receiverCommon_js_1.retryForever;
65
- if (typeof (options === null || options === void 0 ? void 0 : options.maxConcurrentCalls) === "number" && (options === null || options === void 0 ? void 0 : options.maxConcurrentCalls) > 0) {
101
+ if (typeof options?.maxConcurrentCalls === "number" && options?.maxConcurrentCalls > 0) {
66
102
  this.maxConcurrentCalls = options.maxConcurrentCalls;
67
103
  }
68
- this._retryOptions = (options === null || options === void 0 ? void 0 : options.retryOptions) || {};
104
+ this._retryOptions = options?.retryOptions || {};
69
105
  this._receiverHelper = new receiverHelper_js_1.ReceiverHelper(() => ({
70
106
  receiver: this.link,
71
107
  logPrefix: this.logPrefix,
72
108
  }));
73
109
  this._onAmqpClose = async (context) => {
74
- var _a;
75
110
  const receiverError = context.receiver && context.receiver.error;
76
111
  const receiver = this.link || context.receiver;
77
112
  log_js_1.receiverLogger.logError(receiverError, `${this.logPrefix} 'receiver_close' event occurred. The associated error is`);
78
- (_a = this._lockRenewer) === null || _a === void 0 ? void 0 : _a.stopAll(this);
113
+ this._lockRenewer?.stopAll(this);
79
114
  if (receiver && !receiver.isItselfClosed()) {
80
115
  await this.onDetached(receiverError);
81
116
  }
@@ -86,11 +121,10 @@ class StreamingReceiver extends messageReceiver_js_1.MessageReceiver {
86
121
  }
87
122
  };
88
123
  this._onSessionClose = async (context) => {
89
- var _a;
90
124
  const receiver = this.link || context.receiver;
91
125
  const sessionError = context.session && context.session.error;
92
126
  log_js_1.receiverLogger.logError(sessionError, `${this.logPrefix} 'session_close' event occurred. The associated error is`);
93
- (_a = this._lockRenewer) === null || _a === void 0 ? void 0 : _a.stopAll(this);
127
+ this._lockRenewer?.stopAll(this);
94
128
  if (receiver && !receiver.isSessionItselfClosed()) {
95
129
  await this.onDetached(sessionError);
96
130
  }
@@ -129,7 +163,6 @@ class StreamingReceiver extends messageReceiver_js_1.MessageReceiver {
129
163
  }
130
164
  };
131
165
  this._onAmqpMessage = async (context) => {
132
- var _a, _b, _c, _d;
133
166
  // If the receiver got closed in PeekLock mode, avoid processing the message as we
134
167
  // cannot settle the message.
135
168
  if (this.receiveMode === "peekLock" && (!this.link || !this.link.isOpen())) {
@@ -137,8 +170,8 @@ class StreamingReceiver extends messageReceiver_js_1.MessageReceiver {
137
170
  "as the receiver is closed", this.logPrefix);
138
171
  return;
139
172
  }
140
- const bMessage = new serviceBusMessage_js_1.ServiceBusMessageImpl(context.message, context.delivery, true, this.receiveMode, (_a = options.skipParsingBodyAsJson) !== null && _a !== void 0 ? _a : false, (_b = options.skipConvertingDate) !== null && _b !== void 0 ? _b : false);
141
- (_c = this._lockRenewer) === null || _c === void 0 ? void 0 : _c.start(this, bMessage, (err) => {
173
+ const bMessage = new serviceBusMessage_js_1.ServiceBusMessageImpl(context.message, context.delivery, true, this.receiveMode, options.skipParsingBodyAsJson ?? false, options.skipConvertingDate ?? false);
174
+ this._lockRenewer?.start(this, bMessage, (err) => {
142
175
  this._messageHandlers().processError({
143
176
  error: err,
144
177
  errorSource: "renewLock",
@@ -155,7 +188,7 @@ class StreamingReceiver extends messageReceiver_js_1.MessageReceiver {
155
188
  "with id '%s' on the receiver '%s'", this.logPrefix, bMessage.messageId, this.name);
156
189
  // Do not want renewLock to happen unnecessarily, while abandoning the message. Hence,
157
190
  // doing this here. Otherwise, this should be done in finally.
158
- (_d = this._lockRenewer) === null || _d === void 0 ? void 0 : _d.stop(this, bMessage);
191
+ this._lockRenewer?.stop(this, bMessage);
159
192
  const error = (0, serviceBusError_js_1.translateServiceBusError)(err);
160
193
  // Nothing much to do if user's message handler throws. Let us try abandoning the message.
161
194
  if (!bMessage.delivery.remote_settled &&
@@ -253,6 +286,7 @@ class StreamingReceiver extends messageReceiver_js_1.MessageReceiver {
253
286
  await this._receiverHelper.suspend();
254
287
  return super.close();
255
288
  }
289
+ _subscribeCallPromise;
256
290
  /**
257
291
  * Starts the receiver by establishing an AMQP session and an AMQP receiver link on the session.
258
292
  *
@@ -293,7 +327,7 @@ class StreamingReceiver extends messageReceiver_js_1.MessageReceiver {
293
327
  throw err;
294
328
  }
295
329
  finally {
296
- promiseResolve === null || promiseResolve === void 0 ? void 0 : promiseResolve();
330
+ promiseResolve?.();
297
331
  this._subscribeCallPromise = undefined;
298
332
  }
299
333
  }
@@ -305,7 +339,6 @@ class StreamingReceiver extends messageReceiver_js_1.MessageReceiver {
305
339
  * @param operationOptions - The subscribe(options)
306
340
  */
307
341
  _setMessageHandlers(userHandlers, operationOptions) {
308
- var _a;
309
342
  const messageHandlers = {
310
343
  processError: async (args) => {
311
344
  try {
@@ -319,7 +352,7 @@ class StreamingReceiver extends messageReceiver_js_1.MessageReceiver {
319
352
  },
320
353
  processMessage: async (message) => {
321
354
  try {
322
- await tracing_js_1.tracingClient.withSpan("StreamReceiver.process", operationOptions !== null && operationOptions !== void 0 ? operationOptions : {}, () => userHandlers.processMessage(message), (0, instrumentServiceBusMessage_js_1.toProcessingSpanOptions)(message, this, this._context.config, "process"));
355
+ await tracing_js_1.tracingClient.withSpan("StreamReceiver.process", operationOptions ?? {}, () => userHandlers.processMessage(message), (0, instrumentServiceBusMessage_js_1.toProcessingSpanOptions)(message, this, this._context.config, "process"));
323
356
  }
324
357
  catch (err) {
325
358
  this._messageHandlers().processError({
@@ -356,7 +389,7 @@ class StreamingReceiver extends messageReceiver_js_1.MessageReceiver {
356
389
  identifier: this.identifier,
357
390
  }));
358
391
  },
359
- forwardInternalErrors: (_a = userHandlers.forwardInternalErrors) !== null && _a !== void 0 ? _a : false,
392
+ forwardInternalErrors: userHandlers.forwardInternalErrors ?? false,
360
393
  };
361
394
  this._messageHandlers = () => messageHandlers;
362
395
  }
@@ -366,7 +399,6 @@ class StreamingReceiver extends messageReceiver_js_1.MessageReceiver {
366
399
  * @returns A promise that will resolve when a link is created and we successfully add credits to it.
367
400
  */
368
401
  async _subscribeImpl(caller) {
369
- var _a;
370
402
  try {
371
403
  // we don't expect to ever get an error from retryForever but bugs
372
404
  // do happen.
@@ -374,7 +406,7 @@ class StreamingReceiver extends messageReceiver_js_1.MessageReceiver {
374
406
  retryConfig: {
375
407
  connectionId: this._context.connection.id,
376
408
  operationType: core_amqp_1.RetryOperationType.receiverLink,
377
- abortSignal: (_a = this._subscribeOptions) === null || _a === void 0 ? void 0 : _a.abortSignal,
409
+ abortSignal: this._subscribeOptions?.abortSignal,
378
410
  retryOptions: this._retryOptions,
379
411
  operation: () => this._initAndAddCreditOperation(caller),
380
412
  },
@@ -407,7 +439,6 @@ class StreamingReceiver extends messageReceiver_js_1.MessageReceiver {
407
439
  * @param catchAndReportError - A function and reports an error but does not throw it.
408
440
  */
409
441
  async _initAndAddCreditOperation(caller) {
410
- var _a;
411
442
  if (this._receiverHelper.isSuspended()) {
412
443
  // user has suspended us while we were initializing
413
444
  // the connection. Abort this attempt - if they attempt
@@ -422,7 +453,7 @@ class StreamingReceiver extends messageReceiver_js_1.MessageReceiver {
422
453
  // Need to check again as user can suspend us in preInitialize()
423
454
  throw new abort_controller_1.AbortError("Receiver was suspended during initialization.");
424
455
  }
425
- await this._init(this._createReceiverOptions(caller === "detach", this._getHandlers()), (_a = this._subscribeOptions) === null || _a === void 0 ? void 0 : _a.abortSignal);
456
+ await this._init(this._createReceiverOptions(caller === "detach", this._getHandlers()), this._subscribeOptions?.abortSignal);
426
457
  try {
427
458
  await this._messageHandlers().postInitialize();
428
459
  this._receiverHelper.addCredit(this.maxConcurrentCalls);
@@ -1 +1 @@
1
- {"version":3,"file":"streamingReceiver.js","sourceRoot":"","sources":["../../../src/core/streamingReceiver.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAGlC,6DAAuD;AAGvD,2DAAqD;AAErD,iDAAiE;AAEjE,gDAAgF;AAEhF,sCAAqD;AAErD,kEAAgE;AAChE,8DAAiE;AACjE,sEAA+F;AAS/F,kGAAwF;AACxF,8DAAqD;AACrD,0DAA0D;AAW1D;;;;GAIG;AACH,MAAa,iBAAkB,SAAQ,oCAAe;IAwEpD;;;;OAIG;IACH,IAAW,iBAAiB;QAC1B,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,WAAW,EAAE,CAAC;IAC7C,CAAC;IAED;;;;;;OAMG;IACH,YACE,UAAkB,EAClB,iBAAoC,EACpC,UAAkB,EAClB,OAAuB;QAEvB,KAAK,CAAC,UA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F,mFAAmF;gBACnF,yCAAyC;gBACzC,gFAAgF;gBAChF,wDAAwD;gBACxD,2EAA2E;gBAC3E,gCAAgC;gBAChC,uBAAM,CAAC,OAAO,CACZ,GAAG,IAAI,CAAC,SAAS,wDAAwD,IAAI,CAAC,IAAI,2BAA2B,CAC9G,CAAC;gBACF,OAAO;YACT,CAAC;YAED,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;YAEzB,MAAM,eAAe,GAAG,aAAa;gBACnC,CAAC,CAAC,IAAA,6CAAwB,EAAC,aAAa,CAAC;gBACzC,CAAC,CAAC,aAAa,CAAC;YAClB,uBAAM,CAAC,QAAQ,CACb,eAAe,EACf,GAAG,IAAI,CAAC,SAAS,uDAAuD,CACzE,CAAC;YAEF,oFAAoF;YACpF,wEAAwE;YACxE,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC;QACzB,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,uBAAM,CAAC,OAAO,CACZ,GAAG,IAAI,CAAC,SAAS,oEAAoE,EACrF,GAAG,CACJ,CAAC;QACJ,CAAC;QAED,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QACtC,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;QAC5B,CAAC;IACH,CAAC;IAES,qBAAqB;QAC7B,OAAO,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnD,CAAC;CACF;AAjpBD,8CAipBC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { OnAmqpEventAsPromise, ReceiveOptions } from \"./messageReceiver.js\";\nimport { MessageReceiver } from \"./messageReceiver.js\";\nimport type { ConnectionContext } from \"../connectionContext.js\";\n\nimport { ReceiverHelper } from \"./receiverHelper.js\";\n\nimport { throwErrorIfConnectionClosed } from \"../util/errors.js\";\nimport type { MessagingError, RetryOptions } from \"@azure/core-amqp\";\nimport { RetryOperationType, ConditionErrorNameMapper } from \"@azure/core-amqp\";\nimport type { OperationOptionsBase } from \"../modelsToBeSharedWithEventHubs.js\";\nimport { receiverLogger as logger } from \"../log.js\";\nimport type { AmqpError, EventContext, OnAmqpEvent } from \"rhea-promise\";\nimport { ServiceBusMessageImpl } from \"../serviceBusMessage.js\";\nimport { translateServiceBusError } from \"../serviceBusError.js\";\nimport { abandonMessage, completeMessage, retryForever } from \"../receivers/receiverCommon.js\";\nimport type { ReceiverHandlers } from \"./shared.js\";\nimport type {\n InternalMessageHandlers,\n InternalProcessErrorArgs,\n MessageHandlers,\n ProcessErrorArgs,\n SubscribeOptions,\n} from \"../models.js\";\nimport { toProcessingSpanOptions } from \"../diagnostics/instrumentServiceBusMessage.js\";\nimport { AbortError } from \"@azure/abort-controller\";\nimport { tracingClient } from \"../diagnostics/tracing.js\";\n\n/**\n * @internal\n */\nexport interface StreamingReceiverInitArgs\n extends ReceiveOptions,\n Pick<OperationOptionsBase, \"abortSignal\"> {\n messageHandlers: MessageHandlers;\n}\n\n/**\n * @internal\n * Describes the streaming receiver where the user can receive the message\n * by providing handler functions.\n */\nexport class StreamingReceiver extends MessageReceiver {\n /**\n * The maximum number of messages that should be\n * processed concurrently while in streaming mode. Once this limit has been reached, more\n * messages will not be received until the user's message handler has completed processing current message.\n * Default: 1\n */\n maxConcurrentCalls: number = 1;\n\n /**\n * Indicates whether the receiver is already actively\n * running `onDetached`.\n * This is expected to be true while the receiver attempts\n * to bring its link back up due to a retryable issue.\n */\n private _isDetaching: boolean = false;\n /**\n *Retry policy options that determine the mode, number of retries, retry interval etc.\n */\n private _retryOptions: RetryOptions;\n\n private _receiverHelper: ReceiverHelper;\n\n /**\n * The user's message handlers, wrapped so any thrown exceptions are properly logged\n * or forwarded to the user's processError handler.\n */\n private _messageHandlers: () => Required<InternalMessageHandlers> = () => {\n throw new Error(\"messageHandlers are not set.\");\n };\n\n /**\n * The subscribe(options) passed when the subscribe call originally happened. Stored\n * so _subscribeImpl() can re-use them later if we have to restart our subscription\n * when detach/reattaching.\n */\n private _subscribeOptions: SubscribeOptions | undefined;\n\n /**\n * Used so we can stub out retry in tests.\n */\n private _retryForeverFn: typeof retryForever = retryForever;\n\n /**\n * The message handler that will be set as the handler on the\n * underlying rhea receiver for the \"receiver_close\" event.\n */\n private _onAmqpClose: OnAmqpEventAsPromise;\n\n /**\n * The message handler that will be set as the handler on\n * the underlying rhea receiver's session for the \"session_close\" event.\n */\n private _onSessionClose: OnAmqpEventAsPromise;\n\n /**\n * The message handler that will be set as the handler on\n * the underlying rhea receiver's session for the \"session_error\" event.\n */\n private _onSessionError: OnAmqpEvent;\n /**\n * The message handler that will be set as the handler on the\n * underlying rhea receiver for the \"receiver_error\" event.\n */\n private _onAmqpError: OnAmqpEvent;\n\n /**\n * The message handler that will be set as the handler on the\n * underlying rhea receiver for the \"message\" event.\n */\n protected _onAmqpMessage: OnAmqpEventAsPromise;\n\n /**\n * Whether we are currently subscribed (or subscribing) for receiving messages.\n * (this is irrespective of receiver state, etc... - it's just a simple flag to prevent\n * multiple subscribe() calls from happening on this instance)\n */\n public get isSubscribeActive(): boolean {\n return !this._receiverHelper.isSuspended();\n }\n\n /**\n * Instantiate a new Streaming receiver for receiving messages with handlers.\n *\n * @param identifier - the name used to identifier the receiver\n * @param connectionContext - The client entity context.\n * @param options - Options for how you'd like to connect.\n */\n constructor(\n identifier: string,\n connectionContext: ConnectionContext,\n entityPath: string,\n options: ReceiveOptions,\n ) {\n super(identifier, connectionContext, entityPath, \"streaming\", options);\n\n if (typeof options?.maxConcurrentCalls === \"number\" && options?.maxConcurrentCalls > 0) {\n this.maxConcurrentCalls = options.maxConcurrentCalls;\n }\n\n this._retryOptions = options?.retryOptions || {};\n\n this._receiverHelper = new ReceiverHelper(() => ({\n receiver: this.link,\n logPrefix: this.logPrefix,\n }));\n\n this._onAmqpClose = async (context: EventContext) => {\n const receiverError = context.receiver && context.receiver.error;\n const receiver = this.link || context.receiver!;\n\n logger.logError(\n receiverError,\n `${this.logPrefix} 'receiver_close' event occurred. The associated error is`,\n );\n\n this._lockRenewer?.stopAll(this);\n\n if (receiver && !receiver.isItselfClosed()) {\n await this.onDetached(receiverError);\n } else {\n logger.verbose(\n \"%s 'receiver_close' event occurred on the receiver '%s' with address '%s' \" +\n \"because the sdk initiated it. Hence not calling detached from the _onAmqpClose\" +\n \"() handler.\",\n this.logPrefix,\n this.name,\n this.address,\n );\n }\n };\n\n this._onSessionClose = async (context: EventContext) => {\n const receiver = this.link || context.receiver!;\n const sessionError = context.session && context.session.error;\n\n logger.logError(\n sessionError,\n `${this.logPrefix} 'session_close' event occurred. The associated error is`,\n );\n\n this._lockRenewer?.stopAll(this);\n\n if (receiver && !receiver.isSessionItselfClosed()) {\n await this.onDetached(sessionError);\n } else {\n logger.verbose(\n \"%s 'session_close' event occurred on the session of receiver '%s' with address \" +\n \"'%s' because the sdk initiated it. Hence not calling detached from the _onSessionClose\" +\n \"() handler.\",\n this.logPrefix,\n this.name,\n this.address,\n );\n }\n };\n\n this._onAmqpError = (context: EventContext) => {\n const receiverError = context.receiver && context.receiver.error;\n if (receiverError) {\n const sbError = translateServiceBusError(receiverError) as MessagingError;\n logger.logError(\n sbError,\n `${this.logPrefix} 'receiver_error' event occurred. The associated error is`,\n );\n this._messageHandlers().processError({\n error: sbError,\n errorSource: \"receive\",\n entityPath: this.entityPath,\n fullyQualifiedNamespace: this._context.config.host,\n identifier,\n });\n }\n };\n\n this._onSessionError = (context: EventContext) => {\n const sessionError = context.session && context.session.error;\n if (sessionError) {\n const sbError = translateServiceBusError(sessionError) as MessagingError;\n logger.logError(\n sbError,\n `${this.logPrefix} 'session_error' event occurred. The associated error is`,\n );\n this._messageHandlers().processError({\n error: sbError,\n errorSource: \"receive\",\n entityPath: this.entityPath,\n fullyQualifiedNamespace: this._context.config.host,\n identifier,\n });\n }\n };\n\n this._onAmqpMessage = async (context: EventContext) => {\n // If the receiver got closed in PeekLock mode, avoid processing the message as we\n // cannot settle the message.\n if (this.receiveMode === \"peekLock\" && (!this.link || !this.link.isOpen())) {\n logger.verbose(\n \"%s Not calling the user's message handler for the current message \" +\n \"as the receiver is closed\",\n this.logPrefix,\n );\n return;\n }\n\n const bMessage: ServiceBusMessageImpl = new ServiceBusMessageImpl(\n context.message!,\n context.delivery!,\n true,\n this.receiveMode,\n options.skipParsingBodyAsJson ?? false,\n options.skipConvertingDate ?? false,\n );\n\n this._lockRenewer?.start(this, bMessage, (err) => {\n this._messageHandlers().processError({\n error: err,\n errorSource: \"renewLock\",\n entityPath: this.entityPath,\n fullyQualifiedNamespace: this._context.config.host,\n identifier,\n });\n });\n\n try {\n await this._messageHandlers().processMessage(bMessage);\n } catch (err: any) {\n logger.logError(\n err,\n \"%s An error occurred while running user's message handler for the message \" +\n \"with id '%s' on the receiver '%s'\",\n this.logPrefix,\n bMessage.messageId,\n this.name,\n );\n\n // Do not want renewLock to happen unnecessarily, while abandoning the message. Hence,\n // doing this here. Otherwise, this should be done in finally.\n this._lockRenewer?.stop(this, bMessage);\n const error = translateServiceBusError(err) as MessagingError;\n // Nothing much to do if user's message handler throws. Let us try abandoning the message.\n if (\n !bMessage.delivery.remote_settled &&\n error.code !== ConditionErrorNameMapper[\"com.microsoft:message-lock-lost\"] &&\n this.receiveMode === \"peekLock\" &&\n this.isOpen() // only try to abandon the messages if the connection is still open\n ) {\n try {\n logger.logError(\n error,\n \"%s Abandoning the message with id '%s' on the receiver '%s' since \" +\n \"an error occured: %O.\",\n this.logPrefix,\n bMessage.messageId,\n this.name,\n error,\n );\n await abandonMessage(\n bMessage,\n this._context,\n entityPath,\n undefined,\n this._retryOptions,\n );\n } catch (abandonError: any) {\n const translatedError = translateServiceBusError(abandonError);\n logger.logError(\n translatedError,\n \"%s An error occurred while abandoning the message with id '%s' on the \" +\n \"receiver '%s'\",\n this.logPrefix,\n bMessage.messageId,\n this.name,\n );\n this._messageHandlers().processError({\n error: translatedError,\n errorSource: \"abandon\",\n entityPath: this.entityPath,\n fullyQualifiedNamespace: this._context.config.host,\n identifier,\n });\n }\n }\n return;\n } finally {\n try {\n this._receiverHelper.addCredit(1);\n } catch (err: any) {\n // if we're aborting out of the receive operation we don't need to report it (the user already\n // knows the link is being torn down or stopped)\n if (err.name !== \"AbortError\") {\n logger.logError(\n err,\n `[${this.logPrefix}] Failed to add credit after receiving message`,\n );\n await this._reportInternalError(err);\n }\n }\n }\n\n // If we've made it this far, then user's message handler completed fine. Let us try\n // completing the message.\n if (\n this.autoComplete &&\n this.receiveMode === \"peekLock\" &&\n !bMessage.delivery.remote_settled\n ) {\n try {\n logger.verbose(\n \"%s Auto completing the message with id '%s' on \" + \"the receiver.\",\n this.logPrefix,\n bMessage.messageId,\n );\n await completeMessage(bMessage, this._context, entityPath, this._retryOptions);\n } catch (completeError: any) {\n const translatedError = translateServiceBusError(completeError);\n logger.logError(\n translatedError,\n \"%s An error occurred while completing the message with id '%s' on the \" +\n \"receiver '%s'\",\n this.logPrefix,\n bMessage.messageId,\n this.name,\n );\n this._messageHandlers().processError({\n error: translatedError,\n errorSource: \"complete\",\n entityPath: this.entityPath,\n fullyQualifiedNamespace: this._context.config.host,\n identifier,\n });\n }\n }\n };\n }\n\n private _reportInternalError(error: Error): Promise<void> {\n const messageHandlers = this._messageHandlers();\n\n if (messageHandlers.forwardInternalErrors) {\n const errorArgs: InternalProcessErrorArgs = {\n error,\n entityPath: this.entityPath,\n errorSource: \"internal\",\n fullyQualifiedNamespace: this._context.config.host,\n identifier: this.identifier,\n };\n\n return messageHandlers.processError(errorArgs as ProcessErrorArgs);\n }\n\n return Promise.resolve();\n }\n\n private _getHandlers(): ReceiverHandlers {\n return {\n onMessage: (context: EventContext) =>\n this._onAmqpMessage(context).catch((err) => this._reportInternalError(err)),\n onClose: (context: EventContext) =>\n this._onAmqpClose(context).catch((err) => this._reportInternalError(err)),\n onSessionClose: (context: EventContext) =>\n this._onSessionClose(context).catch((err) => this._reportInternalError(err)),\n onError: this._onAmqpError,\n onSessionError: this._onSessionError,\n };\n }\n\n async stopReceivingMessages(): Promise<void> {\n await this._receiverHelper.suspend();\n\n if (this._subscribeCallPromise) {\n await this._subscribeCallPromise;\n }\n }\n\n async close(): Promise<void> {\n await this._receiverHelper.suspend();\n return super.close();\n }\n\n private _subscribeCallPromise: Promise<void> | undefined;\n\n /**\n * Starts the receiver by establishing an AMQP session and an AMQP receiver link on the session.\n *\n * Any errors thrown by this function will also be sent to the messageHandlers.processError function\n * _and_ thrown, ultimately from this method.\n *\n * NOTE: This function retries _infinitely_ until success! It is completely up to the user to break\n * out of this retry cycle otherwise by:\n * 1. closing the receiver\n * 2. Calling `close` on the subscription instance they received when they initially called subscribe().\n * 3. aborting the abortSignal they passed in when calling subscribe (this also applies to initialization calls in onDetach)\n *\n * @param onMessage - The message handler to receive servicebus messages.\n * @param onError - The error handler to receive an error that occurs while receivin messages.\n */\n async subscribe(\n messageHandlers: InternalMessageHandlers,\n subscribeOptions: SubscribeOptions | undefined,\n ): Promise<void> {\n // these options and message handlers will be re-used if/when onDetach is called.\n this._subscribeOptions = subscribeOptions;\n this._setMessageHandlers(messageHandlers, subscribeOptions);\n\n let promiseResolve: (() => void) | undefined;\n this._subscribeCallPromise = new Promise((resolve) => {\n promiseResolve = resolve;\n });\n\n try {\n this._receiverHelper.resume();\n return await this._subscribeImpl(\"subscribe\");\n } catch (err: any) {\n // callers aren't going to be in a good position to forward this error properly\n // so we do it here.\n await this._messageHandlers().processError({\n entityPath: this.entityPath,\n fullyQualifiedNamespace: this._context.config.host,\n errorSource: \"receive\",\n error: err,\n identifier: this.identifier,\n });\n\n throw err;\n } finally {\n promiseResolve?.();\n this._subscribeCallPromise = undefined;\n }\n }\n\n /**\n * Wraps the individual message handlers with tracing and proper error handling\n * and assigns them to `this._messageHandlers`\n *\n * @param userHandlers - The user's message handlers\n * @param operationOptions - The subscribe(options)\n */\n private _setMessageHandlers(\n userHandlers: InternalMessageHandlers,\n operationOptions: OperationOptionsBase | undefined,\n ): void {\n const messageHandlers = {\n processError: async (args: ProcessErrorArgs) => {\n try {\n args.error = translateServiceBusError(args.error);\n await userHandlers.processError(args);\n } catch (err: any) {\n await this._reportInternalError(err);\n logger.logError(err, `An error was thrown from the user's processError handler`);\n }\n },\n processMessage: async (message: ServiceBusMessageImpl) => {\n try {\n await tracingClient.withSpan(\n \"StreamReceiver.process\",\n operationOptions ?? {},\n () => userHandlers.processMessage(message),\n toProcessingSpanOptions(message, this, this._context.config, \"process\"),\n );\n } catch (err: any) {\n this._messageHandlers().processError({\n error: err,\n errorSource: \"processMessageCallback\",\n entityPath: this.entityPath,\n fullyQualifiedNamespace: this._context.config.host,\n identifier: this.identifier,\n });\n throw err;\n }\n },\n postInitialize: async () => {\n if (!userHandlers.postInitialize) {\n return;\n }\n\n return userHandlers.postInitialize().catch((err) =>\n this._messageHandlers().processError({\n error: err,\n errorSource: \"processMessageCallback\",\n entityPath: this.entityPath,\n fullyQualifiedNamespace: this._context.config.host,\n identifier: this.identifier,\n }),\n );\n },\n preInitialize: async () => {\n if (!userHandlers.preInitialize) {\n return;\n }\n\n return userHandlers.preInitialize().catch((err) =>\n this._messageHandlers().processError({\n error: err,\n errorSource: \"processMessageCallback\",\n entityPath: this.entityPath,\n fullyQualifiedNamespace: this._context.config.host,\n identifier: this.identifier,\n }),\n );\n },\n forwardInternalErrors: userHandlers.forwardInternalErrors ?? false,\n };\n\n this._messageHandlers = () => messageHandlers;\n }\n\n /**\n * Subscribes using the already assigned `this._messageHandlers` and `this._subscribeOptions`\n *\n * @returns A promise that will resolve when a link is created and we successfully add credits to it.\n */\n private async _subscribeImpl(caller: \"detach\" | \"subscribe\"): Promise<void> {\n try {\n // we don't expect to ever get an error from retryForever but bugs\n // do happen.\n return await this._retryForeverFn({\n retryConfig: {\n connectionId: this._context.connection.id,\n operationType: RetryOperationType.receiverLink,\n abortSignal: this._subscribeOptions?.abortSignal,\n retryOptions: this._retryOptions,\n operation: () => this._initAndAddCreditOperation(caller),\n },\n onError: (err) =>\n this._messageHandlers().processError({\n error: err,\n errorSource: \"receive\",\n entityPath: this.entityPath,\n fullyQualifiedNamespace: this._context.config.host,\n identifier: this.identifier,\n }),\n logPrefix: this.logPrefix,\n logger,\n });\n } catch (err: any) {\n try {\n await this._receiverHelper.suspend();\n } catch (error: any) {\n logger.logError(error, `${this.logPrefix} receiver.suspend threw an error`);\n }\n\n throw err;\n }\n }\n\n /**\n * Initializes the link and adds credits. If any of these operations fail any created link will\n * be closed.\n *\n * @param caller - The caller which dictates whether or not we create a new name for our created link.\n * @param catchAndReportError - A function and reports an error but does not throw it.\n */\n private async _initAndAddCreditOperation(caller: \"detach\" | \"subscribe\"): Promise<void> {\n if (this._receiverHelper.isSuspended()) {\n // user has suspended us while we were initializing\n // the connection. Abort this attempt - if they attempt\n // resubscribe we'll just reinitialize.\n // This checks should happen before throwErrorIfConnectionClosed(); otherwise\n // we won't be able to break out of the retry-for-ever loops when user suspend us.\n throw new AbortError(\"Receiver was suspended during initialization.\");\n }\n\n throwErrorIfConnectionClosed(this._context);\n\n await this._messageHandlers().preInitialize();\n\n if (this._receiverHelper.isSuspended()) {\n // Need to check again as user can suspend us in preInitialize()\n throw new AbortError(\"Receiver was suspended during initialization.\");\n }\n await this._init(\n this._createReceiverOptions(caller === \"detach\", this._getHandlers()),\n this._subscribeOptions?.abortSignal,\n );\n\n try {\n await this._messageHandlers().postInitialize();\n this._receiverHelper.addCredit(this.maxConcurrentCalls);\n } catch (err: any) {\n try {\n await this.closeLink();\n } catch (error: any) {\n await this._messageHandlers().processError({\n error,\n errorSource: \"receive\",\n entityPath: this.entityPath,\n fullyQualifiedNamespace: this._context.config.host,\n identifier: this.identifier,\n });\n }\n throw err;\n }\n }\n\n /**\n * Will reconnect the receiver link if necessary.\n * @param receiverError - The receiver error or connection error, if any.\n */\n async onDetached(receiverError?: AmqpError | Error): Promise<void> {\n try {\n logger.verbose(`${this.logPrefix} onDetached: reinitializing link.`);\n\n // User explicitly called `close` on the receiver, so link is already closed\n // and we can exit early.\n if (this.wasClosedPermanently) {\n logger.verbose(\n `${this.logPrefix} onDetached: link has been closed permanently, not reinitializing. `,\n );\n return;\n }\n\n // Prevent multiple onDetached invocations from running concurrently.\n if (this._isDetaching) {\n // This can happen when the network connection goes down for some amount of time.\n // The first connection `disconnect` will trigger `onDetached` and attempt to retry\n // creating the connection/receiver link.\n // While those retry attempts fail (until the network connection comes back up),\n // we'll continue to see connection `disconnect` errors.\n // These should be ignored until the already running `onDetached` completes\n // its retry attempts or errors.\n logger.verbose(\n `${this.logPrefix} onDetached: Call to detached on streaming receiver '${this.name}' is already in progress.`,\n );\n return;\n }\n\n this._isDetaching = true;\n\n const translatedError = receiverError\n ? translateServiceBusError(receiverError)\n : receiverError;\n logger.logError(\n translatedError,\n `${this.logPrefix} onDetached: Reinitializing receiver because of error`,\n );\n\n // Clears the token renewal timer. Closes the link and its session if they are open.\n // Removes the link and its session if they are present in rhea's cache.\n await this.closeLink();\n } catch (err: any) {\n logger.verbose(\n `${this.logPrefix} onDetached: Encountered an error when closing the previous link: `,\n err,\n );\n }\n\n try {\n await this._subscribeImpl(\"detach\");\n } finally {\n this._isDetaching = false;\n }\n }\n\n protected removeLinkFromContext(): void {\n delete this._context.messageReceivers[this.name];\n }\n}\n"]}
1
+ {"version":3,"file":"streamingReceiver.js","sourceRoot":"","sources":["../../../src/core/streamingReceiver.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAGlC,6DAAuD;AAGvD,2DAAqD;AAErD,iDAAiE;AAEjE,gDAAgF;AAEhF,sCAAqD;AAErD,kEAAgE;AAChE,8DAAiE;AACjE,sEAA+F;AAS/F,kGAAwF;AACxF,8DAAqD;AACrD,0DAA0D;AAW1D;;;;GAIG;AACH,MAAa,iBAAkB,SAAQ,oCAAe;IACpD;;;;;OAKG;IACH,kBAAkB,GAAW,CAAC,CAAC;IAE/B;;;;;OAKG;IACK,YAAY,GAAY,KAAK,CAAC;IACtC;;OAEG;IACK,aA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IAAI,CAAC,SAAS,qEAAqE,CACvF,CAAC;gBACF,OAAO;YACT,CAAC;YAED,qEAAqE;YACrE,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;gBACtB,iFAAiF;gBACjF,mFAAmF;gBACnF,yCAAyC;gBACzC,gFAAgF;gBAChF,wDAAwD;gBACxD,2EAA2E;gBAC3E,gCAAgC;gBAChC,uBAAM,CAAC,OAAO,CACZ,GAAG,IAAI,CAAC,SAAS,wDAAwD,IAAI,CAAC,IAAI,2BAA2B,CAC9G,CAAC;gBACF,OAAO;YACT,CAAC;YAED,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;YAEzB,MAAM,eAAe,GAAG,aAAa;gBACnC,CAAC,CAAC,IAAA,6CAAwB,EAAC,aAAa,CAAC;gBACzC,CAAC,CAAC,aAAa,CAAC;YAClB,uBAAM,CAAC,QAAQ,CACb,eAAe,EACf,GAAG,IAAI,CAAC,SAAS,uDAAuD,CACzE,CAAC;YAEF,oFAAoF;YACpF,wEAAwE;YACxE,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC;QACzB,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,uBAAM,CAAC,OAAO,CACZ,GAAG,IAAI,CAAC,SAAS,oEAAoE,EACrF,GAAG,CACJ,CAAC;QACJ,CAAC;QAED,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QACtC,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;QAC5B,CAAC;IACH,CAAC;IAES,qBAAqB;QAC7B,OAAO,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnD,CAAC;CACF;AAjpBD,8CAipBC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { OnAmqpEventAsPromise, ReceiveOptions } from \"./messageReceiver.js\";\nimport { MessageReceiver } from \"./messageReceiver.js\";\nimport type { ConnectionContext } from \"../connectionContext.js\";\n\nimport { ReceiverHelper } from \"./receiverHelper.js\";\n\nimport { throwErrorIfConnectionClosed } from \"../util/errors.js\";\nimport type { MessagingError, RetryOptions } from \"@azure/core-amqp\";\nimport { RetryOperationType, ConditionErrorNameMapper } from \"@azure/core-amqp\";\nimport type { OperationOptionsBase } from \"../modelsToBeSharedWithEventHubs.js\";\nimport { receiverLogger as logger } from \"../log.js\";\nimport type { AmqpError, EventContext, OnAmqpEvent } from \"rhea-promise\";\nimport { ServiceBusMessageImpl } from \"../serviceBusMessage.js\";\nimport { translateServiceBusError } from \"../serviceBusError.js\";\nimport { abandonMessage, completeMessage, retryForever } from \"../receivers/receiverCommon.js\";\nimport type { ReceiverHandlers } from \"./shared.js\";\nimport type {\n InternalMessageHandlers,\n InternalProcessErrorArgs,\n MessageHandlers,\n ProcessErrorArgs,\n SubscribeOptions,\n} from \"../models.js\";\nimport { toProcessingSpanOptions } from \"../diagnostics/instrumentServiceBusMessage.js\";\nimport { AbortError } from \"@azure/abort-controller\";\nimport { tracingClient } from \"../diagnostics/tracing.js\";\n\n/**\n * @internal\n */\nexport interface StreamingReceiverInitArgs\n extends ReceiveOptions,\n Pick<OperationOptionsBase, \"abortSignal\"> {\n messageHandlers: MessageHandlers;\n}\n\n/**\n * @internal\n * Describes the streaming receiver where the user can receive the message\n * by providing handler functions.\n */\nexport class StreamingReceiver extends MessageReceiver {\n /**\n * The maximum number of messages that should be\n * processed concurrently while in streaming mode. Once this limit has been reached, more\n * messages will not be received until the user's message handler has completed processing current message.\n * Default: 1\n */\n maxConcurrentCalls: number = 1;\n\n /**\n * Indicates whether the receiver is already actively\n * running `onDetached`.\n * This is expected to be true while the receiver attempts\n * to bring its link back up due to a retryable issue.\n */\n private _isDetaching: boolean = false;\n /**\n *Retry policy options that determine the mode, number of retries, retry interval etc.\n */\n private _retryOptions: RetryOptions;\n\n private _receiverHelper: ReceiverHelper;\n\n /**\n * The user's message handlers, wrapped so any thrown exceptions are properly logged\n * or forwarded to the user's processError handler.\n */\n private _messageHandlers: () => Required<InternalMessageHandlers> = () => {\n throw new Error(\"messageHandlers are not set.\");\n };\n\n /**\n * The subscribe(options) passed when the subscribe call originally happened. Stored\n * so _subscribeImpl() can re-use them later if we have to restart our subscription\n * when detach/reattaching.\n */\n private _subscribeOptions: SubscribeOptions | undefined;\n\n /**\n * Used so we can stub out retry in tests.\n */\n private _retryForeverFn: typeof retryForever = retryForever;\n\n /**\n * The message handler that will be set as the handler on the\n * underlying rhea receiver for the \"receiver_close\" event.\n */\n private _onAmqpClose: OnAmqpEventAsPromise;\n\n /**\n * The message handler that will be set as the handler on\n * the underlying rhea receiver's session for the \"session_close\" event.\n */\n private _onSessionClose: OnAmqpEventAsPromise;\n\n /**\n * The message handler that will be set as the handler on\n * the underlying rhea receiver's session for the \"session_error\" event.\n */\n private _onSessionError: OnAmqpEvent;\n /**\n * The message handler that will be set as the handler on the\n * underlying rhea receiver for the \"receiver_error\" event.\n */\n private _onAmqpError: OnAmqpEvent;\n\n /**\n * The message handler that will be set as the handler on the\n * underlying rhea receiver for the \"message\" event.\n */\n protected _onAmqpMessage: OnAmqpEventAsPromise;\n\n /**\n * Whether we are currently subscribed (or subscribing) for receiving messages.\n * (this is irrespective of receiver state, etc... - it's just a simple flag to prevent\n * multiple subscribe() calls from happening on this instance)\n */\n public get isSubscribeActive(): boolean {\n return !this._receiverHelper.isSuspended();\n }\n\n /**\n * Instantiate a new Streaming receiver for receiving messages with handlers.\n *\n * @param identifier - the name used to identifier the receiver\n * @param connectionContext - The client entity context.\n * @param options - Options for how you'd like to connect.\n */\n constructor(\n identifier: string,\n connectionContext: ConnectionContext,\n entityPath: string,\n options: ReceiveOptions,\n ) {\n super(identifier, connectionContext, entityPath, \"streaming\", options);\n\n if (typeof options?.maxConcurrentCalls === \"number\" && options?.maxConcurrentCalls > 0) {\n this.maxConcurrentCalls = options.maxConcurrentCalls;\n }\n\n this._retryOptions = options?.retryOptions || {};\n\n this._receiverHelper = new ReceiverHelper(() => ({\n receiver: this.link,\n logPrefix: this.logPrefix,\n }));\n\n this._onAmqpClose = async (context: EventContext) => {\n const receiverError = context.receiver && context.receiver.error;\n const receiver = this.link || context.receiver!;\n\n logger.logError(\n receiverError,\n `${this.logPrefix} 'receiver_close' event occurred. The associated error is`,\n );\n\n this._lockRenewer?.stopAll(this);\n\n if (receiver && !receiver.isItselfClosed()) {\n await this.onDetached(receiverError);\n } else {\n logger.verbose(\n \"%s 'receiver_close' event occurred on the receiver '%s' with address '%s' \" +\n \"because the sdk initiated it. Hence not calling detached from the _onAmqpClose\" +\n \"() handler.\",\n this.logPrefix,\n this.name,\n this.address,\n );\n }\n };\n\n this._onSessionClose = async (context: EventContext) => {\n const receiver = this.link || context.receiver!;\n const sessionError = context.session && context.session.error;\n\n logger.logError(\n sessionError,\n `${this.logPrefix} 'session_close' event occurred. The associated error is`,\n );\n\n this._lockRenewer?.stopAll(this);\n\n if (receiver && !receiver.isSessionItselfClosed()) {\n await this.onDetached(sessionError);\n } else {\n logger.verbose(\n \"%s 'session_close' event occurred on the session of receiver '%s' with address \" +\n \"'%s' because the sdk initiated it. Hence not calling detached from the _onSessionClose\" +\n \"() handler.\",\n this.logPrefix,\n this.name,\n this.address,\n );\n }\n };\n\n this._onAmqpError = (context: EventContext) => {\n const receiverError = context.receiver && context.receiver.error;\n if (receiverError) {\n const sbError = translateServiceBusError(receiverError) as MessagingError;\n logger.logError(\n sbError,\n `${this.logPrefix} 'receiver_error' event occurred. The associated error is`,\n );\n this._messageHandlers().processError({\n error: sbError,\n errorSource: \"receive\",\n entityPath: this.entityPath,\n fullyQualifiedNamespace: this._context.config.host,\n identifier,\n });\n }\n };\n\n this._onSessionError = (context: EventContext) => {\n const sessionError = context.session && context.session.error;\n if (sessionError) {\n const sbError = translateServiceBusError(sessionError) as MessagingError;\n logger.logError(\n sbError,\n `${this.logPrefix} 'session_error' event occurred. The associated error is`,\n );\n this._messageHandlers().processError({\n error: sbError,\n errorSource: \"receive\",\n entityPath: this.entityPath,\n fullyQualifiedNamespace: this._context.config.host,\n identifier,\n });\n }\n };\n\n this._onAmqpMessage = async (context: EventContext) => {\n // If the receiver got closed in PeekLock mode, avoid processing the message as we\n // cannot settle the message.\n if (this.receiveMode === \"peekLock\" && (!this.link || !this.link.isOpen())) {\n logger.verbose(\n \"%s Not calling the user's message handler for the current message \" +\n \"as the receiver is closed\",\n this.logPrefix,\n );\n return;\n }\n\n const bMessage: ServiceBusMessageImpl = new ServiceBusMessageImpl(\n context.message!,\n context.delivery!,\n true,\n this.receiveMode,\n options.skipParsingBodyAsJson ?? false,\n options.skipConvertingDate ?? false,\n );\n\n this._lockRenewer?.start(this, bMessage, (err) => {\n this._messageHandlers().processError({\n error: err,\n errorSource: \"renewLock\",\n entityPath: this.entityPath,\n fullyQualifiedNamespace: this._context.config.host,\n identifier,\n });\n });\n\n try {\n await this._messageHandlers().processMessage(bMessage);\n } catch (err: any) {\n logger.logError(\n err,\n \"%s An error occurred while running user's message handler for the message \" +\n \"with id '%s' on the receiver '%s'\",\n this.logPrefix,\n bMessage.messageId,\n this.name,\n );\n\n // Do not want renewLock to happen unnecessarily, while abandoning the message. Hence,\n // doing this here. Otherwise, this should be done in finally.\n this._lockRenewer?.stop(this, bMessage);\n const error = translateServiceBusError(err) as MessagingError;\n // Nothing much to do if user's message handler throws. Let us try abandoning the message.\n if (\n !bMessage.delivery.remote_settled &&\n error.code !== ConditionErrorNameMapper[\"com.microsoft:message-lock-lost\"] &&\n this.receiveMode === \"peekLock\" &&\n this.isOpen() // only try to abandon the messages if the connection is still open\n ) {\n try {\n logger.logError(\n error,\n \"%s Abandoning the message with id '%s' on the receiver '%s' since \" +\n \"an error occured: %O.\",\n this.logPrefix,\n bMessage.messageId,\n this.name,\n error,\n );\n await abandonMessage(\n bMessage,\n this._context,\n entityPath,\n undefined,\n this._retryOptions,\n );\n } catch (abandonError: any) {\n const translatedError = translateServiceBusError(abandonError);\n logger.logError(\n translatedError,\n \"%s An error occurred while abandoning the message with id '%s' on the \" +\n \"receiver '%s'\",\n this.logPrefix,\n bMessage.messageId,\n this.name,\n );\n this._messageHandlers().processError({\n error: translatedError,\n errorSource: \"abandon\",\n entityPath: this.entityPath,\n fullyQualifiedNamespace: this._context.config.host,\n identifier,\n });\n }\n }\n return;\n } finally {\n try {\n this._receiverHelper.addCredit(1);\n } catch (err: any) {\n // if we're aborting out of the receive operation we don't need to report it (the user already\n // knows the link is being torn down or stopped)\n if (err.name !== \"AbortError\") {\n logger.logError(\n err,\n `[${this.logPrefix}] Failed to add credit after receiving message`,\n );\n await this._reportInternalError(err);\n }\n }\n }\n\n // If we've made it this far, then user's message handler completed fine. Let us try\n // completing the message.\n if (\n this.autoComplete &&\n this.receiveMode === \"peekLock\" &&\n !bMessage.delivery.remote_settled\n ) {\n try {\n logger.verbose(\n \"%s Auto completing the message with id '%s' on \" + \"the receiver.\",\n this.logPrefix,\n bMessage.messageId,\n );\n await completeMessage(bMessage, this._context, entityPath, this._retryOptions);\n } catch (completeError: any) {\n const translatedError = translateServiceBusError(completeError);\n logger.logError(\n translatedError,\n \"%s An error occurred while completing the message with id '%s' on the \" +\n \"receiver '%s'\",\n this.logPrefix,\n bMessage.messageId,\n this.name,\n );\n this._messageHandlers().processError({\n error: translatedError,\n errorSource: \"complete\",\n entityPath: this.entityPath,\n fullyQualifiedNamespace: this._context.config.host,\n identifier,\n });\n }\n }\n };\n }\n\n private _reportInternalError(error: Error): Promise<void> {\n const messageHandlers = this._messageHandlers();\n\n if (messageHandlers.forwardInternalErrors) {\n const errorArgs: InternalProcessErrorArgs = {\n error,\n entityPath: this.entityPath,\n errorSource: \"internal\",\n fullyQualifiedNamespace: this._context.config.host,\n identifier: this.identifier,\n };\n\n return messageHandlers.processError(errorArgs as ProcessErrorArgs);\n }\n\n return Promise.resolve();\n }\n\n private _getHandlers(): ReceiverHandlers {\n return {\n onMessage: (context: EventContext) =>\n this._onAmqpMessage(context).catch((err) => this._reportInternalError(err)),\n onClose: (context: EventContext) =>\n this._onAmqpClose(context).catch((err) => this._reportInternalError(err)),\n onSessionClose: (context: EventContext) =>\n this._onSessionClose(context).catch((err) => this._reportInternalError(err)),\n onError: this._onAmqpError,\n onSessionError: this._onSessionError,\n };\n }\n\n async stopReceivingMessages(): Promise<void> {\n await this._receiverHelper.suspend();\n\n if (this._subscribeCallPromise) {\n await this._subscribeCallPromise;\n }\n }\n\n async close(): Promise<void> {\n await this._receiverHelper.suspend();\n return super.close();\n }\n\n private _subscribeCallPromise: Promise<void> | undefined;\n\n /**\n * Starts the receiver by establishing an AMQP session and an AMQP receiver link on the session.\n *\n * Any errors thrown by this function will also be sent to the messageHandlers.processError function\n * _and_ thrown, ultimately from this method.\n *\n * NOTE: This function retries _infinitely_ until success! It is completely up to the user to break\n * out of this retry cycle otherwise by:\n * 1. closing the receiver\n * 2. Calling `close` on the subscription instance they received when they initially called subscribe().\n * 3. aborting the abortSignal they passed in when calling subscribe (this also applies to initialization calls in onDetach)\n *\n * @param onMessage - The message handler to receive servicebus messages.\n * @param onError - The error handler to receive an error that occurs while receivin messages.\n */\n async subscribe(\n messageHandlers: InternalMessageHandlers,\n subscribeOptions: SubscribeOptions | undefined,\n ): Promise<void> {\n // these options and message handlers will be re-used if/when onDetach is called.\n this._subscribeOptions = subscribeOptions;\n this._setMessageHandlers(messageHandlers, subscribeOptions);\n\n let promiseResolve: (() => void) | undefined;\n this._subscribeCallPromise = new Promise((resolve) => {\n promiseResolve = resolve;\n });\n\n try {\n this._receiverHelper.resume();\n return await this._subscribeImpl(\"subscribe\");\n } catch (err: any) {\n // callers aren't going to be in a good position to forward this error properly\n // so we do it here.\n await this._messageHandlers().processError({\n entityPath: this.entityPath,\n fullyQualifiedNamespace: this._context.config.host,\n errorSource: \"receive\",\n error: err,\n identifier: this.identifier,\n });\n\n throw err;\n } finally {\n promiseResolve?.();\n this._subscribeCallPromise = undefined;\n }\n }\n\n /**\n * Wraps the individual message handlers with tracing and proper error handling\n * and assigns them to `this._messageHandlers`\n *\n * @param userHandlers - The user's message handlers\n * @param operationOptions - The subscribe(options)\n */\n private _setMessageHandlers(\n userHandlers: InternalMessageHandlers,\n operationOptions: OperationOptionsBase | undefined,\n ): void {\n const messageHandlers = {\n processError: async (args: ProcessErrorArgs) => {\n try {\n args.error = translateServiceBusError(args.error);\n await userHandlers.processError(args);\n } catch (err: any) {\n await this._reportInternalError(err);\n logger.logError(err, `An error was thrown from the user's processError handler`);\n }\n },\n processMessage: async (message: ServiceBusMessageImpl) => {\n try {\n await tracingClient.withSpan(\n \"StreamReceiver.process\",\n operationOptions ?? {},\n () => userHandlers.processMessage(message),\n toProcessingSpanOptions(message, this, this._context.config, \"process\"),\n );\n } catch (err: any) {\n this._messageHandlers().processError({\n error: err,\n errorSource: \"processMessageCallback\",\n entityPath: this.entityPath,\n fullyQualifiedNamespace: this._context.config.host,\n identifier: this.identifier,\n });\n throw err;\n }\n },\n postInitialize: async () => {\n if (!userHandlers.postInitialize) {\n return;\n }\n\n return userHandlers.postInitialize().catch((err) =>\n this._messageHandlers().processError({\n error: err,\n errorSource: \"processMessageCallback\",\n entityPath: this.entityPath,\n fullyQualifiedNamespace: this._context.config.host,\n identifier: this.identifier,\n }),\n );\n },\n preInitialize: async () => {\n if (!userHandlers.preInitialize) {\n return;\n }\n\n return userHandlers.preInitialize().catch((err) =>\n this._messageHandlers().processError({\n error: err,\n errorSource: \"processMessageCallback\",\n entityPath: this.entityPath,\n fullyQualifiedNamespace: this._context.config.host,\n identifier: this.identifier,\n }),\n );\n },\n forwardInternalErrors: userHandlers.forwardInternalErrors ?? false,\n };\n\n this._messageHandlers = () => messageHandlers;\n }\n\n /**\n * Subscribes using the already assigned `this._messageHandlers` and `this._subscribeOptions`\n *\n * @returns A promise that will resolve when a link is created and we successfully add credits to it.\n */\n private async _subscribeImpl(caller: \"detach\" | \"subscribe\"): Promise<void> {\n try {\n // we don't expect to ever get an error from retryForever but bugs\n // do happen.\n return await this._retryForeverFn({\n retryConfig: {\n connectionId: this._context.connection.id,\n operationType: RetryOperationType.receiverLink,\n abortSignal: this._subscribeOptions?.abortSignal,\n retryOptions: this._retryOptions,\n operation: () => this._initAndAddCreditOperation(caller),\n },\n onError: (err) =>\n this._messageHandlers().processError({\n error: err,\n errorSource: \"receive\",\n entityPath: this.entityPath,\n fullyQualifiedNamespace: this._context.config.host,\n identifier: this.identifier,\n }),\n logPrefix: this.logPrefix,\n logger,\n });\n } catch (err: any) {\n try {\n await this._receiverHelper.suspend();\n } catch (error: any) {\n logger.logError(error, `${this.logPrefix} receiver.suspend threw an error`);\n }\n\n throw err;\n }\n }\n\n /**\n * Initializes the link and adds credits. If any of these operations fail any created link will\n * be closed.\n *\n * @param caller - The caller which dictates whether or not we create a new name for our created link.\n * @param catchAndReportError - A function and reports an error but does not throw it.\n */\n private async _initAndAddCreditOperation(caller: \"detach\" | \"subscribe\"): Promise<void> {\n if (this._receiverHelper.isSuspended()) {\n // user has suspended us while we were initializing\n // the connection. Abort this attempt - if they attempt\n // resubscribe we'll just reinitialize.\n // This checks should happen before throwErrorIfConnectionClosed(); otherwise\n // we won't be able to break out of the retry-for-ever loops when user suspend us.\n throw new AbortError(\"Receiver was suspended during initialization.\");\n }\n\n throwErrorIfConnectionClosed(this._context);\n\n await this._messageHandlers().preInitialize();\n\n if (this._receiverHelper.isSuspended()) {\n // Need to check again as user can suspend us in preInitialize()\n throw new AbortError(\"Receiver was suspended during initialization.\");\n }\n await this._init(\n this._createReceiverOptions(caller === \"detach\", this._getHandlers()),\n this._subscribeOptions?.abortSignal,\n );\n\n try {\n await this._messageHandlers().postInitialize();\n this._receiverHelper.addCredit(this.maxConcurrentCalls);\n } catch (err: any) {\n try {\n await this.closeLink();\n } catch (error: any) {\n await this._messageHandlers().processError({\n error,\n errorSource: \"receive\",\n entityPath: this.entityPath,\n fullyQualifiedNamespace: this._context.config.host,\n identifier: this.identifier,\n });\n }\n throw err;\n }\n }\n\n /**\n * Will reconnect the receiver link if necessary.\n * @param receiverError - The receiver error or connection error, if any.\n */\n async onDetached(receiverError?: AmqpError | Error): Promise<void> {\n try {\n logger.verbose(`${this.logPrefix} onDetached: reinitializing link.`);\n\n // User explicitly called `close` on the receiver, so link is already closed\n // and we can exit early.\n if (this.wasClosedPermanently) {\n logger.verbose(\n `${this.logPrefix} onDetached: link has been closed permanently, not reinitializing. `,\n );\n return;\n }\n\n // Prevent multiple onDetached invocations from running concurrently.\n if (this._isDetaching) {\n // This can happen when the network connection goes down for some amount of time.\n // The first connection `disconnect` will trigger `onDetached` and attempt to retry\n // creating the connection/receiver link.\n // While those retry attempts fail (until the network connection comes back up),\n // we'll continue to see connection `disconnect` errors.\n // These should be ignored until the already running `onDetached` completes\n // its retry attempts or errors.\n logger.verbose(\n `${this.logPrefix} onDetached: Call to detached on streaming receiver '${this.name}' is already in progress.`,\n );\n return;\n }\n\n this._isDetaching = true;\n\n const translatedError = receiverError\n ? translateServiceBusError(receiverError)\n : receiverError;\n logger.logError(\n translatedError,\n `${this.logPrefix} onDetached: Reinitializing receiver because of error`,\n );\n\n // Clears the token renewal timer. Closes the link and its session if they are open.\n // Removes the link and its session if they are present in rhea's cache.\n await this.closeLink();\n } catch (err: any) {\n logger.verbose(\n `${this.logPrefix} onDetached: Encountered an error when closing the previous link: `,\n err,\n );\n }\n\n try {\n await this._subscribeImpl(\"detach\");\n } finally {\n this._isDetaching = false;\n }\n }\n\n protected removeLinkFromContext(): void {\n delete this._context.messageReceivers[this.name];\n }\n}\n"]}
@@ -17,9 +17,8 @@ exports.TRACEPARENT_PROPERTY = "Diagnostic-Id";
17
17
  * @hidden
18
18
  */
19
19
  function instrumentMessage(message, options, entityPath, host, operation) {
20
- var _a, _b, _c;
21
20
  // check if the event has already been instrumented
22
- const previouslyInstrumented = Boolean((_a = message.applicationProperties) === null || _a === void 0 ? void 0 : _a[exports.TRACEPARENT_PROPERTY]);
21
+ const previouslyInstrumented = Boolean(message.applicationProperties?.[exports.TRACEPARENT_PROPERTY]);
23
22
  if (previouslyInstrumented) {
24
23
  return {
25
24
  message,
@@ -34,14 +33,20 @@ function instrumentMessage(message, options, entityPath, host, operation) {
34
33
  spanContext: undefined,
35
34
  };
36
35
  }
37
- const traceParent = tracing_js_1.tracingClient.createRequestHeaders((_b = updatedOptions.tracingOptions) === null || _b === void 0 ? void 0 : _b.tracingContext)["traceparent"];
36
+ const traceParent = tracing_js_1.tracingClient.createRequestHeaders(updatedOptions.tracingOptions?.tracingContext)["traceparent"];
38
37
  if (traceParent) {
39
38
  // create a copy so the original isn't modified
40
- message = Object.assign(Object.assign({}, message), { applicationProperties: Object.assign(Object.assign({}, message.applicationProperties), { [exports.TRACEPARENT_PROPERTY]: traceParent }) });
39
+ message = {
40
+ ...message,
41
+ applicationProperties: {
42
+ ...message.applicationProperties,
43
+ [exports.TRACEPARENT_PROPERTY]: traceParent,
44
+ },
45
+ };
41
46
  }
42
47
  return {
43
48
  message,
44
- spanContext: (_c = updatedOptions.tracingOptions) === null || _c === void 0 ? void 0 : _c.tracingContext,
49
+ spanContext: updatedOptions.tracingOptions?.tracingContext,
45
50
  };
46
51
  }
47
52
  finally {
@@ -81,7 +86,6 @@ function* getReceivedMessages(receivedMessages) {
81
86
  * @internal
82
87
  */
83
88
  function toProcessingSpanOptions(receivedMessages, receiver, connectionConfig, operation) {
84
- var _a;
85
89
  const spanLinks = [];
86
90
  for (const receivedMessage of getReceivedMessages(receivedMessages)) {
87
91
  const tracingContext = extractSpanContextFromServiceBusMessage(receivedMessage);
@@ -89,11 +93,15 @@ function toProcessingSpanOptions(receivedMessages, receiver, connectionConfig, o
89
93
  spanLinks.push({
90
94
  tracingContext,
91
95
  attributes: {
92
- enqueuedTime: (_a = receivedMessage.enqueuedTimeUtc) === null || _a === void 0 ? void 0 : _a.getTime(),
96
+ enqueuedTime: receivedMessage.enqueuedTimeUtc?.getTime(),
93
97
  },
94
98
  });
95
99
  }
96
100
  }
97
- return Object.assign({ spanLinks, spanKind: "consumer" }, (0, tracing_js_1.toSpanOptions)({ host: connectionConfig.host, entityPath: receiver.entityPath }, operation));
101
+ return {
102
+ spanLinks,
103
+ spanKind: "consumer",
104
+ ...(0, tracing_js_1.toSpanOptions)({ host: connectionConfig.host, entityPath: receiver.entityPath }, operation),
105
+ };
98
106
  }
99
107
  //# sourceMappingURL=instrumentServiceBusMessage.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentServiceBusMessage.js","sourceRoot":"","sources":["../../../src/diagnostics/instrumentServiceBusMessage.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AA+BlC,8CAiEC;AAOD,0FASC;AAwBD,0DAuBC;AAvJD,6CAA4D;AAE5D;;GAEG;AACU,QAAA,oBAAoB,GAAG,eAAe,CAAC;AAapD;;;;GAIG;AACH,SAAgB,iBAAiB,CAC/B,OAAU,EACV,OAA6B,EAC7B,UAAkB,EAClB,IAAY,EACZ,SAAkC;;IAclC,mDAAmD;IACnD,MAAM,sBAAsB,GAAG,OAAO,CAAC,MAAA,OAAO,CAAC,qBAAqB,0CAAG,4BAAoB,CAAC,CAAC,CAAC;IAE9F,IAAI,sBAAsB,EAAE,CAAC;QAC3B,OAAO;YACL,OAAO;YACP,WAAW,EAAE,SAAS;SACvB,CAAC;IACJ,CAAC;IAED,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,cAAc,EAAE,GAAG,0BAAa,CAAC,SAAS,CACnE,SAAS,EACT,OAAO,EACP,IAAA,0BAAa,EAAC,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,UAAU,CAAC,CAC3D,CAAC;IAEF,IAAI,CAAC;QACH,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,EAAE,CAAC;YAC/B,OAAO;gBACL,OAAO;gBACP,WAAW,EAAE,SAAS;aACvB,CAAC;QACJ,CAAC;QAED,MAAM,WAAW,GAAG,0BAAa,CAAC,oBAAoB,CACpD,MAAA,cAAc,CAAC,cAAc,0CAAE,cAAc,CAC9C,CAAC,aAAa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AAI,cAAc,EAAE,CAAC;YACnB,SAAS,CAAC,IAAI,CAAC;gBACb,cAAc;gBACd,UAAU,EAAE;oBACV,YAAY,EAAE,MAAA,eAAe,CAAC,eAAe,0CAAE,OAAO,EAAE;iBACzD;aACF,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,uBACE,SAAS,EACT,QAAQ,EAAE,UAAU,IACjB,IAAA,0BAAa,EAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,CAAC,UAAU,EAAE,EAAE,SAAS,CAAC,EAC7F;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { TracingContext, TracingSpanLink, TracingSpanOptions } from \"@azure/core-tracing\";\nimport type { ConnectionContext } from \"../connectionContext.js\";\nimport type { OperationOptionsBase } from \"../modelsToBeSharedWithEventHubs.js\";\nimport type { ServiceBusReceiver } from \"../receivers/receiver.js\";\nimport type { ServiceBusMessage, ServiceBusReceivedMessage } from \"../serviceBusMessage.js\";\nimport type { MessagingOperationNames } from \"./tracing.js\";\nimport { toSpanOptions, tracingClient } from \"./tracing.js\";\n\n/**\n * @internal\n */\nexport const TRACEPARENT_PROPERTY = \"Diagnostic-Id\";\n\n/**\n * @hidden\n */\nexport interface InstrumentableMessage {\n /**\n * The application specific properties which can be\n * used for custom message metadata.\n */\n applicationProperties?: { [key: string]: number | boolean | string | Date | null };\n}\n\n/**\n * Instruments an AMQP message with a proper `Diagnostic-Id` for tracing.\n *\n * @hidden\n */\nexport function instrumentMessage<T extends InstrumentableMessage>(\n message: T,\n options: OperationOptionsBase,\n entityPath: string,\n host: string,\n operation: MessagingOperationNames,\n): {\n /**\n * If instrumentation was done, a copy of the message with\n * message.applicationProperties['Diagnostic-Id'] filled\n * out appropriately.\n */\n message: T;\n\n /**\n * A valid SpanContext if this message should be linked to a parent span, or undefined otherwise.\n */\n spanContext: TracingContext | undefined;\n} {\n // check if the event has already been instrumented\n const previouslyInstrumented = Boolean(message.applicationProperties?.[TRACEPARENT_PROPERTY]);\n\n if (previouslyInstrumented) {\n return {\n message,\n spanContext: undefined,\n };\n }\n\n const { span: messageSpan, updatedOptions } = tracingClient.startSpan(\n \"message\",\n options,\n toSpanOptions({ entityPath, host }, operation, \"producer\"),\n );\n\n try {\n if (!messageSpan.isRecording()) {\n return {\n message,\n spanContext: undefined,\n };\n }\n\n const traceParent = tracingClient.createRequestHeaders(\n updatedOptions.tracingOptions?.tracingContext,\n )[\"traceparent\"];\n\n if (traceParent) {\n // create a copy so the original isn't modified\n message = {\n ...message,\n applicationProperties: {\n ...message.applicationProperties,\n [TRACEPARENT_PROPERTY]: traceParent,\n },\n };\n }\n\n return {\n message,\n spanContext: updatedOptions.tracingOptions?.tracingContext,\n };\n } finally {\n messageSpan.end();\n }\n}\n\n/**\n * Extracts the `SpanContext` from an `ServiceBusMessage` if the context exists.\n * @param message - An individual `ServiceBusMessage` object.\n * @internal\n */\nexport function extractSpanContextFromServiceBusMessage(\n message: ServiceBusMessage,\n): TracingContext | undefined {\n if (!message.applicationProperties || !message.applicationProperties[TRACEPARENT_PROPERTY]) {\n return;\n }\n\n const diagnosticId = message.applicationProperties[TRACEPARENT_PROPERTY] as string;\n return tracingClient.parseTraceparentHeader(diagnosticId);\n}\n\n/**\n * Provides an iterable over messages, whether it is a single message or multiple\n * messages.\n *\n * @param receivedMessages - A single message or a set of messages\n * @internal\n */\nfunction* getReceivedMessages(\n receivedMessages: ServiceBusReceivedMessage | ServiceBusReceivedMessage[],\n): Iterable<ServiceBusReceivedMessage> {\n if (!Array.isArray(receivedMessages)) {\n yield receivedMessages;\n } else {\n for (const message of receivedMessages) {\n yield message;\n }\n }\n}\n\n/**\n * @internal\n */\nexport function toProcessingSpanOptions(\n receivedMessages: ServiceBusReceivedMessage | ServiceBusReceivedMessage[],\n receiver: Pick<ServiceBusReceiver, \"entityPath\">,\n connectionConfig: Pick<ConnectionContext[\"config\"], \"host\">,\n operation: MessagingOperationNames,\n): TracingSpanOptions {\n const spanLinks: TracingSpanLink[] = [];\n for (const receivedMessage of getReceivedMessages(receivedMessages)) {\n const tracingContext = extractSpanContextFromServiceBusMessage(receivedMessage);\n if (tracingContext) {\n spanLinks.push({\n tracingContext,\n attributes: {\n enqueuedTime: receivedMessage.enqueuedTimeUtc?.getTime(),\n },\n });\n }\n }\n return {\n spanLinks,\n spanKind: \"consumer\",\n ...toSpanOptions({ host: connectionConfig.host, entityPath: receiver.entityPath }, operation),\n };\n}\n"]}
1
+ {"version":3,"file":"instrumentServiceBusMessage.js","sourceRoot":"","sources":["../../../src/diagnostics/instrumentServiceBusMessage.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AA+BlC,8CAiEC;AAOD,0FASC;AAwBD,0DAuBC;AAvJD,6CAA4D;AAE5D;;GAEG;AACU,QAAA,oBAAoB,GAAG,eAAe,CAAC;AAapD;;;;GAIG;AACH,SAAgB,iBAAiB,CAC/B,OAAU,EACV,OAA6B,EAC7B,UAAkB,EAClB,IAAY,EACZ,SAAkC;IAclC,mDAAmD;IACnD,MAAM,sBAAsB,GAAG,OAAO,CAAC,OAAO,CAAC,qBAAqB,EAAE,CAAC,4BAAoB,CAAC,CAAC,CAAC;IAE9F,IAAI,sBAAsB,EAAE,CAAC;QAC3B,OAAO;YACL,OAAO;YACP,WAAW,EAAE,SAAS;SACvB,CAAC;IACJ,CAAC;IAED,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,cAAc,EAAE,GAAG,0BAAa,CAAC,SAAS,CACnE,SAAS,EACT,OAAO,EACP,IAAA,0BAAa,EAAC,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,UAAU,CAAC,CAC3D,CAAC;IAEF,IAAI,CAAC;QACH,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,EAAE,CAAC;YAC/B,OAAO;gBACL,OAAO;gBACP,WAAW,EAAE,SAAS;aACvB,CAAC;QACJ,CAAC;QAED,M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AAe,IAAI,mBAAmB,CAAC,gBAAgB,CAAC,EAAE,CAAC;QACpE,MAAM,cAAc,GAAG,uCAAuC,CAAC,eAAe,CAAC,CAAC;QAChF,IAAI,cAAc,EAAE,CAAC;YACnB,SAAS,CAAC,IAAI,CAAC;gBACb,cAAc;gBACd,UAAU,EAAE;oBACV,YAAY,EAAE,eAAe,CAAC,eAAe,EAAE,OAAO,EAAE;iBACzD;aACF,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO;QACL,SAAS;QACT,QAAQ,EAAE,UAAU;QACpB,GAAG,IAAA,0BAAa,EAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,CAAC,UAAU,EAAE,EAAE,SAAS,CAAC;KAC9F,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { TracingContext, TracingSpanLink, TracingSpanOptions } from \"@azure/core-tracing\";\nimport type { ConnectionContext } from \"../connectionContext.js\";\nimport type { OperationOptionsBase } from \"../modelsToBeSharedWithEventHubs.js\";\nimport type { ServiceBusReceiver } from \"../receivers/receiver.js\";\nimport type { ServiceBusMessage, ServiceBusReceivedMessage } from \"../serviceBusMessage.js\";\nimport type { MessagingOperationNames } from \"./tracing.js\";\nimport { toSpanOptions, tracingClient } from \"./tracing.js\";\n\n/**\n * @internal\n */\nexport const TRACEPARENT_PROPERTY = \"Diagnostic-Id\";\n\n/**\n * @hidden\n */\nexport interface InstrumentableMessage {\n /**\n * The application specific properties which can be\n * used for custom message metadata.\n */\n applicationProperties?: { [key: string]: number | boolean | string | Date | null };\n}\n\n/**\n * Instruments an AMQP message with a proper `Diagnostic-Id` for tracing.\n *\n * @hidden\n */\nexport function instrumentMessage<T extends InstrumentableMessage>(\n message: T,\n options: OperationOptionsBase,\n entityPath: string,\n host: string,\n operation: MessagingOperationNames,\n): {\n /**\n * If instrumentation was done, a copy of the message with\n * message.applicationProperties['Diagnostic-Id'] filled\n * out appropriately.\n */\n message: T;\n\n /**\n * A valid SpanContext if this message should be linked to a parent span, or undefined otherwise.\n */\n spanContext: TracingContext | undefined;\n} {\n // check if the event has already been instrumented\n const previouslyInstrumented = Boolean(message.applicationProperties?.[TRACEPARENT_PROPERTY]);\n\n if (previouslyInstrumented) {\n return {\n message,\n spanContext: undefined,\n };\n }\n\n const { span: messageSpan, updatedOptions } = tracingClient.startSpan(\n \"message\",\n options,\n toSpanOptions({ entityPath, host }, operation, \"producer\"),\n );\n\n try {\n if (!messageSpan.isRecording()) {\n return {\n message,\n spanContext: undefined,\n };\n }\n\n const traceParent = tracingClient.createRequestHeaders(\n updatedOptions.tracingOptions?.tracingContext,\n )[\"traceparent\"];\n\n if (traceParent) {\n // create a copy so the original isn't modified\n message = {\n ...message,\n applicationProperties: {\n ...message.applicationProperties,\n [TRACEPARENT_PROPERTY]: traceParent,\n },\n };\n }\n\n return {\n message,\n spanContext: updatedOptions.tracingOptions?.tracingContext,\n };\n } finally {\n messageSpan.end();\n }\n}\n\n/**\n * Extracts the `SpanContext` from an `ServiceBusMessage` if the context exists.\n * @param message - An individual `ServiceBusMessage` object.\n * @internal\n */\nexport function extractSpanContextFromServiceBusMessage(\n message: ServiceBusMessage,\n): TracingContext | undefined {\n if (!message.applicationProperties || !message.applicationProperties[TRACEPARENT_PROPERTY]) {\n return;\n }\n\n const diagnosticId = message.applicationProperties[TRACEPARENT_PROPERTY] as string;\n return tracingClient.parseTraceparentHeader(diagnosticId);\n}\n\n/**\n * Provides an iterable over messages, whether it is a single message or multiple\n * messages.\n *\n * @param receivedMessages - A single message or a set of messages\n * @internal\n */\nfunction* getReceivedMessages(\n receivedMessages: ServiceBusReceivedMessage | ServiceBusReceivedMessage[],\n): Iterable<ServiceBusReceivedMessage> {\n if (!Array.isArray(receivedMessages)) {\n yield receivedMessages;\n } else {\n for (const message of receivedMessages) {\n yield message;\n }\n }\n}\n\n/**\n * @internal\n */\nexport function toProcessingSpanOptions(\n receivedMessages: ServiceBusReceivedMessage | ServiceBusReceivedMessage[],\n receiver: Pick<ServiceBusReceiver, \"entityPath\">,\n connectionConfig: Pick<ConnectionContext[\"config\"], \"host\">,\n operation: MessagingOperationNames,\n): TracingSpanOptions {\n const spanLinks: TracingSpanLink[] = [];\n for (const receivedMessage of getReceivedMessages(receivedMessages)) {\n const tracingContext = extractSpanContextFromServiceBusMessage(receivedMessage);\n if (tracingContext) {\n spanLinks.push({\n tracingContext,\n attributes: {\n enqueuedTime: receivedMessage.enqueuedTimeUtc?.getTime(),\n },\n });\n }\n }\n return {\n spanLinks,\n spanKind: \"consumer\",\n ...toSpanOptions({ host: connectionConfig.host, entityPath: receiver.entityPath }, operation),\n };\n}\n"]}