@azure/event-hubs 6.0.2-alpha.20251014.1 → 6.0.2-alpha.20251021.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (259) hide show
  1. package/dist/browser/batchingPartitionChannel.d.ts.map +1 -1
  2. package/dist/browser/batchingPartitionChannel.js +2 -1
  3. package/dist/browser/batchingPartitionChannel.js.map +1 -1
  4. package/dist/browser/connectionContext.d.ts.map +1 -1
  5. package/dist/browser/connectionContext.js +10 -4
  6. package/dist/browser/connectionContext.js.map +1 -1
  7. package/dist/browser/eventHubBufferedProducerClient.d.ts.map +1 -1
  8. package/dist/browser/eventHubBufferedProducerClient.js +2 -1
  9. package/dist/browser/eventHubBufferedProducerClient.js.map +1 -1
  10. package/dist/browser/eventHubConsumerClient.d.ts.map +1 -1
  11. package/dist/browser/eventHubConsumerClient.js +3 -6
  12. package/dist/browser/eventHubConsumerClient.js.map +1 -1
  13. package/dist/browser/eventHubProducerClient.d.ts.map +1 -1
  14. package/dist/browser/eventHubProducerClient.js +3 -6
  15. package/dist/browser/eventHubProducerClient.js.map +1 -1
  16. package/dist/browser/eventHubSender.d.ts.map +1 -1
  17. package/dist/browser/eventHubSender.js +6 -4
  18. package/dist/browser/eventHubSender.js.map +1 -1
  19. package/dist/browser/partitionReceiver.js +4 -4
  20. package/dist/browser/partitionReceiver.js.map +1 -1
  21. package/dist/browser/util/timerLoop.d.ts.map +1 -1
  22. package/dist/browser/util/timerLoop.js +12 -5
  23. package/dist/browser/util/timerLoop.js.map +1 -1
  24. package/dist/commonjs/batchingPartitionChannel.d.ts.map +1 -1
  25. package/dist/commonjs/batchingPartitionChannel.js +2 -1
  26. package/dist/commonjs/batchingPartitionChannel.js.map +1 -1
  27. package/dist/commonjs/connectionContext.d.ts.map +1 -1
  28. package/dist/commonjs/connectionContext.js +10 -4
  29. package/dist/commonjs/connectionContext.js.map +1 -1
  30. package/dist/commonjs/eventHubBufferedProducerClient.d.ts.map +1 -1
  31. package/dist/commonjs/eventHubBufferedProducerClient.js +2 -1
  32. package/dist/commonjs/eventHubBufferedProducerClient.js.map +1 -1
  33. package/dist/commonjs/eventHubConsumerClient.d.ts.map +1 -1
  34. package/dist/commonjs/eventHubConsumerClient.js +3 -6
  35. package/dist/commonjs/eventHubConsumerClient.js.map +1 -1
  36. package/dist/commonjs/eventHubProducerClient.d.ts.map +1 -1
  37. package/dist/commonjs/eventHubProducerClient.js +3 -6
  38. package/dist/commonjs/eventHubProducerClient.js.map +1 -1
  39. package/dist/commonjs/eventHubSender.d.ts.map +1 -1
  40. package/dist/commonjs/eventHubSender.js +6 -4
  41. package/dist/commonjs/eventHubSender.js.map +1 -1
  42. package/dist/commonjs/partitionReceiver.js +4 -4
  43. package/dist/commonjs/partitionReceiver.js.map +1 -1
  44. package/dist/commonjs/util/timerLoop.d.ts.map +1 -1
  45. package/dist/commonjs/util/timerLoop.js +12 -5
  46. package/dist/commonjs/util/timerLoop.js.map +1 -1
  47. package/dist/esm/batchingPartitionChannel.d.ts.map +1 -1
  48. package/dist/esm/batchingPartitionChannel.js +2 -1
  49. package/dist/esm/batchingPartitionChannel.js.map +1 -1
  50. package/dist/esm/connectionContext.d.ts.map +1 -1
  51. package/dist/esm/connectionContext.js +10 -4
  52. package/dist/esm/connectionContext.js.map +1 -1
  53. package/dist/esm/eventHubBufferedProducerClient.d.ts.map +1 -1
  54. package/dist/esm/eventHubBufferedProducerClient.js +2 -1
  55. package/dist/esm/eventHubBufferedProducerClient.js.map +1 -1
  56. package/dist/esm/eventHubConsumerClient.d.ts.map +1 -1
  57. package/dist/esm/eventHubConsumerClient.js +3 -6
  58. package/dist/esm/eventHubConsumerClient.js.map +1 -1
  59. package/dist/esm/eventHubProducerClient.d.ts.map +1 -1
  60. package/dist/esm/eventHubProducerClient.js +3 -6
  61. package/dist/esm/eventHubProducerClient.js.map +1 -1
  62. package/dist/esm/eventHubSender.d.ts.map +1 -1
  63. package/dist/esm/eventHubSender.js +6 -4
  64. package/dist/esm/eventHubSender.js.map +1 -1
  65. package/dist/esm/partitionReceiver.js +4 -4
  66. package/dist/esm/partitionReceiver.js.map +1 -1
  67. package/dist/esm/util/timerLoop.d.ts.map +1 -1
  68. package/dist/esm/util/timerLoop.js +12 -5
  69. package/dist/esm/util/timerLoop.js.map +1 -1
  70. package/dist/react-native/batchingPartitionChannel.d.ts +94 -0
  71. package/dist/react-native/batchingPartitionChannel.d.ts.map +1 -0
  72. package/dist/react-native/batchingPartitionChannel.js +255 -0
  73. package/dist/react-native/batchingPartitionChannel.js.map +1 -0
  74. package/dist/react-native/connectionContext.d.ts +108 -0
  75. package/dist/react-native/connectionContext.d.ts.map +1 -0
  76. package/dist/react-native/connectionContext.js +310 -0
  77. package/dist/react-native/connectionContext.js.map +1 -0
  78. package/dist/react-native/dataTransformer.d.ts +53 -0
  79. package/dist/react-native/dataTransformer.d.ts.map +1 -0
  80. package/dist/react-native/dataTransformer.js +133 -0
  81. package/dist/react-native/dataTransformer.js.map +1 -0
  82. package/dist/react-native/diagnostics/instrumentEventData.d.ts +28 -0
  83. package/dist/react-native/diagnostics/instrumentEventData.d.ts.map +1 -0
  84. package/dist/react-native/diagnostics/instrumentEventData.js +67 -0
  85. package/dist/react-native/diagnostics/instrumentEventData.js.map +1 -0
  86. package/dist/react-native/diagnostics/tracing.d.ts +19 -0
  87. package/dist/react-native/diagnostics/tracing.d.ts.map +1 -0
  88. package/dist/react-native/diagnostics/tracing.js +40 -0
  89. package/dist/react-native/diagnostics/tracing.js.map +1 -0
  90. package/dist/react-native/eventData.d.ts +295 -0
  91. package/dist/react-native/eventData.d.ts.map +1 -0
  92. package/dist/react-native/eventData.js +247 -0
  93. package/dist/react-native/eventData.js.map +1 -0
  94. package/dist/react-native/eventDataAdapter.d.ts +69 -0
  95. package/dist/react-native/eventDataAdapter.d.ts.map +1 -0
  96. package/dist/react-native/eventDataAdapter.js +38 -0
  97. package/dist/react-native/eventDataAdapter.js.map +1 -0
  98. package/dist/react-native/eventDataBatch.d.ts +225 -0
  99. package/dist/react-native/eventDataBatch.d.ts.map +1 -0
  100. package/dist/react-native/eventDataBatch.js +301 -0
  101. package/dist/react-native/eventDataBatch.js.map +1 -0
  102. package/dist/react-native/eventHubBufferedProducerClient.d.ts +323 -0
  103. package/dist/react-native/eventHubBufferedProducerClient.d.ts.map +1 -0
  104. package/dist/react-native/eventHubBufferedProducerClient.js +301 -0
  105. package/dist/react-native/eventHubBufferedProducerClient.js.map +1 -0
  106. package/dist/react-native/eventHubConsumerClient.d.ts +293 -0
  107. package/dist/react-native/eventHubConsumerClient.d.ts.map +1 -0
  108. package/dist/react-native/eventHubConsumerClient.js +336 -0
  109. package/dist/react-native/eventHubConsumerClient.js.map +1 -0
  110. package/dist/react-native/eventHubConsumerClientModels.d.ts +218 -0
  111. package/dist/react-native/eventHubConsumerClientModels.d.ts.map +1 -0
  112. package/dist/react-native/eventHubConsumerClientModels.js +4 -0
  113. package/dist/react-native/eventHubConsumerClientModels.js.map +1 -0
  114. package/dist/react-native/eventHubProducerClient.d.ts +299 -0
  115. package/dist/react-native/eventHubProducerClient.d.ts.map +1 -0
  116. package/dist/react-native/eventHubProducerClient.js +366 -0
  117. package/dist/react-native/eventHubProducerClient.js.map +1 -0
  118. package/dist/react-native/eventHubSender.d.ts +227 -0
  119. package/dist/react-native/eventHubSender.d.ts.map +1 -0
  120. package/dist/react-native/eventHubSender.js +626 -0
  121. package/dist/react-native/eventHubSender.js.map +1 -0
  122. package/dist/react-native/eventPosition.d.ts +73 -0
  123. package/dist/react-native/eventPosition.d.ts.map +1 -0
  124. package/dist/react-native/eventPosition.js +121 -0
  125. package/dist/react-native/eventPosition.js.map +1 -0
  126. package/dist/react-native/eventProcessor.d.ts +232 -0
  127. package/dist/react-native/eventProcessor.d.ts.map +1 -0
  128. package/dist/react-native/eventProcessor.js +389 -0
  129. package/dist/react-native/eventProcessor.js.map +1 -0
  130. package/dist/react-native/eventhubConnectionConfig.d.ts +96 -0
  131. package/dist/react-native/eventhubConnectionConfig.d.ts.map +1 -0
  132. package/dist/react-native/eventhubConnectionConfig.js +98 -0
  133. package/dist/react-native/eventhubConnectionConfig.js.map +1 -0
  134. package/dist/react-native/impl/awaitableQueue.d.ts +25 -0
  135. package/dist/react-native/impl/awaitableQueue.d.ts.map +1 -0
  136. package/dist/react-native/impl/awaitableQueue.js +51 -0
  137. package/dist/react-native/impl/awaitableQueue.js.map +1 -0
  138. package/dist/react-native/impl/partitionAssigner.d.ts +29 -0
  139. package/dist/react-native/impl/partitionAssigner.d.ts.map +1 -0
  140. package/dist/react-native/impl/partitionAssigner.js +52 -0
  141. package/dist/react-native/impl/partitionAssigner.js.map +1 -0
  142. package/dist/react-native/impl/partitionGate.d.ts +27 -0
  143. package/dist/react-native/impl/partitionGate.d.ts.map +1 -0
  144. package/dist/react-native/impl/partitionGate.js +38 -0
  145. package/dist/react-native/impl/partitionGate.js.map +1 -0
  146. package/dist/react-native/impl/partitionKeyToIdMapper.d.ts +6 -0
  147. package/dist/react-native/impl/partitionKeyToIdMapper.d.ts.map +1 -0
  148. package/dist/react-native/impl/partitionKeyToIdMapper.js +111 -0
  149. package/dist/react-native/impl/partitionKeyToIdMapper.js.map +1 -0
  150. package/dist/react-native/inMemoryCheckpointStore.d.ts +44 -0
  151. package/dist/react-native/inMemoryCheckpointStore.d.ts.map +1 -0
  152. package/dist/react-native/inMemoryCheckpointStore.js +94 -0
  153. package/dist/react-native/inMemoryCheckpointStore.js.map +1 -0
  154. package/dist/react-native/index.d.ts +21 -0
  155. package/dist/react-native/index.d.ts.map +1 -0
  156. package/dist/react-native/index.js +12 -0
  157. package/dist/react-native/index.js.map +1 -0
  158. package/dist/react-native/loadBalancerStrategies/balancedStrategy.d.ts +30 -0
  159. package/dist/react-native/loadBalancerStrategies/balancedStrategy.d.ts.map +1 -0
  160. package/dist/react-native/loadBalancerStrategies/balancedStrategy.js +40 -0
  161. package/dist/react-native/loadBalancerStrategies/balancedStrategy.js.map +1 -0
  162. package/dist/react-native/loadBalancerStrategies/greedyStrategy.d.ts +24 -0
  163. package/dist/react-native/loadBalancerStrategies/greedyStrategy.d.ts.map +1 -0
  164. package/dist/react-native/loadBalancerStrategies/greedyStrategy.js +29 -0
  165. package/dist/react-native/loadBalancerStrategies/greedyStrategy.js.map +1 -0
  166. package/dist/react-native/loadBalancerStrategies/loadBalancingStrategy.d.ts +28 -0
  167. package/dist/react-native/loadBalancerStrategies/loadBalancingStrategy.d.ts.map +1 -0
  168. package/dist/react-native/loadBalancerStrategies/loadBalancingStrategy.js +245 -0
  169. package/dist/react-native/loadBalancerStrategies/loadBalancingStrategy.js.map +1 -0
  170. package/dist/react-native/loadBalancerStrategies/unbalancedStrategy.d.ts +20 -0
  171. package/dist/react-native/loadBalancerStrategies/unbalancedStrategy.d.ts.map +1 -0
  172. package/dist/react-native/loadBalancerStrategies/unbalancedStrategy.js +22 -0
  173. package/dist/react-native/loadBalancerStrategies/unbalancedStrategy.js.map +1 -0
  174. package/dist/react-native/logger.d.ts +37 -0
  175. package/dist/react-native/logger.d.ts.map +1 -0
  176. package/dist/react-native/logger.js +56 -0
  177. package/dist/react-native/logger.js.map +1 -0
  178. package/dist/react-native/managementClient.d.ts +145 -0
  179. package/dist/react-native/managementClient.d.ts.map +1 -0
  180. package/dist/react-native/managementClient.js +305 -0
  181. package/dist/react-native/managementClient.js.map +1 -0
  182. package/dist/react-native/models/private.d.ts +185 -0
  183. package/dist/react-native/models/private.d.ts.map +1 -0
  184. package/dist/react-native/models/private.js +4 -0
  185. package/dist/react-native/models/private.js.map +1 -0
  186. package/dist/react-native/models/public.d.ts +240 -0
  187. package/dist/react-native/models/public.d.ts.map +1 -0
  188. package/dist/react-native/models/public.js +18 -0
  189. package/dist/react-native/models/public.js.map +1 -0
  190. package/dist/react-native/package.json +3 -0
  191. package/dist/react-native/partitionProcessor.d.ts +134 -0
  192. package/dist/react-native/partitionProcessor.d.ts.map +1 -0
  193. package/dist/react-native/partitionProcessor.js +137 -0
  194. package/dist/react-native/partitionProcessor.js.map +1 -0
  195. package/dist/react-native/partitionPump.d.ts +38 -0
  196. package/dist/react-native/partitionPump.d.ts.map +1 -0
  197. package/dist/react-native/partitionPump.js +175 -0
  198. package/dist/react-native/partitionPump.js.map +1 -0
  199. package/dist/react-native/partitionReceiver.d.ts +82 -0
  200. package/dist/react-native/partitionReceiver.d.ts.map +1 -0
  201. package/dist/react-native/partitionReceiver.js +335 -0
  202. package/dist/react-native/partitionReceiver.js.map +1 -0
  203. package/dist/react-native/pumpManager.d.ts +72 -0
  204. package/dist/react-native/pumpManager.d.ts.map +1 -0
  205. package/dist/react-native/pumpManager.js +120 -0
  206. package/dist/react-native/pumpManager.js.map +1 -0
  207. package/dist/react-native/util/connectionStringUtils.d.ts +52 -0
  208. package/dist/react-native/util/connectionStringUtils.d.ts.map +1 -0
  209. package/dist/react-native/util/connectionStringUtils.js +48 -0
  210. package/dist/react-native/util/connectionStringUtils.js.map +1 -0
  211. package/dist/react-native/util/constants.d.ts +25 -0
  212. package/dist/react-native/util/constants.d.ts.map +1 -0
  213. package/dist/react-native/util/constants.js +27 -0
  214. package/dist/react-native/util/constants.js.map +1 -0
  215. package/dist/react-native/util/delayWithoutThrow.d.ts +8 -0
  216. package/dist/react-native/util/delayWithoutThrow.d.ts.map +1 -0
  217. package/dist/react-native/util/delayWithoutThrow.js +17 -0
  218. package/dist/react-native/util/delayWithoutThrow.js.map +1 -0
  219. package/dist/react-native/util/error.d.ts +39 -0
  220. package/dist/react-native/util/error.d.ts.map +1 -0
  221. package/dist/react-native/util/error.js +103 -0
  222. package/dist/react-native/util/error.js.map +1 -0
  223. package/dist/react-native/util/getPromiseParts.d.ts +10 -0
  224. package/dist/react-native/util/getPromiseParts.d.ts.map +1 -0
  225. package/dist/react-native/util/getPromiseParts.js +20 -0
  226. package/dist/react-native/util/getPromiseParts.js.map +1 -0
  227. package/dist/react-native/util/operationOptions.d.ts +16 -0
  228. package/dist/react-native/util/operationOptions.d.ts.map +1 -0
  229. package/dist/react-native/util/operationOptions.js +4 -0
  230. package/dist/react-native/util/operationOptions.js.map +1 -0
  231. package/dist/react-native/util/parseEndpoint.d.ts +11 -0
  232. package/dist/react-native/util/parseEndpoint.d.ts.map +1 -0
  233. package/dist/react-native/util/parseEndpoint.js +17 -0
  234. package/dist/react-native/util/parseEndpoint.js.map +1 -0
  235. package/dist/react-native/util/retries.d.ts +6 -0
  236. package/dist/react-native/util/retries.d.ts.map +1 -0
  237. package/dist/react-native/util/retries.js +13 -0
  238. package/dist/react-native/util/retries.js.map +1 -0
  239. package/dist/react-native/util/runtimeInfo-react-native.d.mts.map +1 -0
  240. package/dist/react-native/util/runtimeInfo-react-native.mjs.map +1 -0
  241. package/dist/react-native/util/runtimeInfo.d.ts +6 -0
  242. package/dist/react-native/util/runtimeInfo.js +20 -0
  243. package/dist/react-native/util/timerLoop.d.ts +26 -0
  244. package/dist/react-native/util/timerLoop.d.ts.map +1 -0
  245. package/dist/react-native/util/timerLoop.js +34 -0
  246. package/dist/react-native/util/timerLoop.js.map +1 -0
  247. package/dist/react-native/util/typeGuards.d.ts +8 -0
  248. package/dist/react-native/util/typeGuards.d.ts.map +1 -0
  249. package/dist/react-native/util/typeGuards.js +12 -0
  250. package/dist/react-native/util/typeGuards.js.map +1 -0
  251. package/dist/react-native/util/utils.d.ts +7 -0
  252. package/dist/react-native/util/utils.d.ts.map +1 -0
  253. package/dist/react-native/util/utils.js +13 -0
  254. package/dist/react-native/util/utils.js.map +1 -0
  255. package/dist/react-native/withAuth.d.ts +25 -0
  256. package/dist/react-native/withAuth.d.ts.map +1 -0
  257. package/dist/react-native/withAuth.js +84 -0
  258. package/dist/react-native/withAuth.js.map +1 -0
  259. package/package.json +16 -11
@@ -1 +1 @@
1
- {"version":3,"file":"batchingPartitionChannel.d.ts","sourceRoot":"","sources":["../../src/batchingPartitionChannel.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAE7D,OA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AAkB;IAC1C,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,yBAAyB,CAAoE;IACrG,OAAO,CAAC,2BAA2B,CAAC,CAAsE;IAE1G,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,SAAS,CAAyB;gBAE9B,EACV,eAAe,EACf,aAAa,EACb,eAAe,EACf,wBAAwB,EACxB,0BAA0B,EAC1B,WAAW,EACX,QAAQ,GACT,EAAE,6BAA6B;IAUhC,uBAAuB,IAAI,MAAM;IAI3B,YAAY,CAAC,KAAK,EAAE,SAAS,GAAG,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAoB1E;;;;;OAKG;IACG,KAAK,CAAC,QAAQ,GAAE,gBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;IAgB3D;;;OAGG;IACH,OAAO,CAAC,MAAM;IAmBd;;;;OAIG;YACW,iBAAiB;IAuF/B;;;;;;;OAOG;YACW,YAAY;IAU1B;;;;;;;OAOG;IACH,OAAO,CAAC,mBAAmB;IAW3B;;;OAGG;IACH,OAAO,CAAC,cAAc;IAmBtB;;;OAGG;IACH,OAAO,CAAC,cAAc;IAoBtB;;;OAGG;IACH,OAAO,CAAC,iBAAiB;CAW1B"}
@@ -46,8 +46,9 @@ export class BatchingPartitionChannel {
46
46
  this._bufferCount++;
47
47
  if (!this._isRunning) {
48
48
  this._isRunning = true;
49
+ // Fire-and-forget background loop with error handling
49
50
  this._startPublishLoop().catch((e) => {
50
- logger.error(`The following error occured during batch creation or sending: ${JSON.stringify(e, undefined, " ")}`);
51
+ logger.error(`The following error occurred during batch creation or sending: ${JSON.stringify(e, undefined, " ")}`);
51
52
  });
52
53
  }
53
54
  }
@@ -1 +1 @@
1
- {"version":3,"file":"batchingPartitionChannel.js","sourceRoot":"","sources":["../../src/batchingPartitionChannel.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,KAAK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,IAAI,CAAC,YAAY;aAC/B,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,CAAU,EAAE,CAAC;YACpB,MAAM,CAAC,KAAK,CACV,iEAAiE,IAAI,CAAC,SAAS,CAC7E,CAAC,EACD,SAAS,EACT,IAAI,CACL,EAAE,CACJ,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;;OAGG;IACK,iBAAiB;QACvB,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC;QAC/B,IAAI,CAAC,KAAK,CAAC,UAAU,IAAI,IAAI,CAAC,uBAAuB,EAAE,KAAK,CAAC,EAAE,CAAC;YAC9D,OAAO;QACT,CAAC;QAED,KAAK,CAAC,OAAO,EAAE,CAAC;QAEhB,IAAI,CAAC,WAAW,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;QACzC,IAAI,CAAC,mBAAmB,EAAE,CAAC;IAC7B,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AmqpAnnotatedMessage } from \"@azure/core-amqp\";\nimport { delay } from \"@azure/core-amqp\";\nimport type {\n EventData,\n EventDataBatch,\n EventHubBufferedProducerClientOptions,\n EventHubProducerClient,\n OperationOptions,\n} from \"./index.js\";\nimport type { AbortOptions } from \"@azure/core-util\";\nimport { isDefined, isObjectWithProperties } from \"@azure/core-util\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport { AwaitableQueue } from \"./impl/awaitableQueue.js\";\nimport { getPromiseParts } from \"./util/getPromiseParts.js\";\nimport { logger } from \"./logger.js\";\nimport { cancelablePromiseRace } from \"@azure/core-util\";\n\nexport interface BatchingPartitionChannelProps {\n loopAbortSignal: AbortSignalLike;\n maxBufferSize: number;\n maxWaitTimeInMs: number;\n partitionId: string;\n producer: EventHubProducerClient;\n /**\n * The handler to call once a batch has successfully published.\n */\n onSendEventsSuccessHandler?: EventHubBufferedProducerClientOptions[\"onSendEventsSuccessHandler\"];\n /**\n * The handler to call when a batch fails to publish.\n */\n onSendEventsErrorHandler: EventHubBufferedProducerClientOptions[\"onSendEventsErrorHandler\"];\n}\n\n/**\n * The `BatchingPartitionChannel` is responsible for accepting enqueued events\n * and optimally batching and sending them to an Event Hub.\n * @internal\n */\nexport class BatchingPartitionChannel {\n private _eventQueue = new AwaitableQueue<EventData | AmqpAnnotatedMessage>();\n private _batchedEvents: Array<EventData | AmqpAnnotatedMessage> = [];\n private _bufferCount: number = 0;\n private _readyQueue: Array<{\n resolve: (value: void) => void;\n reject: (reason?: any) => void;\n }> = [];\n private _flushState:\n | { isFlushing: false }\n | { isFlushing: true; currentPromise: Promise<void>; resolve: () => void } = {\n isFlushing: false,\n };\n private _isRunning: boolean = false;\n private _lastBatchCreationTime: number = 0;\n private _loopAbortSignal: AbortSignalLike;\n private _maxBufferSize: number;\n private _maxWaitTimeInMs: number;\n private _onSendEventsErrorHandler: EventHubBufferedProducerClientOptions[\"onSendEventsErrorHandler\"];\n private _onSendEventsSuccessHandler?: EventHubBufferedProducerClientOptions[\"onSendEventsSuccessHandler\"];\n\n private _partitionId: string;\n private _producer: EventHubProducerClient;\n\n constructor({\n loopAbortSignal,\n maxBufferSize,\n maxWaitTimeInMs,\n onSendEventsErrorHandler,\n onSendEventsSuccessHandler,\n partitionId,\n producer,\n }: BatchingPartitionChannelProps) {\n this._loopAbortSignal = loopAbortSignal;\n this._maxBufferSize = maxBufferSize;\n this._maxWaitTimeInMs = maxWaitTimeInMs;\n this._onSendEventsErrorHandler = onSendEventsErrorHandler;\n this._onSendEventsSuccessHandler = onSendEventsSuccessHandler;\n this._partitionId = partitionId;\n this._producer = producer;\n }\n\n getCurrentBufferedCount(): number {\n return this._bufferCount;\n }\n\n async enqueueEvent(event: EventData | AmqpAnnotatedMessage): Promise<void> {\n await this._ready();\n this._eventQueue.push(event);\n this._bufferCount++;\n\n if (!this._isRunning) {\n this._isRunning = true;\n this._startPublishLoop().catch((e) => {\n logger.error(\n `The following error occured during batch creation or sending: ${JSON.stringify(\n e,\n undefined,\n \" \",\n )}`,\n );\n });\n }\n }\n\n /**\n * Sets the flush state so that no new events can be enqueued until\n * all the currently buffered events are sent to the Event Hub.\n *\n * Returns a promise that resolves once flushing is complete.\n */\n async flush(_options: OperationOptions = {}): Promise<void> {\n const state = this._flushState;\n if (state.isFlushing) {\n return state.currentPromise;\n }\n\n if (this.getCurrentBufferedCount() === 0) {\n return Promise.resolve();\n }\n\n const { promise, resolve } = getPromiseParts<void>();\n this._flushState = { isFlushing: true, currentPromise: promise, resolve };\n\n return promise;\n }\n\n /**\n * Returns a promise that resolves once there is room for events to be added\n * to the buffer.\n */\n private _ready(): Promise<void> {\n const currentBufferedCount = this.getCurrentBufferedCount();\n\n // If the buffer isn't full and we don't have any pending `ready()` calls,\n // then it's safe to return right away.\n if (\n currentBufferedCount < this._maxBufferSize &&\n !this._readyQueue.length &&\n !this._flushState.isFlushing\n ) {\n return Promise.resolve();\n }\n\n const { promise: readyPromise, reject, resolve } = getPromiseParts<void>();\n this._readyQueue.push({ resolve, reject });\n\n return readyPromise;\n }\n\n /**\n * Starts the loop that creates batches and sends them to the Event Hub.\n *\n * The loop will run until the `_loopAbortSignal` is aborted.\n */\n private async _startPublishLoop() {\n let batch: EventDataBatch | undefined;\n // `eventToAddToBatch` is used to keep track of an event that has been removed\n // from the queue, but has not yet been added to a batch.\n // This prevents losing an event if a `sendBatch` or `createBatch` call fails\n // before the event is added to a batch.\n let eventToAddToBatch: EventData | AmqpAnnotatedMessage | undefined;\n while (!this._loopAbortSignal.aborted) {\n try {\n if (!isDefined(batch)) {\n batch = await this._createBatch();\n }\n const timeSinceLastBatchCreation = Date.now() - this._lastBatchCreationTime;\n const maximumTimeToWaitForEvent = batch.count\n ? Math.max(this._maxWaitTimeInMs - timeSinceLastBatchCreation, 0)\n : this._maxWaitTimeInMs;\n\n const event =\n eventToAddToBatch ??\n (await cancelablePromiseRace<[EventData | AmqpAnnotatedMessage, void]>(\n [\n (abortOptions: AbortOptions) => this._eventQueue.shift(abortOptions),\n (abortOptions: AbortOptions) =>\n delay<void>(\n maximumTimeToWaitForEvent,\n abortOptions.abortSignal,\n abortOptions.abortErrorMsg,\n ),\n ],\n { abortSignal: this._loopAbortSignal },\n ));\n\n if (!event) {\n // We didn't receive an event within the allotted time.\n // Send the existing batch if it has events in it.\n if (batch.count) {\n await this._producer.sendBatch(batch);\n this._reportSuccess();\n batch = await this._createBatch();\n }\n continue;\n } else if (!eventToAddToBatch) {\n eventToAddToBatch = event;\n }\n\n const didAdd = batch.tryAdd(event);\n if (didAdd) {\n // This event will definitely make it to one of the user-provided handlers\n // since it was added to a batch.\n // Store it so we can return it in a handler later.\n this._batchedEvents.push(event);\n // Clear reference to existing event since it has been added to the batch.\n eventToAddToBatch = undefined;\n }\n\n if (didAdd && batch.count >= this._maxBufferSize) {\n // Whenever batch.count exceeds the max count of buffered events, send the batch.\n await this._producer.sendBatch(batch);\n this._reportSuccess();\n batch = await this._createBatch();\n } else if (!didAdd && batch.count) {\n // If the event wasn't able to be added and the current batch isn't empty,\n // attempt to send the current batch and add the event to a new batch.\n await this._producer.sendBatch(batch);\n this._reportSuccess();\n batch = await this._createBatch();\n }\n\n if (!didAdd && !batch.tryAdd(event)) {\n // TODO: Report MaxMesageSizeExceeded error. Mimic service's error.\n this._reportFailure(new Error(\"Placeholder for max message size exceeded\"), event);\n } else if (!didAdd) {\n // Handles the case where the event _was_ successfull added to the new batch.\n this._batchedEvents.push(event);\n }\n // Clear reference to existing event since it has been added to the batch.\n eventToAddToBatch = undefined;\n } catch (err: any) {\n if (!isObjectWithProperties(err, [\"name\"]) || err.name !== \"AbortError\") {\n this._reportFailure(err);\n batch = undefined;\n this._batchedEvents = [];\n }\n }\n }\n }\n\n /**\n * Helper method that returns an `EventDataBatch`.\n * This also has the side effects of\n * - keeping track of batch creation time: needed for maxWaitTime calculations.\n * - clearing reference to batched events.\n * - incrementing the readiness: creating a new batch indicates the buffer\n * should have room, so we can resolve some pending `ready()` calls.\n */\n private async _createBatch(): Promise<EventDataBatch> {\n this._lastBatchCreationTime = Date.now();\n this._batchedEvents = [];\n const batch = await this._producer.createBatch({\n partitionId: this._partitionId,\n });\n this._incrementReadiness();\n return batch;\n }\n\n /**\n * This method will resolve as many pending `ready()` calls as it can\n * based on how much space remains in the buffer.\n *\n * If the channel is currently flushing, this is a no-op. This prevents\n * `enqueueEvent` calls from adding the event to the buffer until flushing\n * completes.\n */\n private _incrementReadiness() {\n if (this._flushState.isFlushing) {\n return;\n }\n const currentBufferedCount = this.getCurrentBufferedCount();\n const num = Math.min(this._maxBufferSize - currentBufferedCount, this._readyQueue.length);\n for (let i = 0; i < num; i++) {\n this._readyQueue.shift()?.resolve();\n }\n }\n\n /**\n * Calls the user-provided `onSendEventsSuccessHandler` with the events\n * that were successfully sent.\n */\n private _reportSuccess() {\n this._bufferCount = this._bufferCount - this._batchedEvents.length;\n this._updateFlushState();\n try {\n this._onSendEventsSuccessHandler?.({\n events: this._batchedEvents,\n partitionId: this._partitionId,\n });\n } catch (e: unknown) {\n logger.error(\n `The following error occurred in the onSendEventsSuccessHandler: ${JSON.stringify(\n e,\n undefined,\n \" \",\n )}`,\n );\n }\n }\n\n /**\n * Calls the user-provided `onSendEventsErrorHandler` with an error and the events\n * that were not successfully sent.\n */\n private _reportFailure(err: any, event?: EventData | AmqpAnnotatedMessage) {\n this._bufferCount = this._bufferCount - (event ? 1 : this._batchedEvents.length);\n this._updateFlushState();\n try {\n this._onSendEventsErrorHandler({\n error: err,\n events: event ? [event] : this._batchedEvents,\n partitionId: this._partitionId,\n });\n } catch (e: unknown) {\n logger.error(\n `The following error occurred in the onSendEventsErrorHandler: ${JSON.stringify(\n e,\n undefined,\n \" \",\n )}`,\n );\n }\n }\n\n /**\n * Updates the channel's flush state once the size of the\n * event buffer has decreased to 0.\n */\n private _updateFlushState() {\n const state = this._flushState;\n if (!state.isFlushing || this.getCurrentBufferedCount() !== 0) {\n return;\n }\n\n state.resolve();\n\n this._flushState = { isFlushing: false };\n this._incrementReadiness();\n }\n}\n"]}
1
+ {"version":3,"file":"batchingPartitionChannel.js","sourceRoot":"","sources":["../../src/batchingPartitionChannel.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AASzC,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAErE,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAkBzD;;;;GAIG;AACH,MAAM,OAAO,wBAAwB;IAC3B,WAAW,GAAG,IAAI,cAAc,EAAoC,CAAC;IACrE,cAAc,GAA4C,EAAE,CAAC;IAC7D,YAAY,GAAW,CAAC,CAAC;IACzB,WAAW,GAGd,EAAE,CAAC;IACA,WAAW,GAE4D;QAC7E,UAAU,EAAE,KAAK;KAClB,CAAC;IACM,UAAU,GAAY,KAAK,CAAC;IAC5B,sBAAsB,GAAW,CAAC,CAAC;IACnC,gBAAgB,CAAkB;IAClC,cAAc,CAAS;IACvB,gBAAgB,CAAS;IACzB,yBAAyB,CAAoE;IAC7F,2BAA2B,CAAuE;IAElG,YAAY,CAAS;IACrB,SAAS,CAAyB;IAE1C,YAAY,EACV,eAAe,EACf,aAAa,EACb,eAAe,EACf,wBAAwB,EACxB,0BAA0B,EAC1B,WAAW,EACX,QAAQ,GACsB;QAC9B,IAAI,CAAC,gBAAgB,GAAG,eAAe,CAAC;QACxC,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;QACpC,IAAI,CAAC,gBAAgB,GAAG,eAAe,CAAC;QACxC,IAAI,CAAC,yBAAyB,GAAG,wBAAwB,CAAC;QAC1D,IAAI,CAAC,2BAA2B,GAAG,0BAA0B,CAAC;QA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;YACH,IAAI,CAAC,yBAAyB,CAAC;gBAC7B,KAAK,EAAE,GAAG;gBACV,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc;gBAC7C,WAAW,EAAE,IAAI,CAAC,YAAY;aAC/B,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,CAAU,EAAE,CAAC;YACpB,MAAM,CAAC,KAAK,CACV,iEAAiE,IAAI,CAAC,SAAS,CAC7E,CAAC,EACD,SAAS,EACT,IAAI,CACL,EAAE,CACJ,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;;OAGG;IACK,iBAAiB;QACvB,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC;QAC/B,IAAI,CAAC,KAAK,CAAC,UAAU,IAAI,IAAI,CAAC,uBAAuB,EAAE,KAAK,CAAC,EAAE,CAAC;YAC9D,OAAO;QACT,CAAC;QAED,KAAK,CAAC,OAAO,EAAE,CAAC;QAEhB,IAAI,CAAC,WAAW,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;QACzC,IAAI,CAAC,mBAAmB,EAAE,CAAC;IAC7B,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AmqpAnnotatedMessage } from \"@azure/core-amqp\";\nimport { delay } from \"@azure/core-amqp\";\nimport type {\n EventData,\n EventDataBatch,\n EventHubBufferedProducerClientOptions,\n EventHubProducerClient,\n OperationOptions,\n} from \"./index.js\";\nimport type { AbortOptions } from \"@azure/core-util\";\nimport { isDefined, isObjectWithProperties } from \"@azure/core-util\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport { AwaitableQueue } from \"./impl/awaitableQueue.js\";\nimport { getPromiseParts } from \"./util/getPromiseParts.js\";\nimport { logger } from \"./logger.js\";\nimport { cancelablePromiseRace } from \"@azure/core-util\";\n\nexport interface BatchingPartitionChannelProps {\n loopAbortSignal: AbortSignalLike;\n maxBufferSize: number;\n maxWaitTimeInMs: number;\n partitionId: string;\n producer: EventHubProducerClient;\n /**\n * The handler to call once a batch has successfully published.\n */\n onSendEventsSuccessHandler?: EventHubBufferedProducerClientOptions[\"onSendEventsSuccessHandler\"];\n /**\n * The handler to call when a batch fails to publish.\n */\n onSendEventsErrorHandler: EventHubBufferedProducerClientOptions[\"onSendEventsErrorHandler\"];\n}\n\n/**\n * The `BatchingPartitionChannel` is responsible for accepting enqueued events\n * and optimally batching and sending them to an Event Hub.\n * @internal\n */\nexport class BatchingPartitionChannel {\n private _eventQueue = new AwaitableQueue<EventData | AmqpAnnotatedMessage>();\n private _batchedEvents: Array<EventData | AmqpAnnotatedMessage> = [];\n private _bufferCount: number = 0;\n private _readyQueue: Array<{\n resolve: (value: void) => void;\n reject: (reason?: any) => void;\n }> = [];\n private _flushState:\n | { isFlushing: false }\n | { isFlushing: true; currentPromise: Promise<void>; resolve: () => void } = {\n isFlushing: false,\n };\n private _isRunning: boolean = false;\n private _lastBatchCreationTime: number = 0;\n private _loopAbortSignal: AbortSignalLike;\n private _maxBufferSize: number;\n private _maxWaitTimeInMs: number;\n private _onSendEventsErrorHandler: EventHubBufferedProducerClientOptions[\"onSendEventsErrorHandler\"];\n private _onSendEventsSuccessHandler?: EventHubBufferedProducerClientOptions[\"onSendEventsSuccessHandler\"];\n\n private _partitionId: string;\n private _producer: EventHubProducerClient;\n\n constructor({\n loopAbortSignal,\n maxBufferSize,\n maxWaitTimeInMs,\n onSendEventsErrorHandler,\n onSendEventsSuccessHandler,\n partitionId,\n producer,\n }: BatchingPartitionChannelProps) {\n this._loopAbortSignal = loopAbortSignal;\n this._maxBufferSize = maxBufferSize;\n this._maxWaitTimeInMs = maxWaitTimeInMs;\n this._onSendEventsErrorHandler = onSendEventsErrorHandler;\n this._onSendEventsSuccessHandler = onSendEventsSuccessHandler;\n this._partitionId = partitionId;\n this._producer = producer;\n }\n\n getCurrentBufferedCount(): number {\n return this._bufferCount;\n }\n\n async enqueueEvent(event: EventData | AmqpAnnotatedMessage): Promise<void> {\n await this._ready();\n this._eventQueue.push(event);\n this._bufferCount++;\n\n if (!this._isRunning) {\n this._isRunning = true;\n // Fire-and-forget background loop with error handling\n this._startPublishLoop().catch((e) => {\n logger.error(\n `The following error occurred during batch creation or sending: ${JSON.stringify(\n e,\n undefined,\n \" \",\n )}`,\n );\n });\n }\n }\n\n /**\n * Sets the flush state so that no new events can be enqueued until\n * all the currently buffered events are sent to the Event Hub.\n *\n * Returns a promise that resolves once flushing is complete.\n */\n async flush(_options: OperationOptions = {}): Promise<void> {\n const state = this._flushState;\n if (state.isFlushing) {\n return state.currentPromise;\n }\n\n if (this.getCurrentBufferedCount() === 0) {\n return Promise.resolve();\n }\n\n const { promise, resolve } = getPromiseParts<void>();\n this._flushState = { isFlushing: true, currentPromise: promise, resolve };\n\n return promise;\n }\n\n /**\n * Returns a promise that resolves once there is room for events to be added\n * to the buffer.\n */\n private _ready(): Promise<void> {\n const currentBufferedCount = this.getCurrentBufferedCount();\n\n // If the buffer isn't full and we don't have any pending `ready()` calls,\n // then it's safe to return right away.\n if (\n currentBufferedCount < this._maxBufferSize &&\n !this._readyQueue.length &&\n !this._flushState.isFlushing\n ) {\n return Promise.resolve();\n }\n\n const { promise: readyPromise, reject, resolve } = getPromiseParts<void>();\n this._readyQueue.push({ resolve, reject });\n\n return readyPromise;\n }\n\n /**\n * Starts the loop that creates batches and sends them to the Event Hub.\n *\n * The loop will run until the `_loopAbortSignal` is aborted.\n */\n private async _startPublishLoop() {\n let batch: EventDataBatch | undefined;\n // `eventToAddToBatch` is used to keep track of an event that has been removed\n // from the queue, but has not yet been added to a batch.\n // This prevents losing an event if a `sendBatch` or `createBatch` call fails\n // before the event is added to a batch.\n let eventToAddToBatch: EventData | AmqpAnnotatedMessage | undefined;\n while (!this._loopAbortSignal.aborted) {\n try {\n if (!isDefined(batch)) {\n batch = await this._createBatch();\n }\n const timeSinceLastBatchCreation = Date.now() - this._lastBatchCreationTime;\n const maximumTimeToWaitForEvent = batch.count\n ? Math.max(this._maxWaitTimeInMs - timeSinceLastBatchCreation, 0)\n : this._maxWaitTimeInMs;\n\n const event =\n eventToAddToBatch ??\n (await cancelablePromiseRace<[EventData | AmqpAnnotatedMessage, void]>(\n [\n (abortOptions: AbortOptions) => this._eventQueue.shift(abortOptions),\n (abortOptions: AbortOptions) =>\n delay<void>(\n maximumTimeToWaitForEvent,\n abortOptions.abortSignal,\n abortOptions.abortErrorMsg,\n ),\n ],\n { abortSignal: this._loopAbortSignal },\n ));\n\n if (!event) {\n // We didn't receive an event within the allotted time.\n // Send the existing batch if it has events in it.\n if (batch.count) {\n await this._producer.sendBatch(batch);\n this._reportSuccess();\n batch = await this._createBatch();\n }\n continue;\n } else if (!eventToAddToBatch) {\n eventToAddToBatch = event;\n }\n\n const didAdd = batch.tryAdd(event);\n if (didAdd) {\n // This event will definitely make it to one of the user-provided handlers\n // since it was added to a batch.\n // Store it so we can return it in a handler later.\n this._batchedEvents.push(event);\n // Clear reference to existing event since it has been added to the batch.\n eventToAddToBatch = undefined;\n }\n\n if (didAdd && batch.count >= this._maxBufferSize) {\n // Whenever batch.count exceeds the max count of buffered events, send the batch.\n await this._producer.sendBatch(batch);\n this._reportSuccess();\n batch = await this._createBatch();\n } else if (!didAdd && batch.count) {\n // If the event wasn't able to be added and the current batch isn't empty,\n // attempt to send the current batch and add the event to a new batch.\n await this._producer.sendBatch(batch);\n this._reportSuccess();\n batch = await this._createBatch();\n }\n\n if (!didAdd && !batch.tryAdd(event)) {\n // TODO: Report MaxMesageSizeExceeded error. Mimic service's error.\n this._reportFailure(new Error(\"Placeholder for max message size exceeded\"), event);\n } else if (!didAdd) {\n // Handles the case where the event _was_ successfull added to the new batch.\n this._batchedEvents.push(event);\n }\n // Clear reference to existing event since it has been added to the batch.\n eventToAddToBatch = undefined;\n } catch (err: any) {\n if (!isObjectWithProperties(err, [\"name\"]) || err.name !== \"AbortError\") {\n this._reportFailure(err);\n batch = undefined;\n this._batchedEvents = [];\n }\n }\n }\n }\n\n /**\n * Helper method that returns an `EventDataBatch`.\n * This also has the side effects of\n * - keeping track of batch creation time: needed for maxWaitTime calculations.\n * - clearing reference to batched events.\n * - incrementing the readiness: creating a new batch indicates the buffer\n * should have room, so we can resolve some pending `ready()` calls.\n */\n private async _createBatch(): Promise<EventDataBatch> {\n this._lastBatchCreationTime = Date.now();\n this._batchedEvents = [];\n const batch = await this._producer.createBatch({\n partitionId: this._partitionId,\n });\n this._incrementReadiness();\n return batch;\n }\n\n /**\n * This method will resolve as many pending `ready()` calls as it can\n * based on how much space remains in the buffer.\n *\n * If the channel is currently flushing, this is a no-op. This prevents\n * `enqueueEvent` calls from adding the event to the buffer until flushing\n * completes.\n */\n private _incrementReadiness() {\n if (this._flushState.isFlushing) {\n return;\n }\n const currentBufferedCount = this.getCurrentBufferedCount();\n const num = Math.min(this._maxBufferSize - currentBufferedCount, this._readyQueue.length);\n for (let i = 0; i < num; i++) {\n this._readyQueue.shift()?.resolve();\n }\n }\n\n /**\n * Calls the user-provided `onSendEventsSuccessHandler` with the events\n * that were successfully sent.\n */\n private _reportSuccess() {\n this._bufferCount = this._bufferCount - this._batchedEvents.length;\n this._updateFlushState();\n try {\n this._onSendEventsSuccessHandler?.({\n events: this._batchedEvents,\n partitionId: this._partitionId,\n });\n } catch (e: unknown) {\n logger.error(\n `The following error occurred in the onSendEventsSuccessHandler: ${JSON.stringify(\n e,\n undefined,\n \" \",\n )}`,\n );\n }\n }\n\n /**\n * Calls the user-provided `onSendEventsErrorHandler` with an error and the events\n * that were not successfully sent.\n */\n private _reportFailure(err: any, event?: EventData | AmqpAnnotatedMessage) {\n this._bufferCount = this._bufferCount - (event ? 1 : this._batchedEvents.length);\n this._updateFlushState();\n try {\n this._onSendEventsErrorHandler({\n error: err,\n events: event ? [event] : this._batchedEvents,\n partitionId: this._partitionId,\n });\n } catch (e: unknown) {\n logger.error(\n `The following error occurred in the onSendEventsErrorHandler: ${JSON.stringify(\n e,\n undefined,\n \" \",\n )}`,\n );\n }\n }\n\n /**\n * Updates the channel's flush state once the size of the\n * event buffer has decreased to 0.\n */\n private _updateFlushState() {\n const state = this._flushState;\n if (!state.isFlushing || this.getCurrentBufferedCount() !== 0) {\n return;\n }\n\n state.resolve();\n\n this._flushState = { isFlushing: false };\n this._incrementReadiness();\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"connectionContext.d.ts","sourceRoot":"","sources":["../../src/connectionContext.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAc,UAAU,EAA6B,MAAM,cAAc,CAAC;AAEtF,OAAO,KAAK,EAAyC,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAChG,OAAO,EAEL,qBAAqB,EAGtB,MAAM,kBAAkB,CAAC;AAI1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAG3F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAI1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAG/D;;;;GAIG;AACH,MAAM,WAAW,iBAAkB,SAAQ,qBAAqB;IAC9D;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,wBAAwB,CAAC;IAC1C;;;OAGG;IACH,eAAe,EAAE,gBAAgB,GAAG,eAAe,CAAC;IACpD;;;OAGG;IACH,wBAAwB,EAAE,OAAO,CAAC;IAClC;;OAEG;IACH,SAAS,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC;IACzC;;OAEG;IACH,OAAO,EAAE,UAAU,CAAC,c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;CACxB;AAED;;;;GAIG;AACH,MAAM,WAAW,gCAAiC,SAAQ,iBAAiB;IACzE;;;;;OAKG;IACH,mBAAmB,IAAI,OAAO,CAAC;IAC/B;;OAEG;IACH,wBAAwB,CAAC,OAAO,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,eAAe,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrF;;;OAGG;IACH,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzC;AAED;;GAEG;AACH,MAAM,WAAW,wBAAyB,SAAQ,qBAAqB;IACrE,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,yBAAyB,CAAC,EAAE,MAAM,CAAC;CACpC;AAsBD;;GAEG;AACH,yBAAiB,iBAAiB,CAAC;IASjC,SAAgB,YAAY,CAAC,OAAO,EAAE,wBAAwB,GAAG,MAAM,CAStE;IAED,SAAgB,MAAM,CACpB,MAAM,EAAE,wBAAwB,EAChC,eAAe,EAAE,gBAAgB,GAAG,eAAe,EACnD,OAAO,CAAC,EAAE,wBAAwB,GACjC,iBAAiB,CAmTnB;CACF;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,sBAAsB,EAAE,MAAM,EAC9B,qBAAqB,CAAC,EAAE,MAAM,GAAG,qBAAqB,EACtD,mBAAmB,CAAC,EAChB,eAAe,GACf,kBAAkB,GAClB,aAAa,GACb,qBAAqB,EACzB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,iBAAiB,CAyEnB"}
@@ -127,7 +127,7 @@ export var ConnectionContext;
127
127
  connectionContext.wasConnectionCloseCalled = false;
128
128
  logger.verbose("[%s] setting 'wasConnectionCloseCalled' property of connection context to %s.", connectionContext.connection.id, connectionContext.wasConnectionCloseCalled);
129
129
  };
130
- const onDisconnected = async (context) => {
130
+ async function handleDisconnection(context) {
131
131
  if (waitForConnectionRefreshPromise) {
132
132
  return;
133
133
  }
@@ -137,7 +137,7 @@ export var ConnectionContext;
137
137
  try {
138
138
  logger.verbose("[%s] 'disconnected' event occurred on the amqp connection.", connectionContext.connection.id);
139
139
  if (context.connection && context.connection.error) {
140
- logger.verbose("[%s] Accompanying error on the context.connection: %O", connectionContext.connection.id, context.connection && context.connection.error);
140
+ logger.verbose("[%s] Accompanying error on the context.connection: %O", connectionContext.connection.id, context.connection.error);
141
141
  }
142
142
  if (context.error) {
143
143
  logger.verbose("[%s] Accompanying error on the context: %O", connectionContext.connection.id, context.error);
@@ -182,8 +182,14 @@ export var ConnectionContext;
182
182
  waitForConnectionRefreshResolve();
183
183
  waitForConnectionRefreshPromise = undefined;
184
184
  }
185
+ }
186
+ const onDisconnected = (context) => {
187
+ // Fire-and-forget async operation with error handling
188
+ handleDisconnection(context).catch((err) => {
189
+ logger.verbose(`[${connectionContext.connectionId}] Unhandled error in 'disconnected' event handler. %O`, err);
190
+ });
185
191
  };
186
- const protocolError = async (context) => {
192
+ const protocolError = (context) => {
187
193
  logger.verbose("[%s] 'protocol_error' event occurred on the amqp connection.", connectionContext.connection.id);
188
194
  if (context.connection && context.connection.error) {
189
195
  logger.verbose("[%s] Accompanying error on the context.connection: %O", connectionContext.connection.id, context.connection && context.connection.error);
@@ -192,7 +198,7 @@ export var ConnectionContext;
192
198
  logger.verbose("[%s] Accompanying error on the context: %O", connectionContext.connection.id, context.error);
193
199
  }
194
200
  };
195
- const error = async (context) => {
201
+ const error = (context) => {
196
202
  logger.verbose("[%s] 'error' event occurred on the amqp connection.", connectionContext.connection.id);
197
203
  if (context.connection && context.connection.error) {
198
204
  logger.verbose("[%s] Accompanying error on the context.connection: %O", connectionContext.connection.id, context.connection && context.connection.error);
@@ -1 +1 @@
1
- {"version":3,"file":"connectionContext.js","sourceRoot":"","sources":["../../src/connectionContext.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAMlC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,SAAS,E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AAqB,EAAE,CAAC;QACnC,wBAAwB,CAAC,wBAAwB,CAAC,MAAM,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAC3F,CAAC;IAED,gBAAgB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAElC,OAAO,iBAAiB,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/* eslint-disable @typescript-eslint/no-namespace */\n/* eslint-disable no-inner-declarations */\n\nimport type { Connection, Dictionary, EventContext, OnAmqpEvent } from \"rhea-promise\";\nimport { ConnectionEvents } from \"rhea-promise\";\nimport type { CreateConnectionContextBaseParameters, SasTokenProvider } from \"@azure/core-amqp\";\nimport {\n ConnectionConfig,\n ConnectionContextBase,\n Constants,\n createSasTokenProvider,\n} from \"@azure/core-amqp\";\nimport type { EventHubConnectionStringProperties } from \"./util/connectionStringUtils.js\";\nimport { parseEventHubConnectionString } from \"./util/connectionStringUtils.js\";\nimport type { ManagementClientOptions } from \"./managementClient.js\";\nimport { ManagementClient } from \"./managementClient.js\";\nimport type { NamedKeyCredential, SASCredential, TokenCredential } from \"@azure/core-auth\";\nimport { isNamedKeyCredential, isSASCredential } from \"@azure/core-auth\";\nimport { logErrorStackTrace, logger } from \"./logger.js\";\nimport type { EventHubClientOptions } from \"./models/public.js\";\nimport { EventHubConnectionConfig } from \"./eventhubConnectionConfig.js\";\nimport type { PartitionReceiver } from \"./partitionReceiver.js\";\nimport type { EventHubSender } from \"./eventHubSender.js\";\nimport { getRuntimeInfo } from \"./util/runtimeInfo.js\";\nimport { isCredential } from \"./util/typeGuards.js\";\nimport { packageJsonInfo } from \"./util/constants.js\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport { createAbortablePromise } from \"@azure/core-util\";\n\n/**\n * @internal\n * Provides contextual information like the underlying amqp connection, cbs session, management session,\n * tokenProvider, senders, receivers, etc. about the EventHub client.\n */\nexport interface ConnectionContext extends ConnectionContextBase {\n /**\n * The EventHub connection config that is created after\n * parsing the connection string.\n */\n readonly config: EventHubConnectionConfig;\n /**\n * The credential to be used for Authentication.\n * Default value: SasTokenProvider.\n */\n tokenCredential: SasTokenProvider | TokenCredential;\n /**\n * Indicates whether the close() method was\n * called on theconnection object.\n */\n wasConnectionCloseCalled: boolean;\n /**\n * A dictionary of the EventHub Receivers associated with this client.\n */\n receivers: Dictionary<PartitionReceiver>;\n /**\n * A dictionary of the EventHub Senders associated with this client.\n */\n senders: Dictionary<EventHubSender>;\n /**\n * A reference to the management session ($management endpoint) on\n * the underlying amqp connection for the EventHub Client.\n */\n managementSession?: ManagementClient;\n /**\n * Function returning a promise that resolves once the connectionContext is ready to open an AMQP link.\n * ConnectionContext will be ready to open an AMQP link when:\n * - The AMQP connection is already open on both sides.\n * - The AMQP connection has been closed or disconnected. In this case, a new AMQP connection is expected\n * to be created first.\n * An AMQP link cannot be opened if the AMQP connection\n * is in the process of closing or disconnecting.\n */\n readyToOpenLink(options?: { abortSignal?: AbortSignalLike }): Promise<void>;\n /**\n * Closes all AMQP links, sessions and connection.\n */\n close(): Promise<void>;\n}\n\n/**\n * Describes the members on the ConnectionContext that are only\n * used by it internally.\n * @internal\n */\nexport interface ConnectionContextInternalMembers extends ConnectionContext {\n /**\n * Indicates whether the connection is in the process of closing.\n * When this returns `true`, a `disconnected` event will be received\n * after the connection is closed.\n *\n */\n isConnectionClosing(): boolean;\n /**\n * Resolves once the context's connection emits a `disconnected` event.\n */\n waitForDisconnectedEvent(options?: { abortSignal?: AbortSignalLike }): Promise<void>;\n /**\n * Resolves once the connection has finished being reset.\n * Connections are reset as part of reacting to a `disconnected` event.\n */\n waitForConnectionReset(): Promise<void>;\n}\n\n/**\n * @internal\n */\nexport interface ConnectionContextOptions extends EventHubClientOptions {\n managementSessionAddress?: string;\n managementSessionAudience?: string;\n}\n\n/**\n * Helper type to get the names of all the functions on an object.\n */\ntype FunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? K : never }[keyof T]; // eslint-disable-line @typescript-eslint/no-unsafe-function-type\n/**\n * Helper type to get the types of all the functions on an object.\n */\ntype FunctionProperties<T> = Pick<T, FunctionPropertyNames<T>>;\n/**\n * Helper type to get the types of all the functions on ConnectionContext\n * and the internal methods from ConnectionContextInternalMembers.\n * Note that this excludes the functions that ConnectionContext inherits.\n * Each function also has its `this` type set as `ConnectionContext`.\n */\ntype ConnectionContextMethods = Omit<\n FunctionProperties<ConnectionContextInternalMembers>,\n FunctionPropertyNames<ConnectionContextBase>\n> &\n ThisType<ConnectionContextInternalMembers>;\n\n/**\n * @internal\n */\nexport namespace ConnectionContext {\n /**\n * The user agent string for the EventHubs client.\n * See guideline at https://github.com/Azure/azure-sdk/blob/main/docs/design/Telemetry.mdk\n */\n const userAgent: string = `azsdk-js-azureeventhubs/${\n packageJsonInfo.version\n } (${getRuntimeInfo()})`;\n\n export function getUserAgent(options: ConnectionContextOptions): string {\n const finalUserAgent = options.userAgent ? `${userAgent},${options.userAgent}` : userAgent;\n if (finalUserAgent.length > Constants.maxUserAgentLength) {\n throw new Error(\n `The user-agent string cannot be more than ${Constants.maxUserAgentLength} characters in length.` +\n `The given user-agent string is: ${finalUserAgent} with length: ${finalUserAgent.length}`,\n );\n }\n return finalUserAgent;\n }\n\n export function create(\n config: EventHubConnectionConfig,\n tokenCredential: SasTokenProvider | TokenCredential,\n options?: ConnectionContextOptions,\n ): ConnectionContext {\n if (!options) options = {};\n\n config.webSocket = options.webSocketOptions && options.webSocketOptions.webSocket;\n config.webSocketEndpointPath = \"$servicebus/websocket\";\n config.webSocketConstructorOptions =\n options.webSocketOptions && options.webSocketOptions.webSocketConstructorOptions;\n\n const parameters: CreateConnectionContextBaseParameters = {\n config: config,\n // re-enabling this will be a post-GA discussion.\n // dataTransformer: options.dataTransformer,\n isEntityPathRequired: true,\n connectionProperties: {\n product: \"MSJSClient\",\n userAgent: getUserAgent(options),\n version: packageJsonInfo.version,\n },\n };\n // Let us create the base context and then add EventHub specific ConnectionContext properties.\n const connectionContext = ConnectionContextBase.create(parameters) as ConnectionContext;\n connectionContext.tokenCredential = tokenCredential;\n connectionContext.wasConnectionCloseCalled = false;\n connectionContext.senders = {};\n connectionContext.receivers = {};\n const mOptions: ManagementClientOptions = {\n address: options.managementSessionAddress,\n audience: options.managementSessionAudience,\n };\n connectionContext.managementSession = new ManagementClient(connectionContext, mOptions);\n\n let waitForConnectionRefreshResolve: () => void;\n let waitForConnectionRefreshPromise: Promise<void> | undefined;\n\n Object.assign<ConnectionContext, ConnectionContextMethods>(connectionContext, {\n isConnectionClosing() {\n // When the connection is not open, but the remote end is open,\n // then the rhea connection is in the process of terminating.\n return Boolean(!this.connection.isOpen() && this.connection.isRemoteOpen());\n },\n async readyToOpenLink(optionsArg?: { abortSignal?: AbortSignalLike }) {\n // Check that the connection isn't in the process of closing.\n // This can happen when the idle timeout has been reached but\n // the underlying socket is waiting to be destroyed.\n if (this.isConnectionClosing()) {\n // Wait for the disconnected event that indicates the underlying socket has closed.\n await this.waitForDisconnectedEvent(optionsArg);\n }\n\n // Wait for the connection to be reset.\n await this.waitForConnectionReset();\n },\n waitForDisconnectedEvent(optionsArg?: { abortSignal?: AbortSignalLike }) {\n return createAbortablePromise((resolve) => {\n logger.verbose(\n `[${this.connectionId}] Attempting to reinitialize connection` +\n ` but the connection is in the process of closing.` +\n ` Waiting for the disconnect event before continuing.`,\n );\n this.connection.once(ConnectionEvents.disconnected, resolve);\n }, optionsArg);\n },\n waitForConnectionReset() {\n // Check if the connection is currently in the process of disconnecting.\n if (waitForConnectionRefreshPromise) {\n return waitForConnectionRefreshPromise;\n }\n return Promise.resolve();\n },\n async close() {\n try {\n if (this.connection.isOpen()) {\n // Close all the senders.\n await Promise.all(\n Object.keys(connectionContext.senders).map((name) =>\n connectionContext.senders[name]?.close().catch(() => {\n /* error already logged, swallow it here */\n }),\n ),\n );\n // Close all the receivers.\n await Promise.all(\n Object.keys(connectionContext.receivers).map((name) =>\n connectionContext.receivers[name]?.close().catch(() => {\n /* error already logged, swallow it here */\n }),\n ),\n );\n // Close the cbs session;\n await this.cbsSession.close();\n // Close the management session\n await this.managementSession?.close();\n await this.connection.close();\n this.wasConnectionCloseCalled = true;\n logger.info(\"Closed the amqp connection '%s' on the client.\", this.connectionId);\n }\n } catch (err: any) {\n const errorDescription =\n err instanceof Error ? `${err.name}: ${err.message}` : JSON.stringify(err);\n logger.warning(\n `An error occurred while closing the connection \"${this.connectionId}\":\\n${errorDescription}`,\n );\n logErrorStackTrace(err);\n throw err;\n }\n },\n });\n\n // Define listeners to be added to the connection object for\n // \"connection_open\" and \"connection_error\" events.\n const onConnectionOpen: OnAmqpEvent = () => {\n connectionContext.wasConnectionCloseCalled = false;\n logger.verbose(\n \"[%s] setting 'wasConnectionCloseCalled' property of connection context to %s.\",\n connectionContext.connection.id,\n connectionContext.wasConnectionCloseCalled,\n );\n };\n\n const onDisconnected: OnAmqpEvent = async (context: EventContext) => {\n if (waitForConnectionRefreshPromise) {\n return;\n }\n waitForConnectionRefreshPromise = new Promise((resolve) => {\n waitForConnectionRefreshResolve = resolve;\n });\n try {\n logger.verbose(\n \"[%s] 'disconnected' event occurred on the amqp connection.\",\n connectionContext.connection.id,\n );\n\n if (context.connection && context.connection.error) {\n logger.verbose(\n \"[%s] Accompanying error on the context.connection: %O\",\n connectionContext.connection.id,\n context.connection && context.connection.error,\n );\n }\n if (context.error) {\n logger.verbose(\n \"[%s] Accompanying error on the context: %O\",\n connectionContext.connection.id,\n context.error,\n );\n }\n const state: Readonly<{\n wasConnectionCloseCalled: boolean;\n numSenders: number;\n numReceivers: number;\n }> = {\n wasConnectionCloseCalled: connectionContext.wasConnectionCloseCalled,\n numSenders: Object.keys(connectionContext.senders).length,\n numReceivers: Object.keys(connectionContext.receivers).length,\n };\n logger.verbose(\n \"[%s] Closing all open senders and receivers in the state: %O\",\n connectionContext.connection.id,\n state,\n );\n\n // Clear internal map maintained by rhea to avoid reconnecting of old links once the\n // connection is back up.\n connectionContext.connection.removeAllSessions();\n\n // Close the cbs session to ensure all the event handlers are released.\n await connectionContext.cbsSession?.close().catch(() => {\n /* error already logged, swallow it here */\n });\n // Close the management session to ensure all the event handlers are released.\n await connectionContext.managementSession?.close().catch(() => {\n /* error already logged, swallow it here */\n });\n\n // Close all senders and receivers to ensure clean up of timers & other resources.\n if (state.numSenders || state.numReceivers) {\n await Promise.all(\n Object.keys(connectionContext.senders).map((name) =>\n connectionContext.senders[name]?.close().catch(() => {\n /* error already logged, swallow it here */\n }),\n ),\n );\n\n await Promise.all(\n Object.keys(connectionContext.receivers).map((name) =>\n connectionContext.receivers[name]?.close().catch(() => {\n /* error already logged, swallow it here */\n }),\n ),\n );\n }\n } catch (err: any) {\n logger.verbose(\n `[${connectionContext.connectionId}] An error occurred while closing the connection in 'disconnected'. %O`,\n err,\n );\n }\n\n try {\n await refreshConnection(connectionContext);\n } catch (err: any) {\n logger.verbose(\n `[${connectionContext.connectionId}] An error occurred while refreshing the connection in 'disconnected'. %O`,\n err,\n );\n } finally {\n waitForConnectionRefreshResolve();\n waitForConnectionRefreshPromise = undefined;\n }\n };\n\n const protocolError: OnAmqpEvent = async (context: EventContext) => {\n logger.verbose(\n \"[%s] 'protocol_error' event occurred on the amqp connection.\",\n connectionContext.connection.id,\n );\n\n if (context.connection && context.connection.error) {\n logger.verbose(\n \"[%s] Accompanying error on the context.connection: %O\",\n connectionContext.connection.id,\n context.connection && context.connection.error,\n );\n }\n if (context.error) {\n logger.verbose(\n \"[%s] Accompanying error on the context: %O\",\n connectionContext.connection.id,\n context.error,\n );\n }\n };\n\n const error: OnAmqpEvent = async (context: EventContext) => {\n logger.verbose(\n \"[%s] 'error' event occurred on the amqp connection.\",\n connectionContext.connection.id,\n );\n\n if (context.connection && context.connection.error) {\n logger.verbose(\n \"[%s] Accompanying error on the context.connection: %O\",\n connectionContext.connection.id,\n context.connection && context.connection.error,\n );\n }\n if (context.error) {\n logger.verbose(\n \"[%s] Accompanying error on the context: %O\",\n connectionContext.connection.id,\n context.error,\n );\n }\n };\n\n function addConnectionListeners(connection: Connection): void {\n // Add listeners on the connection object.\n connection.on(ConnectionEvents.connectionOpen, onConnectionOpen);\n connection.on(ConnectionEvents.disconnected, onDisconnected);\n connection.on(ConnectionEvents.protocolError, protocolError);\n connection.on(ConnectionEvents.error, error);\n }\n\n function cleanConnectionContext(context: ConnectionContext): Promise<void> {\n // Remove listeners from the connection object.\n context.connection.removeListener(ConnectionEvents.connectionOpen, onConnectionOpen);\n context.connection.removeListener(ConnectionEvents.disconnected, onDisconnected);\n context.connection.removeListener(ConnectionEvents.protocolError, protocolError);\n context.connection.removeListener(ConnectionEvents.error, error);\n // Close the connection\n return context.connection.close();\n }\n\n async function refreshConnection(context: ConnectionContext): Promise<void> {\n const originalConnectionId = context.connectionId;\n try {\n await cleanConnectionContext(context);\n } catch (err: any) {\n logger.verbose(\n `[${context.connectionId}] There was an error closing the connection before reconnecting: %O`,\n err,\n );\n }\n\n // Create a new connection, id, locks, and cbs client.\n context.refreshConnection();\n addConnectionListeners(context.connection);\n logger.verbose(\n `The connection \"${originalConnectionId}\" has been updated to \"${context.connectionId}\".`,\n );\n }\n\n addConnectionListeners(connectionContext.connection);\n\n logger.verbose(\"[%s] Created connection context successfully.\", connectionContext.connectionId);\n return connectionContext;\n }\n}\n\n/**\n * Helper method to create a ConnectionContext from the input passed to either\n * EventHubProducerClient or EventHubConsumerClient constructors\n *\n * @internal\n */\nexport function createConnectionContext(\n hostOrConnectionString: string,\n eventHubNameOrOptions?: string | EventHubClientOptions,\n credentialOrOptions?:\n | TokenCredential\n | NamedKeyCredential\n | SASCredential\n | EventHubClientOptions,\n options?: EventHubClientOptions,\n): ConnectionContext {\n let connectionString;\n let config;\n let credential: TokenCredential | SasTokenProvider;\n hostOrConnectionString = String(hostOrConnectionString);\n\n if (!isCredential(credentialOrOptions)) {\n const parsedCS = parseEventHubConnectionString(hostOrConnectionString);\n if (\n !(\n parsedCS.eventHubName ||\n (typeof eventHubNameOrOptions === \"string\" && eventHubNameOrOptions)\n )\n ) {\n throw new TypeError(\n `Either provide \"eventHubName\" or the \"connectionString\": \"${hostOrConnectionString}\", ` +\n `must contain \"EntityPath=<your-event-hub-name>\".`,\n );\n }\n if (\n parsedCS.eventHubName &&\n typeof eventHubNameOrOptions === \"string\" &&\n eventHubNameOrOptions &&\n parsedCS.eventHubName !== eventHubNameOrOptions\n ) {\n throw new TypeError(\n `The entity path \"${parsedCS.eventHubName}\" in connectionString: \"${hostOrConnectionString}\" ` +\n `doesn't match with eventHubName: \"${eventHubNameOrOptions}\".`,\n );\n }\n connectionString = hostOrConnectionString;\n if (typeof eventHubNameOrOptions !== \"string\") {\n // connectionstring and/or options were passed to constructor\n config = EventHubConnectionConfig.create(connectionString);\n options = eventHubNameOrOptions;\n } else {\n // connectionstring, eventHubName and/or options were passed to constructor\n const eventHubName = eventHubNameOrOptions;\n config = EventHubConnectionConfig.create(connectionString, eventHubName);\n options = credentialOrOptions;\n }\n\n const parsed = parseEventHubConnectionString(connectionString) as Required<\n | Pick<EventHubConnectionStringProperties, \"sharedAccessKey\" | \"sharedAccessKeyName\">\n | Pick<EventHubConnectionStringProperties, \"sharedAccessSignature\">\n >;\n // Since connectionString was passed, create a TokenProvider.\n credential = createSasTokenProvider(parsed);\n } else {\n // host, eventHubName, a TokenCredential and/or options were passed to constructor\n const eventHubName = eventHubNameOrOptions;\n let host = hostOrConnectionString;\n if (isNamedKeyCredential(credentialOrOptions) || isSASCredential(credentialOrOptions)) {\n credential = createSasTokenProvider(credentialOrOptions);\n } else {\n credential = credentialOrOptions;\n }\n if (!eventHubName) {\n throw new TypeError(`\"eventHubName\" is missing`);\n }\n\n if (!host.endsWith(\"/\")) host += \"/\";\n connectionString = `Endpoint=sb://${host};SharedAccessKeyName=defaultKeyName;SharedAccessKey=defaultKeyValue;EntityPath=${eventHubName}`;\n config = EventHubConnectionConfig.create(connectionString);\n }\n\n if (options?.customEndpointAddress) {\n EventHubConnectionConfig.setCustomEndpointAddress(config, options.customEndpointAddress);\n }\n\n ConnectionConfig.validate(config);\n\n return ConnectionContext.create(config, credential, options);\n}\n"]}
1
+ {"version":3,"file":"connectionContext.js","sourceRoot":"","sources":["../../src/connectionContext.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAMlC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,SAAS,EACT,sBAAsB,GACvB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAEhF,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAEzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAGzE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAwG1D;;GAEG;AACH,MAAM,KAAW,iBAAiB,CA4UjC;AA5UD,WAAiB,iBAAiB;IAChC;;;OAGG;IACH,MAAM,SAAS,GAAW,2BACxB,eAAe,CAAC,OAClB,KAAK,cAAc,EAAE,GAAG,CAAC;IAEzB,SAAgB,YAAY,CAAC,OAAiC;QAC5D,MAAM,cAAc,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;QAC3F,IAAI,cAAc,CAAC,MAAM,GAAG,SA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B,CAAC,mBAAmB,CAAC,IAAI,eAAe,CAAC,mBAAmB,CAAC,EAAE,CAAC;YACtF,UAAU,GAAG,sBAAsB,CAAC,mBAAmB,CAAC,CAAC;QAC3D,CAAC;aAAM,CAAC;YACN,UAAU,GAAG,mBAAmB,CAAC;QACnC,CAAC;QACD,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,MAAM,IAAI,SAAS,CAAC,2BAA2B,CAAC,CAAC;QACnD,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;YAAE,IAAI,IAAI,GAAG,CAAC;QACrC,gBAAgB,GAAG,iBAAiB,IAAI,kFAAkF,YAAY,EAAE,CAAC;QACzI,MAAM,GAAG,wBAAwB,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAC7D,CAAC;IAED,IAAI,OAAO,EAAE,qBAAqB,EAAE,CAAC;QACnC,wBAAwB,CAAC,wBAAwB,CAAC,MAAM,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAC3F,CAAC;IAED,gBAAgB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAElC,OAAO,iBAAiB,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/* eslint-disable @typescript-eslint/no-namespace */\n/* eslint-disable no-inner-declarations */\n\nimport type { Connection, Dictionary, EventContext, OnAmqpEvent } from \"rhea-promise\";\nimport { ConnectionEvents } from \"rhea-promise\";\nimport type { CreateConnectionContextBaseParameters, SasTokenProvider } from \"@azure/core-amqp\";\nimport {\n ConnectionConfig,\n ConnectionContextBase,\n Constants,\n createSasTokenProvider,\n} from \"@azure/core-amqp\";\nimport type { EventHubConnectionStringProperties } from \"./util/connectionStringUtils.js\";\nimport { parseEventHubConnectionString } from \"./util/connectionStringUtils.js\";\nimport type { ManagementClientOptions } from \"./managementClient.js\";\nimport { ManagementClient } from \"./managementClient.js\";\nimport type { NamedKeyCredential, SASCredential, TokenCredential } from \"@azure/core-auth\";\nimport { isNamedKeyCredential, isSASCredential } from \"@azure/core-auth\";\nimport { logErrorStackTrace, logger } from \"./logger.js\";\nimport type { EventHubClientOptions } from \"./models/public.js\";\nimport { EventHubConnectionConfig } from \"./eventhubConnectionConfig.js\";\nimport type { PartitionReceiver } from \"./partitionReceiver.js\";\nimport type { EventHubSender } from \"./eventHubSender.js\";\nimport { getRuntimeInfo } from \"./util/runtimeInfo.js\";\nimport { isCredential } from \"./util/typeGuards.js\";\nimport { packageJsonInfo } from \"./util/constants.js\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport { createAbortablePromise } from \"@azure/core-util\";\n\n/**\n * @internal\n * Provides contextual information like the underlying amqp connection, cbs session, management session,\n * tokenProvider, senders, receivers, etc. about the EventHub client.\n */\nexport interface ConnectionContext extends ConnectionContextBase {\n /**\n * The EventHub connection config that is created after\n * parsing the connection string.\n */\n readonly config: EventHubConnectionConfig;\n /**\n * The credential to be used for Authentication.\n * Default value: SasTokenProvider.\n */\n tokenCredential: SasTokenProvider | TokenCredential;\n /**\n * Indicates whether the close() method was\n * called on theconnection object.\n */\n wasConnectionCloseCalled: boolean;\n /**\n * A dictionary of the EventHub Receivers associated with this client.\n */\n receivers: Dictionary<PartitionReceiver>;\n /**\n * A dictionary of the EventHub Senders associated with this client.\n */\n senders: Dictionary<EventHubSender>;\n /**\n * A reference to the management session ($management endpoint) on\n * the underlying amqp connection for the EventHub Client.\n */\n managementSession?: ManagementClient;\n /**\n * Function returning a promise that resolves once the connectionContext is ready to open an AMQP link.\n * ConnectionContext will be ready to open an AMQP link when:\n * - The AMQP connection is already open on both sides.\n * - The AMQP connection has been closed or disconnected. In this case, a new AMQP connection is expected\n * to be created first.\n * An AMQP link cannot be opened if the AMQP connection\n * is in the process of closing or disconnecting.\n */\n readyToOpenLink(options?: { abortSignal?: AbortSignalLike }): Promise<void>;\n /**\n * Closes all AMQP links, sessions and connection.\n */\n close(): Promise<void>;\n}\n\n/**\n * Describes the members on the ConnectionContext that are only\n * used by it internally.\n * @internal\n */\nexport interface ConnectionContextInternalMembers extends ConnectionContext {\n /**\n * Indicates whether the connection is in the process of closing.\n * When this returns `true`, a `disconnected` event will be received\n * after the connection is closed.\n *\n */\n isConnectionClosing(): boolean;\n /**\n * Resolves once the context's connection emits a `disconnected` event.\n */\n waitForDisconnectedEvent(options?: { abortSignal?: AbortSignalLike }): Promise<void>;\n /**\n * Resolves once the connection has finished being reset.\n * Connections are reset as part of reacting to a `disconnected` event.\n */\n waitForConnectionReset(): Promise<void>;\n}\n\n/**\n * @internal\n */\nexport interface ConnectionContextOptions extends EventHubClientOptions {\n managementSessionAddress?: string;\n managementSessionAudience?: string;\n}\n\n/**\n * Helper type to get the names of all the functions on an object.\n */\ntype FunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? K : never }[keyof T]; // eslint-disable-line @typescript-eslint/no-unsafe-function-type\n/**\n * Helper type to get the types of all the functions on an object.\n */\ntype FunctionProperties<T> = Pick<T, FunctionPropertyNames<T>>;\n/**\n * Helper type to get the types of all the functions on ConnectionContext\n * and the internal methods from ConnectionContextInternalMembers.\n * Note that this excludes the functions that ConnectionContext inherits.\n * Each function also has its `this` type set as `ConnectionContext`.\n */\ntype ConnectionContextMethods = Omit<\n FunctionProperties<ConnectionContextInternalMembers>,\n FunctionPropertyNames<ConnectionContextBase>\n> &\n ThisType<ConnectionContextInternalMembers>;\n\n/**\n * @internal\n */\nexport namespace ConnectionContext {\n /**\n * The user agent string for the EventHubs client.\n * See guideline at https://github.com/Azure/azure-sdk/blob/main/docs/design/Telemetry.mdk\n */\n const userAgent: string = `azsdk-js-azureeventhubs/${\n packageJsonInfo.version\n } (${getRuntimeInfo()})`;\n\n export function getUserAgent(options: ConnectionContextOptions): string {\n const finalUserAgent = options.userAgent ? `${userAgent},${options.userAgent}` : userAgent;\n if (finalUserAgent.length > Constants.maxUserAgentLength) {\n throw new Error(\n `The user-agent string cannot be more than ${Constants.maxUserAgentLength} characters in length.` +\n `The given user-agent string is: ${finalUserAgent} with length: ${finalUserAgent.length}`,\n );\n }\n return finalUserAgent;\n }\n\n export function create(\n config: EventHubConnectionConfig,\n tokenCredential: SasTokenProvider | TokenCredential,\n options?: ConnectionContextOptions,\n ): ConnectionContext {\n if (!options) options = {};\n\n config.webSocket = options.webSocketOptions && options.webSocketOptions.webSocket;\n config.webSocketEndpointPath = \"$servicebus/websocket\";\n config.webSocketConstructorOptions =\n options.webSocketOptions && options.webSocketOptions.webSocketConstructorOptions;\n\n const parameters: CreateConnectionContextBaseParameters = {\n config: config,\n // re-enabling this will be a post-GA discussion.\n // dataTransformer: options.dataTransformer,\n isEntityPathRequired: true,\n connectionProperties: {\n product: \"MSJSClient\",\n userAgent: getUserAgent(options),\n version: packageJsonInfo.version,\n },\n };\n // Let us create the base context and then add EventHub specific ConnectionContext properties.\n const connectionContext = ConnectionContextBase.create(parameters) as ConnectionContext;\n connectionContext.tokenCredential = tokenCredential;\n connectionContext.wasConnectionCloseCalled = false;\n connectionContext.senders = {};\n connectionContext.receivers = {};\n const mOptions: ManagementClientOptions = {\n address: options.managementSessionAddress,\n audience: options.managementSessionAudience,\n };\n connectionContext.managementSession = new ManagementClient(connectionContext, mOptions);\n\n let waitForConnectionRefreshResolve: () => void;\n let waitForConnectionRefreshPromise: Promise<void> | undefined;\n\n Object.assign<ConnectionContext, ConnectionContextMethods>(connectionContext, {\n isConnectionClosing() {\n // When the connection is not open, but the remote end is open,\n // then the rhea connection is in the process of terminating.\n return Boolean(!this.connection.isOpen() && this.connection.isRemoteOpen());\n },\n async readyToOpenLink(optionsArg?: { abortSignal?: AbortSignalLike }) {\n // Check that the connection isn't in the process of closing.\n // This can happen when the idle timeout has been reached but\n // the underlying socket is waiting to be destroyed.\n if (this.isConnectionClosing()) {\n // Wait for the disconnected event that indicates the underlying socket has closed.\n await this.waitForDisconnectedEvent(optionsArg);\n }\n\n // Wait for the connection to be reset.\n await this.waitForConnectionReset();\n },\n waitForDisconnectedEvent(optionsArg?: { abortSignal?: AbortSignalLike }) {\n return createAbortablePromise((resolve) => {\n logger.verbose(\n `[${this.connectionId}] Attempting to reinitialize connection` +\n ` but the connection is in the process of closing.` +\n ` Waiting for the disconnect event before continuing.`,\n );\n this.connection.once(ConnectionEvents.disconnected, resolve);\n }, optionsArg);\n },\n waitForConnectionReset() {\n // Check if the connection is currently in the process of disconnecting.\n if (waitForConnectionRefreshPromise) {\n return waitForConnectionRefreshPromise;\n }\n return Promise.resolve();\n },\n async close() {\n try {\n if (this.connection.isOpen()) {\n // Close all the senders.\n await Promise.all(\n Object.keys(connectionContext.senders).map((name) =>\n connectionContext.senders[name]?.close().catch(() => {\n /* error already logged, swallow it here */\n }),\n ),\n );\n // Close all the receivers.\n await Promise.all(\n Object.keys(connectionContext.receivers).map((name) =>\n connectionContext.receivers[name]?.close().catch(() => {\n /* error already logged, swallow it here */\n }),\n ),\n );\n // Close the cbs session;\n await this.cbsSession.close();\n // Close the management session\n await this.managementSession?.close();\n await this.connection.close();\n this.wasConnectionCloseCalled = true;\n logger.info(\"Closed the amqp connection '%s' on the client.\", this.connectionId);\n }\n } catch (err: any) {\n const errorDescription =\n err instanceof Error ? `${err.name}: ${err.message}` : JSON.stringify(err);\n logger.warning(\n `An error occurred while closing the connection \"${this.connectionId}\":\\n${errorDescription}`,\n );\n logErrorStackTrace(err);\n throw err;\n }\n },\n });\n\n // Define listeners to be added to the connection object for\n // \"connection_open\" and \"connection_error\" events.\n const onConnectionOpen: OnAmqpEvent = () => {\n connectionContext.wasConnectionCloseCalled = false;\n logger.verbose(\n \"[%s] setting 'wasConnectionCloseCalled' property of connection context to %s.\",\n connectionContext.connection.id,\n connectionContext.wasConnectionCloseCalled,\n );\n };\n\n async function handleDisconnection(context: EventContext): Promise<void> {\n if (waitForConnectionRefreshPromise) {\n return;\n }\n waitForConnectionRefreshPromise = new Promise((resolve) => {\n waitForConnectionRefreshResolve = resolve;\n });\n try {\n logger.verbose(\n \"[%s] 'disconnected' event occurred on the amqp connection.\",\n connectionContext.connection.id,\n );\n\n if (context.connection && context.connection.error) {\n logger.verbose(\n \"[%s] Accompanying error on the context.connection: %O\",\n connectionContext.connection.id,\n context.connection.error,\n );\n }\n if (context.error) {\n logger.verbose(\n \"[%s] Accompanying error on the context: %O\",\n connectionContext.connection.id,\n context.error,\n );\n }\n const state: Readonly<{\n wasConnectionCloseCalled: boolean;\n numSenders: number;\n numReceivers: number;\n }> = {\n wasConnectionCloseCalled: connectionContext.wasConnectionCloseCalled,\n numSenders: Object.keys(connectionContext.senders).length,\n numReceivers: Object.keys(connectionContext.receivers).length,\n };\n logger.verbose(\n \"[%s] Closing all open senders and receivers in the state: %O\",\n connectionContext.connection.id,\n state,\n );\n\n // Clear internal map maintained by rhea to avoid reconnecting of old links once the\n // connection is back up.\n connectionContext.connection.removeAllSessions();\n\n // Close the cbs session to ensure all the event handlers are released.\n await connectionContext.cbsSession?.close().catch(() => {\n /* error already logged, swallow it here */\n });\n // Close the management session to ensure all the event handlers are released.\n await connectionContext.managementSession?.close().catch(() => {\n /* error already logged, swallow it here */\n });\n\n // Close all senders and receivers to ensure clean up of timers & other resources.\n if (state.numSenders || state.numReceivers) {\n await Promise.all(\n Object.keys(connectionContext.senders).map((name) =>\n connectionContext.senders[name]?.close().catch(() => {\n /* error already logged, swallow it here */\n }),\n ),\n );\n\n await Promise.all(\n Object.keys(connectionContext.receivers).map((name) =>\n connectionContext.receivers[name]?.close().catch(() => {\n /* error already logged, swallow it here */\n }),\n ),\n );\n }\n } catch (err: any) {\n logger.verbose(\n `[${connectionContext.connectionId}] An error occurred while closing the connection in 'disconnected'. %O`,\n err,\n );\n }\n\n try {\n await refreshConnection(connectionContext);\n } catch (err: any) {\n logger.verbose(\n `[${connectionContext.connectionId}] An error occurred while refreshing the connection in 'disconnected'. %O`,\n err,\n );\n } finally {\n waitForConnectionRefreshResolve();\n waitForConnectionRefreshPromise = undefined;\n }\n }\n\n const onDisconnected: OnAmqpEvent = (context: EventContext) => {\n // Fire-and-forget async operation with error handling\n handleDisconnection(context).catch((err) => {\n logger.verbose(\n `[${connectionContext.connectionId}] Unhandled error in 'disconnected' event handler. %O`,\n err,\n );\n });\n };\n\n const protocolError: OnAmqpEvent = (context: EventContext) => {\n logger.verbose(\n \"[%s] 'protocol_error' event occurred on the amqp connection.\",\n connectionContext.connection.id,\n );\n\n if (context.connection && context.connection.error) {\n logger.verbose(\n \"[%s] Accompanying error on the context.connection: %O\",\n connectionContext.connection.id,\n context.connection && context.connection.error,\n );\n }\n if (context.error) {\n logger.verbose(\n \"[%s] Accompanying error on the context: %O\",\n connectionContext.connection.id,\n context.error,\n );\n }\n };\n\n const error: OnAmqpEvent = (context: EventContext) => {\n logger.verbose(\n \"[%s] 'error' event occurred on the amqp connection.\",\n connectionContext.connection.id,\n );\n\n if (context.connection && context.connection.error) {\n logger.verbose(\n \"[%s] Accompanying error on the context.connection: %O\",\n connectionContext.connection.id,\n context.connection && context.connection.error,\n );\n }\n if (context.error) {\n logger.verbose(\n \"[%s] Accompanying error on the context: %O\",\n connectionContext.connection.id,\n context.error,\n );\n }\n };\n\n function addConnectionListeners(connection: Connection): void {\n // Add listeners on the connection object.\n connection.on(ConnectionEvents.connectionOpen, onConnectionOpen);\n connection.on(ConnectionEvents.disconnected, onDisconnected);\n connection.on(ConnectionEvents.protocolError, protocolError);\n connection.on(ConnectionEvents.error, error);\n }\n\n function cleanConnectionContext(context: ConnectionContext): Promise<void> {\n // Remove listeners from the connection object.\n context.connection.removeListener(ConnectionEvents.connectionOpen, onConnectionOpen);\n context.connection.removeListener(ConnectionEvents.disconnected, onDisconnected);\n context.connection.removeListener(ConnectionEvents.protocolError, protocolError);\n context.connection.removeListener(ConnectionEvents.error, error);\n // Close the connection\n return context.connection.close();\n }\n\n async function refreshConnection(context: ConnectionContext): Promise<void> {\n const originalConnectionId = context.connectionId;\n try {\n await cleanConnectionContext(context);\n } catch (err: any) {\n logger.verbose(\n `[${context.connectionId}] There was an error closing the connection before reconnecting: %O`,\n err,\n );\n }\n\n // Create a new connection, id, locks, and cbs client.\n context.refreshConnection();\n addConnectionListeners(context.connection);\n logger.verbose(\n `The connection \"${originalConnectionId}\" has been updated to \"${context.connectionId}\".`,\n );\n }\n\n addConnectionListeners(connectionContext.connection);\n\n logger.verbose(\"[%s] Created connection context successfully.\", connectionContext.connectionId);\n return connectionContext;\n }\n}\n\n/**\n * Helper method to create a ConnectionContext from the input passed to either\n * EventHubProducerClient or EventHubConsumerClient constructors\n *\n * @internal\n */\nexport function createConnectionContext(\n hostOrConnectionString: string,\n eventHubNameOrOptions?: string | EventHubClientOptions,\n credentialOrOptions?:\n | TokenCredential\n | NamedKeyCredential\n | SASCredential\n | EventHubClientOptions,\n options?: EventHubClientOptions,\n): ConnectionContext {\n let connectionString;\n let config;\n let credential: TokenCredential | SasTokenProvider;\n hostOrConnectionString = String(hostOrConnectionString);\n\n if (!isCredential(credentialOrOptions)) {\n const parsedCS = parseEventHubConnectionString(hostOrConnectionString);\n if (\n !(\n parsedCS.eventHubName ||\n (typeof eventHubNameOrOptions === \"string\" && eventHubNameOrOptions)\n )\n ) {\n throw new TypeError(\n `Either provide \"eventHubName\" or the \"connectionString\": \"${hostOrConnectionString}\", ` +\n `must contain \"EntityPath=<your-event-hub-name>\".`,\n );\n }\n if (\n parsedCS.eventHubName &&\n typeof eventHubNameOrOptions === \"string\" &&\n eventHubNameOrOptions &&\n parsedCS.eventHubName !== eventHubNameOrOptions\n ) {\n throw new TypeError(\n `The entity path \"${parsedCS.eventHubName}\" in connectionString: \"${hostOrConnectionString}\" ` +\n `doesn't match with eventHubName: \"${eventHubNameOrOptions}\".`,\n );\n }\n connectionString = hostOrConnectionString;\n if (typeof eventHubNameOrOptions !== \"string\") {\n // connectionstring and/or options were passed to constructor\n config = EventHubConnectionConfig.create(connectionString);\n options = eventHubNameOrOptions;\n } else {\n // connectionstring, eventHubName and/or options were passed to constructor\n const eventHubName = eventHubNameOrOptions;\n config = EventHubConnectionConfig.create(connectionString, eventHubName);\n options = credentialOrOptions;\n }\n\n const parsed = parseEventHubConnectionString(connectionString) as Required<\n | Pick<EventHubConnectionStringProperties, \"sharedAccessKey\" | \"sharedAccessKeyName\">\n | Pick<EventHubConnectionStringProperties, \"sharedAccessSignature\">\n >;\n // Since connectionString was passed, create a TokenProvider.\n credential = createSasTokenProvider(parsed);\n } else {\n // host, eventHubName, a TokenCredential and/or options were passed to constructor\n const eventHubName = eventHubNameOrOptions;\n let host = hostOrConnectionString;\n if (isNamedKeyCredential(credentialOrOptions) || isSASCredential(credentialOrOptions)) {\n credential = createSasTokenProvider(credentialOrOptions);\n } else {\n credential = credentialOrOptions;\n }\n if (!eventHubName) {\n throw new TypeError(`\"eventHubName\" is missing`);\n }\n\n if (!host.endsWith(\"/\")) host += \"/\";\n connectionString = `Endpoint=sb://${host};SharedAccessKeyName=defaultKeyName;SharedAccessKey=defaultKeyValue;EntityPath=${eventHubName}`;\n config = EventHubConnectionConfig.create(connectionString);\n }\n\n if (options?.customEndpointAddress) {\n EventHubConnectionConfig.setCustomEndpointAddress(config, options.customEndpointAddress);\n }\n\n ConnectionConfig.validate(config);\n\n return ConnectionContext.create(config, credential, options);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"eventHubBufferedProducerClient.d.ts","sourceRoot":"","sources":["../../src/eventHubBufferedProducerClient.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,KAAK,EACV,qBAAqB,EACrB,4BAA4B,EAC5B,sBAAsB,EACtB,6BAA6B,EAC7B,gBAAgB,EACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACrF,OAAO,KAAK,EA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;;;;;OAOG;IACH,sBAAsB,CACpB,WAAW,EAAE,MAAM,EACnB,OAAO,GAAE,6BAAkC,GAC1C,OAAO,CAAC,mBAAmB,CAAC;IAI/B;;;;OAIG;IACH,OAAO,CAAC,oBAAoB;IAgB5B;;OAEG;IACH,OAAO,CAAC,4BAA4B;YAStB,mBAAmB;YAWnB,4BAA4B;CAS3C"}
@@ -167,8 +167,9 @@ export class EventHubBufferedProducerClient {
167
167
  await this._updatePartitionIds();
168
168
  }
169
169
  if (!this._isBackgroundManagementRunning) {
170
+ // Fire-and-forget background loop with error handling
170
171
  this._startPartitionIdsUpdateLoop().catch((e) => {
171
- logger.error(`The following error occured during batch creation or sending: ${JSON.stringify(e, undefined, " ")}`);
172
+ logger.error(`The following error occurred during partition ID update loop: ${JSON.stringify(e, undefined, " ")}`);
172
173
  });
173
174
  this._isBackgroundManagementRunning = true;
174
175
  }
@@ -1 +1 @@
1
- {"version":3,"file":"eventHubBufferedProducerClient.js","sourceRoot":"","sources":["../../src/eventHubBufferedProducerClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAWrE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AA4FhD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,OAAO,8BAA8B;IACzC;;;OAGG;IACK,gBAAgB,GAAG,IAAI,eAAe,EAAE,CAAC;IA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K,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;YACnD,KAAK,IAAI,OAAO,CAAC,uBAAuB,EAAE,CAAC;QAC7C,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,KAAK,CAAC,mBAAmB;QAC/B,MAAM,CAAC,OAAO,CAAC,sCAAsC,CAAC,CAAC;QACvD,MAAM,mBAAmB,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;QAEzD,IAAI,IAAI,CAAC,aAAa,CAAC,MAAM,KAAK,mBAAmB,CAAC,MAAM,EAAE,CAAC;YAC7D,MAAM,CAAC,OAAO,CAAC,+BAA+B,CAAC,CAAC;YAChD,IAAI,CAAC,aAAa,GAAG,mBAAmB,CAAC;YACzC,IAAI,CAAC,kBAAkB,CAAC,eAAe,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,4BAA4B;QACxC,MAAM,CAAC,OAAO,CAAC,uEAAuE,CAAC,CAAC;QACxF,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YAChE,MAAM,KAAK,CAAO,IAAI,CAAC,6BAA6B,CAAC,CAAC;YACtD,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;gBACpB,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAC;YACnC,CAAC;QACH,CAAC;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { EventData } from \"./eventData.js\";\nimport { EventHubProducerClient } from \"./eventHubProducerClient.js\";\nimport type { OperationOptions } from \"./util/operationOptions.js\";\nimport type {\n EventHubClientOptions,\n GetEventHubPropertiesOptions,\n GetPartitionIdsOptions,\n GetPartitionPropertiesOptions,\n SendBatchOptions,\n} from \"./models/public.js\";\nimport type { EventHubProperties, PartitionProperties } from \"./managementClient.js\";\nimport type { NamedKeyCredential, SASCredential, TokenCredential } from \"@azure/core-auth\";\nimport { isDefined } from \"@azure/core-util\";\nimport { isCredential } from \"./util/typeGuards.js\";\nimport type { AmqpAnnotatedMessage } from \"@azure/core-amqp\";\nimport { delay } from \"@azure/core-amqp\";\nimport { BatchingPartitionChannel } from \"./batchingPartitionChannel.js\";\nimport { PartitionAssigner } from \"./impl/partitionAssigner.js\";\nimport { logger } from \"./logger.js\";\nimport { getRandomName } from \"./util/utils.js\";\n\n/**\n * Contains the events that were successfully sent to the Event Hub,\n * and the partition they were assigned to.\n */\nexport interface OnSendEventsSuccessContext {\n /**\n * The partition each event was assigned.\n */\n partitionId: string;\n /**\n * The array of {@link EventData} and/or `AmqpAnnotatedMessage` that were successfully sent to the Event Hub.\n */\n events: Array<EventData | AmqpAnnotatedMessage>;\n}\n\n/**\n * Contains the events that were not successfully sent to the Event Hub,\n * the partition they were assigned to, and the error that was encountered while sending.\n */\nexport interface OnSendEventsErrorContext {\n /**\n * The partition each event was assigned.\n */\n partitionId: string;\n /**\n * The array of {@link EventData} and/or `AmqpAnnotatedMessage` that were not successfully sent to the Event Hub.\n */\n events: Array<EventData | AmqpAnnotatedMessage>;\n /**\n * The error that occurred when sending the associated events to the Event Hub.\n */\n error: Error;\n}\n\n/**\n * Describes the options that can be provided while creating the `EventHubBufferedProducerClient`.\n */\nexport interface EventHubBufferedProducerClientOptions extends EventHubClientOptions {\n /**\n * The total number of events that can be buffered for publishing at a given time for a given partition.\n *\n * Default: 1500\n */\n maxEventBufferLengthPerPartition?: number;\n /**\n * The amount of time to wait for a new event to be enqueued in the buffer before publishing a partially full batch.\n *\n * Default: 1 second.\n */\n maxWaitTimeInMs?: number;\n /**\n * The handler to call once a batch has successfully published.\n */\n onSendEventsSuccessHandler?: (ctx: OnSendEventsSuccessContext) => void;\n /**\n * The handler to call when a batch fails to publish.\n */\n onSendEventsErrorHandler: (ctx: OnSendEventsErrorContext) => void;\n /**\n * Indicates whether or not the EventHubProducerClient should enable idempotent publishing to Event Hub partitions.\n * If enabled, the producer will only be able to publish directly to partitions;\n * it will not be able to publish to the Event Hubs gateway for automatic partition routing\n * nor will it be able to use a partition key.\n * Default: false\n */\n enableIdempotentRetries?: boolean;\n}\n\n/**\n * Options to configure the `flush` method on the `EventHubBufferedProducerClient`.\n */\nexport interface BufferedFlushOptions extends OperationOptions {}\n\n/**\n * Options to configure the `close` method on the `EventHubBufferedProducerClient`.\n */\nexport interface BufferedCloseOptions extends OperationOptions {\n /**\n * When `true`, all buffered events that are pending should be sent before closing.\n * When `false`, abandon all buffered events and close immediately.\n * Defaults to `true`.\n */\n flush?: boolean;\n}\n\n/**\n * Options to configure the `enqueueEvents` method on the `EventHubBufferedProducerClient`.\n */\nexport interface EnqueueEventOptions extends SendBatchOptions {}\n\n/**\n * The `EventHubBufferedProducerClient`is used to publish events to a specific Event Hub.\n *\n * The `EventHubBufferedProducerClient` does not publish events immediately.\n * Instead, events are buffered so they can be efficiently batched and published\n * when the batch is full or the `maxWaitTimeInMs` has elapsed with no new events\n * enqueued.\n *\n * Depending on the options specified when events are enqueued, they may be\n * automatically assigned to a partition, grouped according to the specified partition key,\n * or assigned a specifically requested partition.\n *\n * This model is intended to shift the burden of batch management from callers, at the cost of\n * non-deterministic timing, for when events will be published. There are additional trade-offs\n * to consider, as well:\n * - If the application crashes, events in the buffer will not have been published. To prevent\n * data loss, callers are encouraged to track publishing progress using the\n * `onSendEventsSuccessHandler` and `onSendEventsErrorHandler` handlers.\n * - Events specifying a partition key may be assigned a different partition than those using\n * the same key with other producers.\n * - In the unlikely event that a partition becomes temporarily unavailable, the\n * `EventHubBufferedProducerClient` may take longer to recover than other producers.\n *\n * In scenarios where it is important to have events published immediately with a deterministic\n * outcome, ensure that partition keys are assigned to a partition consistent with other\n * publishers, or where maximizing availability is a requirement, using the\n * `EventHubProducerClient` is recommended.\n */\nexport class EventHubBufferedProducerClient {\n /**\n * Controls the `abortSignal` passed to each `BatchingPartitionChannel`.\n * Used to signal when a channel should stop waiting for events.\n */\n private _abortController = new AbortController();\n\n /**\n * Indicates whether the client has been explicitly closed.\n */\n private _isClosed: boolean = false;\n\n /**\n * Handles assigning partitions.\n */\n private _partitionAssigner = new PartitionAssigner();\n\n /**\n * The known partitionIds that will be used when assigning events to partitions.\n */\n private _partitionIds: string[] = [];\n\n /**\n * The EventHubProducerClient to use when creating and sending batches to the Event Hub.\n */\n private _producer: EventHubProducerClient;\n\n /**\n * Mapping of partitionIds to `BatchingPartitionChannels`.\n * Each `BatchingPartitionChannel` handles buffering events and backpressure independently.\n */\n private _partitionChannels = new Map<string, BatchingPartitionChannel>();\n\n /**\n * The options passed by the user when creating the EventHubBufferedProducerClient instance.\n */\n private _clientOptions: EventHubBufferedProducerClientOptions;\n\n /**\n * The interval at which the background management operation should run.\n */\n private _backgroundManagementInterval = 10000; // 10 seconds\n\n /**\n * Indicates whether the background management loop is running.\n */\n private _isBackgroundManagementRunning = false;\n\n /**\n * @readonly\n * The name of the Event Hub instance for which this client is created.\n */\n get eventHubName(): string {\n return this._producer.eventHubName;\n }\n\n /**\n * @readonly\n * The fully qualified namespace of the Event Hub instance for which this client is created.\n * This is likely to be similar to <yournamespace>.servicebus.windows.net.\n */\n get fullyQualifiedNamespace(): string {\n return this._producer.fullyQualifiedNamespace;\n }\n\n /**\n * The name used to identify this EventHubBufferedProducerClient.\n * If not specified or empty, a random unique one will be generated.\n */\n public readonly identifier: string;\n\n /**\n * The `EventHubBufferedProducerClient` class is used to send events to an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param connectionString - The connection string to use for connecting to the Event Hub instance.\n * It is expected that the shared key properties and the Event Hub path are contained in this connection string.\n * e.g. 'Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key;EntityPath=my-event-hub-name'.\n * @param options - A set of options to apply when configuring the client.\n * - `retryOptions` : Configures the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n * - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.\n * - `userAgent` : A string to append to the built in user agent string that is passed to the service.\n */\n constructor(connectionString: string, options: EventHubBufferedProducerClientOptions);\n /**\n * The `EventHubBufferedProducerClient` class is used to send events to an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param connectionString - The connection string to use for connecting to the Event Hubs namespace.\n * It is expected that the shared key properties are contained in this connection string, but not the Event Hub path,\n * e.g. 'Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key;'.\n * @param eventHubName - The name of the specific Event Hub to connect the client to.\n * @param options - A set of options to apply when configuring the client.\n * - `retryOptions` : Configures the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n * - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.\n * - `userAgent` : A string to append to the built in user agent string that is passed to the service.\n */\n constructor(\n connectionString: string,\n eventHubName: string,\n options: EventHubBufferedProducerClientOptions,\n );\n /**\n * The `EventHubBufferedProducerClient` class is used to send events to an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param fullyQualifiedNamespace - The full namespace which is likely to be similar to\n * <yournamespace>.servicebus.windows.net\n * @param eventHubName - The name of the specific Event Hub to connect the client to.\n * @param credential - An credential object used by the client to get the token to authenticate the connection\n * with the Azure Event Hubs service.\n * See &commat;azure/identity for creating credentials that support AAD auth.\n * Use the `AzureNamedKeyCredential` from &commat;azure/core-auth if you want to pass in a `SharedAccessKeyName`\n * and `SharedAccessKey` without using a connection string. These fields map to the `name` and `key` field respectively\n * in `AzureNamedKeyCredential`.\n * Use the `AzureSASCredential` from &commat;azure/core-auth if you want to pass in a `SharedAccessSignature`\n * without using a connection string. This field maps to `signature` in `AzureSASCredential`.\n * @param options - A set of options to apply when configuring the client.\n * - `retryOptions` : Configures the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n * - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.\n * - `userAgent` : A string to append to the built in user agent string that is passed to the service.\n */\n constructor(\n fullyQualifiedNamespace: string,\n eventHubName: string,\n credential: TokenCredential | NamedKeyCredential | SASCredential,\n options: EventHubBufferedProducerClientOptions,\n );\n constructor(\n fullyQualifiedNamespaceOrConnectionString1: string,\n eventHubNameOrOptions2: string | EventHubBufferedProducerClientOptions,\n credentialOrOptions3?:\n | TokenCredential\n | NamedKeyCredential\n | SASCredential\n | EventHubBufferedProducerClientOptions,\n options4?: EventHubBufferedProducerClientOptions,\n ) {\n if (typeof eventHubNameOrOptions2 !== \"string\") {\n this.identifier = eventHubNameOrOptions2.identifier ?? getRandomName();\n this._producer = new EventHubProducerClient(fullyQualifiedNamespaceOrConnectionString1, {\n ...eventHubNameOrOptions2,\n identifier: this.identifier,\n });\n this._clientOptions = { ...eventHubNameOrOptions2 };\n } else if (!isCredential(credentialOrOptions3)) {\n this.identifier = credentialOrOptions3?.identifier ?? getRandomName();\n this._producer = new EventHubProducerClient(\n fullyQualifiedNamespaceOrConnectionString1,\n eventHubNameOrOptions2,\n { ...credentialOrOptions3, identifier: this.identifier },\n );\n this._clientOptions = { ...credentialOrOptions3! };\n } else {\n this.identifier = options4?.identifier ?? getRandomName();\n this._producer = new EventHubProducerClient(\n fullyQualifiedNamespaceOrConnectionString1,\n eventHubNameOrOptions2,\n credentialOrOptions3,\n { ...options4, identifier: this.identifier },\n );\n this._clientOptions = { ...options4! };\n }\n // setting internal idempotent publishing option on the standard producer.\n (this._producer as any)._enableIdempotentRetries = this._clientOptions.enableIdempotentRetries;\n }\n\n /**\n * Closes the AMQP connection to the Event Hub instance,\n * returning a promise that will be resolved when disconnection is completed.\n *\n * This will wait for enqueued events to be flushed to the service before closing\n * the connection.\n * To close without flushing, set the `flush` option to `false`.\n *\n * @param options - The set of options to apply to the operation call.\n * @returns Promise<void>\n * @throws Error if the underlying connection encounters an error while closing.\n */\n async close(options: BufferedCloseOptions = {}): Promise<void> {\n logger.verbose(\"closing buffered producer client...\");\n if (!isDefined(options.flush) || options.flush === true) {\n await this.flush(options);\n }\n // Calling abort signals to the BatchingPartitionChannels that they\n // should stop reading/sending events, and to the background management\n // loop that it should stop periodic partition id updates.\n this._abortController.abort();\n await this._producer.close();\n this._isClosed = true;\n }\n\n /**\n * Enqueues an event into the buffer to be published to the Event Hub.\n * If there is no capacity in the buffer when this method is invoked,\n * it will wait for space to become available and ensure that the event\n * has been enqueued.\n *\n * When this call returns, the event has been accepted into the buffer,\n * but it may not have been published yet.\n * Publishing will take place at a nondeterministic point in the future as the buffer is processed.\n *\n * @param events - An {@link EventData} or `AmqpAnnotatedMessage`.\n * @param options - A set of options that can be specified to influence the way in which\n * the event is sent to the associated Event Hub.\n * - `abortSignal` : A signal used to cancel the enqueueEvent operation.\n * - `partitionId` : The partition this set of events will be sent to. If set, `partitionKey` can not be set.\n * - `partitionKey` : A value that is hashed to produce a partition assignment. If set, `partitionId` can not be set.\n * @returns The total number of events that are currently buffered and waiting to be published, across all partitions.\n */\n async enqueueEvent(\n event: EventData | AmqpAnnotatedMessage,\n options: EnqueueEventOptions = {},\n ): Promise<number> {\n if (this._isClosed) {\n throw new Error(\n `This EventHubBufferedProducerClient has already been closed. Create a new client to enqueue events.`,\n );\n }\n\n if (!this._partitionIds.length) {\n await this._updatePartitionIds();\n }\n if (!this._isBackgroundManagementRunning) {\n this._startPartitionIdsUpdateLoop().catch((e) => {\n logger.error(\n `The following error occured during batch creation or sending: ${JSON.stringify(\n e,\n undefined,\n \" \",\n )}`,\n );\n });\n this._isBackgroundManagementRunning = true;\n }\n\n const partitionId = this._partitionAssigner.assignPartition({\n partitionId: options.partitionId,\n partitionKey: options.partitionKey,\n });\n\n const partitionChannel = this._getPartitionChannel(partitionId);\n await partitionChannel.enqueueEvent(event);\n return this._getTotalBufferedEventsCount();\n }\n\n /**\n * Enqueues events into the buffer to be published to the Event Hub.\n * If there is no capacity in the buffer when this method is invoked,\n * it will wait for space to become available and ensure that the events\n * have been enqueued.\n *\n * When this call returns, the events have been accepted into the buffer,\n * but it may not have been published yet.\n * Publishing will take place at a nondeterministic point in the future as the buffer is processed.\n *\n * @param events - An array of {@link EventData} or `AmqpAnnotatedMessage`.\n * @param options - A set of options that can be specified to influence the way in which\n * events are sent to the associated Event Hub.\n * - `abortSignal` : A signal used to cancel the enqueueEvents operation.\n * - `partitionId` : The partition this set of events will be sent to. If set, `partitionKey` can not be set.\n * - `partitionKey` : A value that is hashed to produce a partition assignment. If set, `partitionId` can not be set.\n * @returns The total number of events that are currently buffered and waiting to be published, across all partitions.\n */\n async enqueueEvents(\n events: EventData[] | AmqpAnnotatedMessage[],\n // eslint-disable-next-line @azure/azure-sdk/ts-naming-options\n options: EnqueueEventOptions = {},\n ): Promise<number> {\n for (const event of events) {\n await this.enqueueEvent(event, options);\n }\n\n return this._getTotalBufferedEventsCount();\n }\n\n /**\n * Attempts to publish all events in the buffer immediately.\n * This may result in multiple batches being published,\n * the outcome of each of which will be individually reported by\n * the `onSendEventsSuccessHandler` and `onSendEventsErrorHandler` handlers.\n *\n * @param options - The set of options to apply to the operation call.\n */\n async flush(options: BufferedFlushOptions = {}): Promise<void> {\n await Promise.all(\n Array.from(this._partitionChannels.values()).map((channel) => channel.flush(options)),\n );\n }\n\n /**\n * Provides the Event Hub runtime information.\n * @param options - The set of options to apply to the operation call.\n * @returns A promise that resolves with information about the Event Hub instance.\n * @throws Error if the underlying connection has been closed, create a new EventHubBufferedProducerClient.\n * @throws AbortError if the operation is cancelled via the abortSignal.\n */\n getEventHubProperties(options: GetEventHubPropertiesOptions = {}): Promise<EventHubProperties> {\n return this._producer.getEventHubProperties(options);\n }\n\n /**\n * Provides the id for each partition associated with the Event Hub.\n * @param options - The set of options to apply to the operation call.\n * @returns A promise that resolves with an Array of strings representing the id for\n * each partition associated with the Event Hub.\n * @throws Error if the underlying connection has been closed, create a new EventHubBufferedProducerClient.\n * @throws AbortError if the operation is cancelled via the abortSignal.\n */\n getPartitionIds(options: GetPartitionIdsOptions = {}): Promise<Array<string>> {\n return this._producer.getPartitionIds(options);\n }\n\n /**\n * Provides information about the state of the specified partition.\n * @param partitionId - The id of the partition for which information is required.\n * @param options - The set of options to apply to the operation call.\n * @returns A promise that resolves with information about the state of the partition .\n * @throws Error if the underlying connection has been closed, create a new EventHubBufferedProducerClient.\n * @throws AbortError if the operation is cancelled via the abortSignal.\n */\n getPartitionProperties(\n partitionId: string,\n options: GetPartitionPropertiesOptions = {},\n ): Promise<PartitionProperties> {\n return this._producer.getPartitionProperties(partitionId, options);\n }\n\n /**\n * Gets the `BatchingPartitionChannel` associated with the partitionId.\n *\n * If one does not exist, it is created.\n */\n private _getPartitionChannel(partitionId: string): BatchingPartitionChannel {\n const partitionChannel =\n this._partitionChannels.get(partitionId) ??\n new BatchingPartitionChannel({\n loopAbortSignal: this._abortController.signal,\n maxBufferSize: this._clientOptions.maxEventBufferLengthPerPartition || 1500,\n maxWaitTimeInMs: this._clientOptions.maxWaitTimeInMs || 1000,\n onSendEventsErrorHandler: this._clientOptions.onSendEventsErrorHandler,\n onSendEventsSuccessHandler: this._clientOptions.onSendEventsSuccessHandler,\n partitionId,\n producer: this._producer,\n });\n this._partitionChannels.set(partitionId, partitionChannel);\n return partitionChannel;\n }\n\n /**\n * Returns the total number of buffered events across all partitions.\n */\n private _getTotalBufferedEventsCount(): number {\n let total = 0;\n for (const [_, channel] of this._partitionChannels) {\n total += channel.getCurrentBufferedCount();\n }\n\n return total;\n }\n\n private async _updatePartitionIds(): Promise<void> {\n logger.verbose(\"Checking for partition Id updates...\");\n const queriedPartitionIds = await this.getPartitionIds();\n\n if (this._partitionIds.length !== queriedPartitionIds.length) {\n logger.verbose(\"Applying partition Id updates\");\n this._partitionIds = queriedPartitionIds;\n this._partitionAssigner.setPartitionIds(this._partitionIds);\n }\n }\n\n private async _startPartitionIdsUpdateLoop(): Promise<void> {\n logger.verbose(\"Starting a background loop to check and apply partition id updates...\");\n while (!this._abortController.signal.aborted && !this._isClosed) {\n await delay<void>(this._backgroundManagementInterval);\n if (!this._isClosed) {\n await this._updatePartitionIds();\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"eventHubBufferedProducerClient.js","sourceRoot":"","sources":["../../src/eventHubBufferedProducerClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAWrE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AA4FhD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,OAAO,8BAA8B;IACzC;;;OAGG;IACK,gBAAgB,GAAG,IAAI,eAAe,EAAE,CAAC;IAEjD;;OAEG;IACK,SAAS,GAAY,KAAK,CAAC;IAEnC;;OAEG;IACK,kBAAkB,GAAG,IAAI,iBAAiB,EAAE,CAAC;IAErD;;OAEG;IACK,aAAa,GAAa,EAAE,CAAC;IAErC;;OAEG;IACK,SAAS,CAAyB;IAE1C;;;OAGG;IACK,kBAAkB,GAAG,IAAI,GAAG,EAAoC,CAAC;IAEzE;;OAEG;IACK,cAAc,CAAwC;IAE9D;;OAEG;IACK,6BAA6B,GAAG,KAAK,CAAC,CAAC,aAA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,CAAC;QAEzD,IAAI,IAAI,CAAC,aAAa,CAAC,MAAM,KAAK,mBAAmB,CAAC,MAAM,EAAE,CAAC;YAC7D,MAAM,CAAC,OAAO,CAAC,+BAA+B,CAAC,CAAC;YAChD,IAAI,CAAC,aAAa,GAAG,mBAAmB,CAAC;YACzC,IAAI,CAAC,kBAAkB,CAAC,eAAe,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,4BAA4B;QACxC,MAAM,CAAC,OAAO,CAAC,uEAAuE,CAAC,CAAC;QACxF,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YAChE,MAAM,KAAK,CAAO,IAAI,CAAC,6BAA6B,CAAC,CAAC;YACtD,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;gBACpB,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAC;YACnC,CAAC;QACH,CAAC;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { EventData } from \"./eventData.js\";\nimport { EventHubProducerClient } from \"./eventHubProducerClient.js\";\nimport type { OperationOptions } from \"./util/operationOptions.js\";\nimport type {\n EventHubClientOptions,\n GetEventHubPropertiesOptions,\n GetPartitionIdsOptions,\n GetPartitionPropertiesOptions,\n SendBatchOptions,\n} from \"./models/public.js\";\nimport type { EventHubProperties, PartitionProperties } from \"./managementClient.js\";\nimport type { NamedKeyCredential, SASCredential, TokenCredential } from \"@azure/core-auth\";\nimport { isDefined } from \"@azure/core-util\";\nimport { isCredential } from \"./util/typeGuards.js\";\nimport type { AmqpAnnotatedMessage } from \"@azure/core-amqp\";\nimport { delay } from \"@azure/core-amqp\";\nimport { BatchingPartitionChannel } from \"./batchingPartitionChannel.js\";\nimport { PartitionAssigner } from \"./impl/partitionAssigner.js\";\nimport { logger } from \"./logger.js\";\nimport { getRandomName } from \"./util/utils.js\";\n\n/**\n * Contains the events that were successfully sent to the Event Hub,\n * and the partition they were assigned to.\n */\nexport interface OnSendEventsSuccessContext {\n /**\n * The partition each event was assigned.\n */\n partitionId: string;\n /**\n * The array of {@link EventData} and/or `AmqpAnnotatedMessage` that were successfully sent to the Event Hub.\n */\n events: Array<EventData | AmqpAnnotatedMessage>;\n}\n\n/**\n * Contains the events that were not successfully sent to the Event Hub,\n * the partition they were assigned to, and the error that was encountered while sending.\n */\nexport interface OnSendEventsErrorContext {\n /**\n * The partition each event was assigned.\n */\n partitionId: string;\n /**\n * The array of {@link EventData} and/or `AmqpAnnotatedMessage` that were not successfully sent to the Event Hub.\n */\n events: Array<EventData | AmqpAnnotatedMessage>;\n /**\n * The error that occurred when sending the associated events to the Event Hub.\n */\n error: Error;\n}\n\n/**\n * Describes the options that can be provided while creating the `EventHubBufferedProducerClient`.\n */\nexport interface EventHubBufferedProducerClientOptions extends EventHubClientOptions {\n /**\n * The total number of events that can be buffered for publishing at a given time for a given partition.\n *\n * Default: 1500\n */\n maxEventBufferLengthPerPartition?: number;\n /**\n * The amount of time to wait for a new event to be enqueued in the buffer before publishing a partially full batch.\n *\n * Default: 1 second.\n */\n maxWaitTimeInMs?: number;\n /**\n * The handler to call once a batch has successfully published.\n */\n onSendEventsSuccessHandler?: (ctx: OnSendEventsSuccessContext) => void;\n /**\n * The handler to call when a batch fails to publish.\n */\n onSendEventsErrorHandler: (ctx: OnSendEventsErrorContext) => void;\n /**\n * Indicates whether or not the EventHubProducerClient should enable idempotent publishing to Event Hub partitions.\n * If enabled, the producer will only be able to publish directly to partitions;\n * it will not be able to publish to the Event Hubs gateway for automatic partition routing\n * nor will it be able to use a partition key.\n * Default: false\n */\n enableIdempotentRetries?: boolean;\n}\n\n/**\n * Options to configure the `flush` method on the `EventHubBufferedProducerClient`.\n */\nexport interface BufferedFlushOptions extends OperationOptions {}\n\n/**\n * Options to configure the `close` method on the `EventHubBufferedProducerClient`.\n */\nexport interface BufferedCloseOptions extends OperationOptions {\n /**\n * When `true`, all buffered events that are pending should be sent before closing.\n * When `false`, abandon all buffered events and close immediately.\n * Defaults to `true`.\n */\n flush?: boolean;\n}\n\n/**\n * Options to configure the `enqueueEvents` method on the `EventHubBufferedProducerClient`.\n */\nexport interface EnqueueEventOptions extends SendBatchOptions {}\n\n/**\n * The `EventHubBufferedProducerClient`is used to publish events to a specific Event Hub.\n *\n * The `EventHubBufferedProducerClient` does not publish events immediately.\n * Instead, events are buffered so they can be efficiently batched and published\n * when the batch is full or the `maxWaitTimeInMs` has elapsed with no new events\n * enqueued.\n *\n * Depending on the options specified when events are enqueued, they may be\n * automatically assigned to a partition, grouped according to the specified partition key,\n * or assigned a specifically requested partition.\n *\n * This model is intended to shift the burden of batch management from callers, at the cost of\n * non-deterministic timing, for when events will be published. There are additional trade-offs\n * to consider, as well:\n * - If the application crashes, events in the buffer will not have been published. To prevent\n * data loss, callers are encouraged to track publishing progress using the\n * `onSendEventsSuccessHandler` and `onSendEventsErrorHandler` handlers.\n * - Events specifying a partition key may be assigned a different partition than those using\n * the same key with other producers.\n * - In the unlikely event that a partition becomes temporarily unavailable, the\n * `EventHubBufferedProducerClient` may take longer to recover than other producers.\n *\n * In scenarios where it is important to have events published immediately with a deterministic\n * outcome, ensure that partition keys are assigned to a partition consistent with other\n * publishers, or where maximizing availability is a requirement, using the\n * `EventHubProducerClient` is recommended.\n */\nexport class EventHubBufferedProducerClient {\n /**\n * Controls the `abortSignal` passed to each `BatchingPartitionChannel`.\n * Used to signal when a channel should stop waiting for events.\n */\n private _abortController = new AbortController();\n\n /**\n * Indicates whether the client has been explicitly closed.\n */\n private _isClosed: boolean = false;\n\n /**\n * Handles assigning partitions.\n */\n private _partitionAssigner = new PartitionAssigner();\n\n /**\n * The known partitionIds that will be used when assigning events to partitions.\n */\n private _partitionIds: string[] = [];\n\n /**\n * The EventHubProducerClient to use when creating and sending batches to the Event Hub.\n */\n private _producer: EventHubProducerClient;\n\n /**\n * Mapping of partitionIds to `BatchingPartitionChannels`.\n * Each `BatchingPartitionChannel` handles buffering events and backpressure independently.\n */\n private _partitionChannels = new Map<string, BatchingPartitionChannel>();\n\n /**\n * The options passed by the user when creating the EventHubBufferedProducerClient instance.\n */\n private _clientOptions: EventHubBufferedProducerClientOptions;\n\n /**\n * The interval at which the background management operation should run.\n */\n private _backgroundManagementInterval = 10000; // 10 seconds\n\n /**\n * Indicates whether the background management loop is running.\n */\n private _isBackgroundManagementRunning = false;\n\n /**\n * @readonly\n * The name of the Event Hub instance for which this client is created.\n */\n get eventHubName(): string {\n return this._producer.eventHubName;\n }\n\n /**\n * @readonly\n * The fully qualified namespace of the Event Hub instance for which this client is created.\n * This is likely to be similar to <yournamespace>.servicebus.windows.net.\n */\n get fullyQualifiedNamespace(): string {\n return this._producer.fullyQualifiedNamespace;\n }\n\n /**\n * The name used to identify this EventHubBufferedProducerClient.\n * If not specified or empty, a random unique one will be generated.\n */\n public readonly identifier: string;\n\n /**\n * The `EventHubBufferedProducerClient` class is used to send events to an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param connectionString - The connection string to use for connecting to the Event Hub instance.\n * It is expected that the shared key properties and the Event Hub path are contained in this connection string.\n * e.g. 'Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key;EntityPath=my-event-hub-name'.\n * @param options - A set of options to apply when configuring the client.\n * - `retryOptions` : Configures the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n * - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.\n * - `userAgent` : A string to append to the built in user agent string that is passed to the service.\n */\n constructor(connectionString: string, options: EventHubBufferedProducerClientOptions);\n /**\n * The `EventHubBufferedProducerClient` class is used to send events to an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param connectionString - The connection string to use for connecting to the Event Hubs namespace.\n * It is expected that the shared key properties are contained in this connection string, but not the Event Hub path,\n * e.g. 'Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key;'.\n * @param eventHubName - The name of the specific Event Hub to connect the client to.\n * @param options - A set of options to apply when configuring the client.\n * - `retryOptions` : Configures the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n * - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.\n * - `userAgent` : A string to append to the built in user agent string that is passed to the service.\n */\n constructor(\n connectionString: string,\n eventHubName: string,\n options: EventHubBufferedProducerClientOptions,\n );\n /**\n * The `EventHubBufferedProducerClient` class is used to send events to an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param fullyQualifiedNamespace - The full namespace which is likely to be similar to\n * <yournamespace>.servicebus.windows.net\n * @param eventHubName - The name of the specific Event Hub to connect the client to.\n * @param credential - An credential object used by the client to get the token to authenticate the connection\n * with the Azure Event Hubs service.\n * See &commat;azure/identity for creating credentials that support AAD auth.\n * Use the `AzureNamedKeyCredential` from &commat;azure/core-auth if you want to pass in a `SharedAccessKeyName`\n * and `SharedAccessKey` without using a connection string. These fields map to the `name` and `key` field respectively\n * in `AzureNamedKeyCredential`.\n * Use the `AzureSASCredential` from &commat;azure/core-auth if you want to pass in a `SharedAccessSignature`\n * without using a connection string. This field maps to `signature` in `AzureSASCredential`.\n * @param options - A set of options to apply when configuring the client.\n * - `retryOptions` : Configures the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n * - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.\n * - `userAgent` : A string to append to the built in user agent string that is passed to the service.\n */\n constructor(\n fullyQualifiedNamespace: string,\n eventHubName: string,\n credential: TokenCredential | NamedKeyCredential | SASCredential,\n options: EventHubBufferedProducerClientOptions,\n );\n constructor(\n fullyQualifiedNamespaceOrConnectionString1: string,\n eventHubNameOrOptions2: string | EventHubBufferedProducerClientOptions,\n credentialOrOptions3?:\n | TokenCredential\n | NamedKeyCredential\n | SASCredential\n | EventHubBufferedProducerClientOptions,\n options4?: EventHubBufferedProducerClientOptions,\n ) {\n if (typeof eventHubNameOrOptions2 !== \"string\") {\n this.identifier = eventHubNameOrOptions2.identifier ?? getRandomName();\n this._producer = new EventHubProducerClient(fullyQualifiedNamespaceOrConnectionString1, {\n ...eventHubNameOrOptions2,\n identifier: this.identifier,\n });\n this._clientOptions = { ...eventHubNameOrOptions2 };\n } else if (!isCredential(credentialOrOptions3)) {\n this.identifier = credentialOrOptions3?.identifier ?? getRandomName();\n this._producer = new EventHubProducerClient(\n fullyQualifiedNamespaceOrConnectionString1,\n eventHubNameOrOptions2,\n { ...credentialOrOptions3, identifier: this.identifier },\n );\n this._clientOptions = { ...credentialOrOptions3! };\n } else {\n this.identifier = options4?.identifier ?? getRandomName();\n this._producer = new EventHubProducerClient(\n fullyQualifiedNamespaceOrConnectionString1,\n eventHubNameOrOptions2,\n credentialOrOptions3,\n { ...options4, identifier: this.identifier },\n );\n this._clientOptions = { ...options4! };\n }\n // setting internal idempotent publishing option on the standard producer.\n (this._producer as any)._enableIdempotentRetries = this._clientOptions.enableIdempotentRetries;\n }\n\n /**\n * Closes the AMQP connection to the Event Hub instance,\n * returning a promise that will be resolved when disconnection is completed.\n *\n * This will wait for enqueued events to be flushed to the service before closing\n * the connection.\n * To close without flushing, set the `flush` option to `false`.\n *\n * @param options - The set of options to apply to the operation call.\n * @returns Promise<void>\n * @throws Error if the underlying connection encounters an error while closing.\n */\n async close(options: BufferedCloseOptions = {}): Promise<void> {\n logger.verbose(\"closing buffered producer client...\");\n if (!isDefined(options.flush) || options.flush === true) {\n await this.flush(options);\n }\n // Calling abort signals to the BatchingPartitionChannels that they\n // should stop reading/sending events, and to the background management\n // loop that it should stop periodic partition id updates.\n this._abortController.abort();\n await this._producer.close();\n this._isClosed = true;\n }\n\n /**\n * Enqueues an event into the buffer to be published to the Event Hub.\n * If there is no capacity in the buffer when this method is invoked,\n * it will wait for space to become available and ensure that the event\n * has been enqueued.\n *\n * When this call returns, the event has been accepted into the buffer,\n * but it may not have been published yet.\n * Publishing will take place at a nondeterministic point in the future as the buffer is processed.\n *\n * @param events - An {@link EventData} or `AmqpAnnotatedMessage`.\n * @param options - A set of options that can be specified to influence the way in which\n * the event is sent to the associated Event Hub.\n * - `abortSignal` : A signal used to cancel the enqueueEvent operation.\n * - `partitionId` : The partition this set of events will be sent to. If set, `partitionKey` can not be set.\n * - `partitionKey` : A value that is hashed to produce a partition assignment. If set, `partitionId` can not be set.\n * @returns The total number of events that are currently buffered and waiting to be published, across all partitions.\n */\n async enqueueEvent(\n event: EventData | AmqpAnnotatedMessage,\n options: EnqueueEventOptions = {},\n ): Promise<number> {\n if (this._isClosed) {\n throw new Error(\n `This EventHubBufferedProducerClient has already been closed. Create a new client to enqueue events.`,\n );\n }\n\n if (!this._partitionIds.length) {\n await this._updatePartitionIds();\n }\n if (!this._isBackgroundManagementRunning) {\n // Fire-and-forget background loop with error handling\n this._startPartitionIdsUpdateLoop().catch((e) => {\n logger.error(\n `The following error occurred during partition ID update loop: ${JSON.stringify(\n e,\n undefined,\n \" \",\n )}`,\n );\n });\n this._isBackgroundManagementRunning = true;\n }\n\n const partitionId = this._partitionAssigner.assignPartition({\n partitionId: options.partitionId,\n partitionKey: options.partitionKey,\n });\n\n const partitionChannel = this._getPartitionChannel(partitionId);\n await partitionChannel.enqueueEvent(event);\n return this._getTotalBufferedEventsCount();\n }\n\n /**\n * Enqueues events into the buffer to be published to the Event Hub.\n * If there is no capacity in the buffer when this method is invoked,\n * it will wait for space to become available and ensure that the events\n * have been enqueued.\n *\n * When this call returns, the events have been accepted into the buffer,\n * but it may not have been published yet.\n * Publishing will take place at a nondeterministic point in the future as the buffer is processed.\n *\n * @param events - An array of {@link EventData} or `AmqpAnnotatedMessage`.\n * @param options - A set of options that can be specified to influence the way in which\n * events are sent to the associated Event Hub.\n * - `abortSignal` : A signal used to cancel the enqueueEvents operation.\n * - `partitionId` : The partition this set of events will be sent to. If set, `partitionKey` can not be set.\n * - `partitionKey` : A value that is hashed to produce a partition assignment. If set, `partitionId` can not be set.\n * @returns The total number of events that are currently buffered and waiting to be published, across all partitions.\n */\n async enqueueEvents(\n events: EventData[] | AmqpAnnotatedMessage[],\n // eslint-disable-next-line @azure/azure-sdk/ts-naming-options\n options: EnqueueEventOptions = {},\n ): Promise<number> {\n for (const event of events) {\n await this.enqueueEvent(event, options);\n }\n\n return this._getTotalBufferedEventsCount();\n }\n\n /**\n * Attempts to publish all events in the buffer immediately.\n * This may result in multiple batches being published,\n * the outcome of each of which will be individually reported by\n * the `onSendEventsSuccessHandler` and `onSendEventsErrorHandler` handlers.\n *\n * @param options - The set of options to apply to the operation call.\n */\n async flush(options: BufferedFlushOptions = {}): Promise<void> {\n await Promise.all(\n Array.from(this._partitionChannels.values()).map((channel) => channel.flush(options)),\n );\n }\n\n /**\n * Provides the Event Hub runtime information.\n * @param options - The set of options to apply to the operation call.\n * @returns A promise that resolves with information about the Event Hub instance.\n * @throws Error if the underlying connection has been closed, create a new EventHubBufferedProducerClient.\n * @throws AbortError if the operation is cancelled via the abortSignal.\n */\n getEventHubProperties(options: GetEventHubPropertiesOptions = {}): Promise<EventHubProperties> {\n return this._producer.getEventHubProperties(options);\n }\n\n /**\n * Provides the id for each partition associated with the Event Hub.\n * @param options - The set of options to apply to the operation call.\n * @returns A promise that resolves with an Array of strings representing the id for\n * each partition associated with the Event Hub.\n * @throws Error if the underlying connection has been closed, create a new EventHubBufferedProducerClient.\n * @throws AbortError if the operation is cancelled via the abortSignal.\n */\n getPartitionIds(options: GetPartitionIdsOptions = {}): Promise<Array<string>> {\n return this._producer.getPartitionIds(options);\n }\n\n /**\n * Provides information about the state of the specified partition.\n * @param partitionId - The id of the partition for which information is required.\n * @param options - The set of options to apply to the operation call.\n * @returns A promise that resolves with information about the state of the partition .\n * @throws Error if the underlying connection has been closed, create a new EventHubBufferedProducerClient.\n * @throws AbortError if the operation is cancelled via the abortSignal.\n */\n getPartitionProperties(\n partitionId: string,\n options: GetPartitionPropertiesOptions = {},\n ): Promise<PartitionProperties> {\n return this._producer.getPartitionProperties(partitionId, options);\n }\n\n /**\n * Gets the `BatchingPartitionChannel` associated with the partitionId.\n *\n * If one does not exist, it is created.\n */\n private _getPartitionChannel(partitionId: string): BatchingPartitionChannel {\n const partitionChannel =\n this._partitionChannels.get(partitionId) ??\n new BatchingPartitionChannel({\n loopAbortSignal: this._abortController.signal,\n maxBufferSize: this._clientOptions.maxEventBufferLengthPerPartition || 1500,\n maxWaitTimeInMs: this._clientOptions.maxWaitTimeInMs || 1000,\n onSendEventsErrorHandler: this._clientOptions.onSendEventsErrorHandler,\n onSendEventsSuccessHandler: this._clientOptions.onSendEventsSuccessHandler,\n partitionId,\n producer: this._producer,\n });\n this._partitionChannels.set(partitionId, partitionChannel);\n return partitionChannel;\n }\n\n /**\n * Returns the total number of buffered events across all partitions.\n */\n private _getTotalBufferedEventsCount(): number {\n let total = 0;\n for (const [_, channel] of this._partitionChannels) {\n total += channel.getCurrentBufferedCount();\n }\n\n return total;\n }\n\n private async _updatePartitionIds(): Promise<void> {\n logger.verbose(\"Checking for partition Id updates...\");\n const queriedPartitionIds = await this.getPartitionIds();\n\n if (this._partitionIds.length !== queriedPartitionIds.length) {\n logger.verbose(\"Applying partition Id updates\");\n this._partitionIds = queriedPartitionIds;\n this._partitionAssigner.setPartitionIds(this._partitionIds);\n }\n }\n\n private async _startPartitionIdsUpdateLoop(): Promise<void> {\n logger.verbose(\"Starting a background loop to check and apply partition id updates...\");\n while (!this._abortController.signal.aborted && !this._isClosed) {\n await delay<void>(this._backgroundManagementInterval);\n if (!this._isClosed) {\n await this._updatePartitionIds();\n }\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"eventHubConsumerClient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AAe,EAAE,eAAe,EAChC,OAAO,CAAC,EAAE,6BAA6B;IA8FzC;;;;;OAKG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAY5B;;;;;;;OAOG;IACG,eAAe,CAAC,OAAO,GAAE,sBAA2B,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAQnF;;;;;;;OAOG;IACH,sBAAsB,CACpB,WAAW,EAAE,MAAM,EACnB,OAAO,GAAE,6BAAkC,GAC1C,OAAO,CAAC,mBAAmB,CAAC;IAO/B;;;;;;OAMG;IACH,qBAAqB,CAAC,OAAO,GAAE,4BAAiC,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAO9F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmCG;IACH,SAAS,CAAC,QAAQ,EAAE,yBAAyB,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,YAAY;IACxF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IAEH,SAAS,CACP,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,yBAAyB,EACnC,OAAO,CAAC,EAAE,gBAAgB,GACzB,YAAY;IAoDf;;OAEG;IACH,OAAO,CAAC,yBAAyB;IAkBjC,OAAO,CAAC,oCAAoC;IAmC5C,OAAO,CAAC,sCAAsC;IAqC9C,OAAO,CAAC,qBAAqB;CAc9B;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,eAAe,GAAG,GAAG,GAAG,QAAQ,IAAI,eAAe,CAa9F"}
@@ -167,15 +167,12 @@ export class EventHubConsumerClient {
167
167
  * @throws Error if the underlying connection has been closed, create a new EventHubConsumerClient.
168
168
  * @throws AbortError if the operation is cancelled via the abortSignal.
169
169
  */
170
- getPartitionIds(options = {}) {
171
- return this._context
172
- .managementSession.getEventHubProperties({
170
+ async getPartitionIds(options = {}) {
171
+ const eventHubProperties = await this._context.managementSession.getEventHubProperties({
173
172
  ...options,
174
173
  retryOptions: this._clientOptions.retryOptions,
175
- })
176
- .then((eventHubProperties) => {
177
- return eventHubProperties.partitionIds;
178
174
  });
175
+ return eventHubProperties.partitionIds;
179
176
  }
180
177
  /**
181
178
  * Provides information about the state of the specified partition.