@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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eventHubProducerClient.d.ts","sourceRoot":"","sources":["../../src/eventHubProducerClient.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACrB,4BAA4B,EAC5B,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,EAChE,OAAO,CAAC,EAAE,qBAAqB;IA6BjC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmDG;IACG,WAAW,CAAC,OAAO,GAAE,kBAAuB,GAAG,OAAO,CAAC,cAAc,CAAC;IAiD5E;;;;;;;;;;OAUG;YAGW,gCAAgC;IA2B9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqCG;IACG,SAAS,CACb,KAAK,EAAE,SAAS,EAAE,GAAG,oBAAoB,EAAE,EAC3C,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,IAAI,CAAC;IAChB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgDG;IACG,SAAS,CAAC,KAAK,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IA8FjF;;;;;OAKG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAS5B;;;;;;OAMG;IACH,qBAAqB,CAAC,OAAO,GAAE,4BAAiC,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAO9F;;;;;;;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;CAMhC"}
@@ -0,0 +1,366 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import { createConnectionContext } from "./connectionContext.js";
4
+ import { EventDataBatchImpl, isEventDataBatch } from "./eventDataBatch.js";
5
+ import { isDefined } from "@azure/core-util";
6
+ import { isCredential } from "./util/typeGuards.js";
7
+ import { logErrorStackTrace, logger } from "./logger.js";
8
+ import { idempotentAlreadyPublished, idempotentSomeAlreadyPublished, throwErrorIfConnectionClosed, throwTypeErrorIfParameterMissing, validateProducerPartitionSettings, } from "./util/error.js";
9
+ import { assertIsEventData } from "./eventData.js";
10
+ import { EventHubSender } from "./eventHubSender.js";
11
+ import { toSpanOptions, tracingClient } from "./diagnostics/tracing.js";
12
+ import { instrumentEventData } from "./diagnostics/instrumentEventData.js";
13
+ import { getRandomName } from "./util/utils.js";
14
+ /**
15
+ * The `EventHubProducerClient` class is used to send events to an Event Hub.
16
+ *
17
+ * There are multiple ways to create an `EventHubProducerClient`
18
+ * - Use the connection string from the SAS policy created for your Event Hub instance.
19
+ * - Use the connection string from the SAS policy created for your Event Hub namespace,
20
+ * and the name of the Event Hub instance
21
+ * - Use the full namespace like `<yournamespace>.servicebus.windows.net`, and a credentials object.
22
+ *
23
+ * Optionally, you can also pass an options bag to configure the retry policy or proxy settings.
24
+ *
25
+ */
26
+ export class EventHubProducerClient {
27
+ /**
28
+ * Describes the amqp connection context for the client.
29
+ */
30
+ _context;
31
+ /**
32
+ * The options passed by the user when creating the EventHubClient instance.
33
+ */
34
+ _clientOptions;
35
+ /**
36
+ * Map of partitionId to senders
37
+ */
38
+ _sendersMap;
39
+ /**
40
+ * Indicates whether or not the EventHubProducerClient should enable idempotent publishing to Event Hub partitions.
41
+ * If enabled, the producer will only be able to publish directly to partitions;
42
+ * it will not be able to publish to the Event Hubs gateway for automatic partition routing
43
+ * nor will it be able to use a partition key.
44
+ * Default: false
45
+ */
46
+ _enableIdempotentRetries;
47
+ /**
48
+ * The set of options that can be specified to influence publishing behavior specific to the configured Event Hub partition.
49
+ * These options are not necessary in the majority of scenarios and are intended for use with specialized scenarios,
50
+ * such as when recovering the state used for idempotent publishing.
51
+ */
52
+ _partitionOptions;
53
+ /**
54
+ * @readonly
55
+ * The name of the Event Hub instance for which this client is created.
56
+ */
57
+ get eventHubName() {
58
+ return this._context.config.entityPath;
59
+ }
60
+ /**
61
+ * @readonly
62
+ * The fully qualified namespace of the Event Hub instance for which this client is created.
63
+ * This is likely to be similar to <yournamespace>.servicebus.windows.net.
64
+ */
65
+ get fullyQualifiedNamespace() {
66
+ return this._context.config.host;
67
+ }
68
+ /**
69
+ * The name used to identify this EventHubProducerClient.
70
+ * If not specified or empty, a random unique one will be generated.
71
+ */
72
+ identifier;
73
+ constructor(fullyQualifiedNamespaceOrConnectionString1, eventHubNameOrOptions2, credentialOrOptions3, options4) {
74
+ this._context = createConnectionContext(fullyQualifiedNamespaceOrConnectionString1, eventHubNameOrOptions2, credentialOrOptions3, options4);
75
+ if (typeof eventHubNameOrOptions2 !== "string") {
76
+ this._clientOptions = eventHubNameOrOptions2 || {};
77
+ }
78
+ else if (!isCredential(credentialOrOptions3)) {
79
+ this._clientOptions = credentialOrOptions3 || {};
80
+ }
81
+ else {
82
+ this._clientOptions = options4 || {};
83
+ }
84
+ this.identifier = this._clientOptions.identifier ?? getRandomName();
85
+ this._sendersMap = new Map();
86
+ }
87
+ /**
88
+ * Creates an instance of `EventDataBatch` to which one can add events until the maximum supported size is reached.
89
+ * The batch can be passed to the {@link sendBatch} method of the `EventHubProducerClient` to be sent to Azure Event Hubs.
90
+ *
91
+ * Events with different values for partitionKey or partitionId will need to be put into different batches.
92
+ * To simplify such batch management across partitions or to have the client automatically batch events
93
+ * and send them in specific intervals, use `EventHubBufferedProducerClient` instead.
94
+ *
95
+ * The below example assumes you have an array of events at hand to be batched safely.
96
+ * If you have events coming in one by one, `EventHubBufferedProducerClient` is recommended instead
97
+ * for effecient management of batches.
98
+ *
99
+ * Example usage:
100
+ * ```ts snippet:EventHubProducerClient_CreateBatch
101
+ * import { EventHubProducerClient } from "@azure/event-hubs";
102
+ *
103
+ * const client = new EventHubProducerClient("my-connection-string", "my-event-hub");
104
+ *
105
+ * const messages = [
106
+ * { body: "my-event-body1" },
107
+ * { body: "my-event-body2" },
108
+ * { body: "my-event-body3" },
109
+ * { body: "my-event-body4" },
110
+ * { body: "my-event-body5" },
111
+ * ];
112
+ *
113
+ * let batch = await client.createBatch();
114
+ * for (let i = 0; i < messages.length; i++) {
115
+ * if (!batch.tryAdd(messages[i])) {
116
+ * await client.sendBatch(batch);
117
+ * batch = await client.createBatch();
118
+ * if (!batch.tryAdd(messages[i])) {
119
+ * throw new Error("Message too big to fit");
120
+ * }
121
+ * if (i === messages.length - 1) {
122
+ * await client.sendBatch(batch);
123
+ * }
124
+ * }
125
+ * }
126
+ * ```
127
+ *
128
+ * @param options - Configures the behavior of the batch.
129
+ * - `partitionKey` : A value that is hashed and used by the Azure Event Hubs service to determine the partition to which
130
+ * the events need to be sent.
131
+ * - `partitionId` : Id of the partition to which the batch of events need to be sent.
132
+ * - `maxSizeInBytes`: The upper limit for the size of batch. The `tryAdd` function will return `false` after this limit is reached.
133
+ * - `abortSignal` : A signal the request to cancel the operation.
134
+ * @returns Promise<EventDataBatch>
135
+ * @throws Error if both `partitionId` and `partitionKey` are set in the options.
136
+ * @throws Error if the underlying connection has been closed, create a new EventHubProducerClient.
137
+ * @throws AbortError if the operation is cancelled via the abortSignal in the options.
138
+ */
139
+ async createBatch(options = {}) {
140
+ throwErrorIfConnectionClosed(this._context);
141
+ const partitionId = isDefined(options.partitionId) ? String(options.partitionId) : undefined;
142
+ validateProducerPartitionSettings({
143
+ enableIdempotentRetries: this._enableIdempotentRetries,
144
+ partitionId,
145
+ partitionKey: options.partitionKey,
146
+ });
147
+ let sender = this._sendersMap.get(partitionId || "");
148
+ if (!sender) {
149
+ const partitionPublishingOptions = isDefined(partitionId)
150
+ ? this._partitionOptions?.[partitionId]
151
+ : undefined;
152
+ sender = EventHubSender.create(this._context, this.identifier, {
153
+ enableIdempotentProducer: Boolean(this._enableIdempotentRetries),
154
+ partitionId,
155
+ partitionPublishingOptions,
156
+ });
157
+ this._sendersMap.set(partitionId || "", sender);
158
+ }
159
+ let maxMessageSize = await sender.getMaxMessageSize({
160
+ retryOptions: this._clientOptions.retryOptions,
161
+ abortSignal: options.abortSignal,
162
+ });
163
+ if (options.maxSizeInBytes) {
164
+ if (options.maxSizeInBytes > maxMessageSize) {
165
+ const error = new Error(`Max message size (${options.maxSizeInBytes} bytes) is greater than maximum message size (${maxMessageSize} bytes) on the AMQP sender link.`);
166
+ logger.warning(`[${this._context.connectionId}] ${error.message}`);
167
+ logErrorStackTrace(error);
168
+ throw error;
169
+ }
170
+ maxMessageSize = options.maxSizeInBytes;
171
+ }
172
+ return new EventDataBatchImpl(this._context, maxMessageSize, Boolean(this._enableIdempotentRetries), options.partitionKey, partitionId);
173
+ }
174
+ /**
175
+ * Get the information about the state of publishing for a partition as observed by the `EventHubProducerClient`.
176
+ * This data can always be read, but will only be populated with information relevant to the active features
177
+ * for the producer client.
178
+ *
179
+ * @param partitionId - Id of the partition from which to retrieve publishing properties.
180
+ * @param options - The set of options to apply to the operation call.
181
+ * - `abortSignal` : A signal the request to cancel the send operation.
182
+ * @returns Promise<void>
183
+ * @throws AbortError if the operation is cancelled via the abortSignal.
184
+ */
185
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
186
+ // @ts-ignore this is called in EventHubBufferedProducerClient via cast-to-any workaround
187
+ async getPartitionPublishingProperties(partitionId, options = {}) {
188
+ if (!isDefined(partitionId)) {
189
+ throw new TypeError(`getPartitionPublishingProperties called without required argument "partitionId"`);
190
+ }
191
+ if (typeof partitionId === "number") {
192
+ partitionId = String(partitionId);
193
+ }
194
+ let sender = this._sendersMap.get(partitionId);
195
+ if (!sender) {
196
+ sender = EventHubSender.create(this._context, this.identifier, {
197
+ enableIdempotentProducer: Boolean(this._enableIdempotentRetries),
198
+ partitionId,
199
+ partitionPublishingOptions: this._partitionOptions?.[partitionId],
200
+ });
201
+ this._sendersMap.set(partitionId, sender);
202
+ }
203
+ return sender.getPartitionPublishingProperties(options);
204
+ }
205
+ async sendBatch(batch, options = {}) {
206
+ throwErrorIfConnectionClosed(this._context);
207
+ throwTypeErrorIfParameterMissing(this._context.connectionId, "sendBatch", "batch", batch);
208
+ let partitionId;
209
+ let partitionKey;
210
+ // Holds an EventData properties object containing tracing properties.
211
+ // This lets us avoid cloning batch when it is EventData[], which is
212
+ // important as the idempotent EventHubSender needs to decorate the
213
+ // original EventData passed through.
214
+ const eventDataTracingProperties = [];
215
+ // link message span contexts
216
+ let spanContextsToLink = [];
217
+ if (isEventDataBatch(batch)) {
218
+ if (this._enableIdempotentRetries &&
219
+ isDefined(batch.startingPublishedSequenceNumber)) {
220
+ throw new Error(idempotentAlreadyPublished);
221
+ }
222
+ const partitionAssignment = extractPartitionAssignmentFromBatch(batch, options);
223
+ partitionId = partitionAssignment.partitionId;
224
+ partitionKey = partitionAssignment.partitionKey;
225
+ spanContextsToLink = batch._messageSpanContexts;
226
+ }
227
+ else {
228
+ if (!Array.isArray(batch)) {
229
+ batch = [batch];
230
+ }
231
+ batch.forEach(assertIsEventData);
232
+ if (batch.some((event) => isDefined(event._publishedSequenceNumber))) {
233
+ throw new Error(idempotentSomeAlreadyPublished);
234
+ }
235
+ const partitionAssignment = extractPartitionAssignmentFromOptions(options);
236
+ partitionId = partitionAssignment.partitionId;
237
+ partitionKey = partitionAssignment.partitionKey;
238
+ for (let i = 0; i < batch.length; i++) {
239
+ batch[i] = instrumentEventData(batch[i], options, this._context.config.entityPath, this._context.config.host, "publish").event;
240
+ eventDataTracingProperties[i] = batch[i].properties;
241
+ }
242
+ }
243
+ validateProducerPartitionSettings({
244
+ enableIdempotentRetries: this._enableIdempotentRetries,
245
+ partitionId,
246
+ partitionKey,
247
+ });
248
+ return tracingClient.withSpan(`${EventHubProducerClient.name}.${this.sendBatch.name}`, options, (updatedOptions) => {
249
+ let sender = this._sendersMap.get(partitionId || "");
250
+ if (!sender) {
251
+ const partitionPublishingOptions = isDefined(partitionId)
252
+ ? this._partitionOptions?.[partitionId]
253
+ : undefined;
254
+ sender = EventHubSender.create(this._context, this.identifier, {
255
+ enableIdempotentProducer: Boolean(this._enableIdempotentRetries),
256
+ partitionId,
257
+ partitionPublishingOptions,
258
+ });
259
+ this._sendersMap.set(partitionId || "", sender);
260
+ }
261
+ return sender.send(batch, {
262
+ ...updatedOptions,
263
+ partitionId,
264
+ partitionKey,
265
+ retryOptions: this._clientOptions.retryOptions,
266
+ });
267
+ }, {
268
+ spanLinks: spanContextsToLink.map((tracingContext) => {
269
+ return { tracingContext };
270
+ }),
271
+ ...toSpanOptions(this._context.config, "publish", "client"),
272
+ });
273
+ }
274
+ /**
275
+ * Closes the AMQP connection to the Event Hub instance,
276
+ * returning a promise that will be resolved when disconnection is completed.
277
+ * @returns Promise<void>
278
+ * @throws Error if the underlying connection encounters an error while closing.
279
+ */
280
+ async close() {
281
+ await this._context.close();
282
+ for (const pair of this._sendersMap) {
283
+ await pair[1].close();
284
+ }
285
+ this._sendersMap.clear();
286
+ }
287
+ /**
288
+ * Provides the Event Hub runtime information.
289
+ * @param options - The set of options to apply to the operation call.
290
+ * @returns A promise that resolves with information about the Event Hub instance.
291
+ * @throws Error if the underlying connection has been closed, create a new EventHubProducerClient.
292
+ * @throws AbortError if the operation is cancelled via the abortSignal.
293
+ */
294
+ getEventHubProperties(options = {}) {
295
+ return this._context.managementSession.getEventHubProperties({
296
+ ...options,
297
+ retryOptions: this._clientOptions.retryOptions,
298
+ });
299
+ }
300
+ /**
301
+ * Provides the id for each partition associated with the Event Hub.
302
+ * @param options - The set of options to apply to the operation call.
303
+ * @returns A promise that resolves with an Array of strings representing the id for
304
+ * each partition associated with the Event Hub.
305
+ * @throws Error if the underlying connection has been closed, create a new EventHubProducerClient.
306
+ * @throws AbortError if the operation is cancelled via the abortSignal.
307
+ */
308
+ async getPartitionIds(options = {}) {
309
+ const eventHubProperties = await this._context.managementSession.getEventHubProperties({
310
+ ...options,
311
+ retryOptions: this._clientOptions.retryOptions,
312
+ });
313
+ return eventHubProperties.partitionIds;
314
+ }
315
+ /**
316
+ * Provides information about the state of the specified partition.
317
+ * @param partitionId - The id of the partition for which information is required.
318
+ * @param options - The set of options to apply to the operation call.
319
+ * @returns A promise that resolves with information about the state of the partition .
320
+ * @throws Error if the underlying connection has been closed, create a new EventHubProducerClient.
321
+ * @throws AbortError if the operation is cancelled via the abortSignal.
322
+ */
323
+ getPartitionProperties(partitionId, options = {}) {
324
+ return this._context.managementSession.getPartitionProperties(partitionId, {
325
+ ...options,
326
+ retryOptions: this._clientOptions.retryOptions,
327
+ });
328
+ }
329
+ }
330
+ /**
331
+ * @internal
332
+ */
333
+ function extractPartitionAssignmentFromOptions(options = {}) {
334
+ const result = {};
335
+ const { partitionId, partitionKey } = options;
336
+ if (isDefined(partitionId)) {
337
+ result.partitionId = String(partitionId);
338
+ }
339
+ if (isDefined(partitionKey)) {
340
+ result.partitionKey = String(partitionKey);
341
+ }
342
+ return result;
343
+ }
344
+ /**
345
+ * @internal
346
+ */
347
+ function extractPartitionAssignmentFromBatch(batch, options) {
348
+ const result = {};
349
+ const partitionId = batch.partitionId;
350
+ const partitionKey = batch.partitionKey;
351
+ const { partitionId: unexpectedPartitionId, partitionKey: unexpectedPartitionKey } = extractPartitionAssignmentFromOptions(options);
352
+ if (unexpectedPartitionKey && partitionKey !== unexpectedPartitionKey) {
353
+ throw new Error(`The partitionKey (${unexpectedPartitionKey}) set on sendBatch does not match the partitionKey (${partitionKey}) set when creating the batch.`);
354
+ }
355
+ if (unexpectedPartitionId && unexpectedPartitionId !== partitionId) {
356
+ throw new Error(`The partitionId (${unexpectedPartitionId}) set on sendBatch does not match the partitionId (${partitionId}) set when creating the batch.`);
357
+ }
358
+ if (isDefined(partitionId)) {
359
+ result.partitionId = String(partitionId);
360
+ }
361
+ if (isDefined(partitionKey)) {
362
+ result.partitionKey = String(partitionKey);
363
+ }
364
+ return result;
365
+ }
366
+ //# sourceMappingURL=eventHubProducerClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eventHubProducerClient.js","sourceRoot":"","sources":["../../src/eventHubProducerClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAcjE,OAAO,EAAE,kBAAkB,E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AC,WAAW,CAAC,CAAC;IAC3C,CAAC;IACD,IAAI,SAAS,CAAC,YAAY,CAAC,EAAE,CAAC;QAC5B,MAAM,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;IAC7C,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,SAAS,mCAAmC,CAC1C,KAAqB,EACrB,OAAyB;IAEzB,MAAM,MAAM,GAA2D,EAAE,CAAC;IAC1E,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC;IACtC,MAAM,YAAY,GAAG,KAAK,CAAC,YAAY,CAAC;IAExC,MAAM,EAAE,WAAW,EAAE,qBAAqB,EAAE,YAAY,EAAE,sBAAsB,EAAE,GAChF,qCAAqC,CAAC,OAAO,CAAC,CAAC;IACjD,IAAI,sBAAsB,IAAI,YAAY,KAAK,sBAAsB,EAAE,CAAC;QACtE,MAAM,IAAI,KAAK,CACb,qBAAqB,sBAAsB,uDAAuD,YAAY,gCAAgC,CAC/I,CAAC;IACJ,CAAC;IACD,IAAI,qBAAqB,IAAI,qBAAqB,KAAK,WAAW,EAAE,CAAC;QACnE,MAAM,IAAI,KAAK,CACb,oBAAoB,qBAAqB,sDAAsD,WAAW,gCAAgC,CAC3I,CAAC;IACJ,CAAC;IAED,IAAI,SAAS,CAAC,WAAW,CAAC,EAAE,CAAC;QAC3B,MAAM,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;IAC3C,CAAC;IACD,IAAI,SAAS,CAAC,YAAY,CAAC,EAAE,CAAC;QAC5B,MAAM,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;IAC7C,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { ConnectionContext } from \"./connectionContext.js\";\nimport { createConnectionContext } from \"./connectionContext.js\";\nimport type {\n CreateBatchOptions,\n EventHubClientOptions,\n GetEventHubPropertiesOptions,\n GetPartitionIdsOptions,\n GetPartitionPropertiesOptions,\n SendBatchOptions,\n} from \"./models/public.js\";\nimport type {\n PartitionPublishingOptions,\n PartitionPublishingProperties,\n} from \"./models/private.js\";\nimport type { EventDataBatch } from \"./eventDataBatch.js\";\nimport { EventDataBatchImpl, isEventDataBatch } from \"./eventDataBatch.js\";\nimport type { EventHubProperties, PartitionProperties } from \"./managementClient.js\";\nimport type { TracingContext, TracingSpanLink } from \"@azure/core-tracing\";\nimport type { NamedKeyCredential, SASCredential, TokenCredential } from \"@azure/core-auth\";\nimport { isDefined } from \"@azure/core-util\";\nimport { isCredential } from \"./util/typeGuards.js\";\nimport { logErrorStackTrace, logger } from \"./logger.js\";\nimport {\n idempotentAlreadyPublished,\n idempotentSomeAlreadyPublished,\n throwErrorIfConnectionClosed,\n throwTypeErrorIfParameterMissing,\n validateProducerPartitionSettings,\n} from \"./util/error.js\";\nimport type { AmqpAnnotatedMessage } from \"@azure/core-amqp\";\nimport type { EventData, EventDataInternal } from \"./eventData.js\";\nimport { assertIsEventData } from \"./eventData.js\";\nimport { EventHubSender } from \"./eventHubSender.js\";\nimport type { OperationOptions } from \"./util/operationOptions.js\";\nimport { toSpanOptions, tracingClient } from \"./diagnostics/tracing.js\";\nimport { instrumentEventData } from \"./diagnostics/instrumentEventData.js\";\nimport { getRandomName } from \"./util/utils.js\";\n\n/**\n * The `EventHubProducerClient` class is used to send events to an Event Hub.\n *\n * There are multiple ways to create an `EventHubProducerClient`\n * - Use the connection string from the SAS policy created for your Event Hub instance.\n * - Use the connection string from the SAS policy created for your Event Hub namespace,\n * and the name of the Event Hub instance\n * - Use the full namespace like `<yournamespace>.servicebus.windows.net`, and a credentials object.\n *\n * Optionally, you can also pass an options bag to configure the retry policy or proxy settings.\n *\n */\nexport class EventHubProducerClient {\n /**\n * Describes the amqp connection context for the client.\n */\n private _context: ConnectionContext;\n\n /**\n * The options passed by the user when creating the EventHubClient instance.\n */\n private _clientOptions: EventHubClientOptions;\n /**\n * Map of partitionId to senders\n */\n private _sendersMap: Map<string, EventHubSender>;\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 private _enableIdempotentRetries?: boolean;\n /**\n * The set of options that can be specified to influence publishing behavior specific to the configured Event Hub partition.\n * These options are not necessary in the majority of scenarios and are intended for use with specialized scenarios,\n * such as when recovering the state used for idempotent publishing.\n */\n private _partitionOptions?: Record<string, PartitionPublishingOptions>;\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._context.config.entityPath;\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._context.config.host;\n }\n\n /**\n * The name used to identify this EventHubProducerClient.\n * If not specified or empty, a random unique one will be generated.\n */\n public readonly identifier: string;\n\n /**\n * The `EventHubProducerClient` 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?: EventHubClientOptions); // eslint-disable-line @azure/azure-sdk/ts-naming-options\n /**\n * The `EventHubProducerClient` 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(connectionString: string, eventHubName: string, options?: EventHubClientOptions); // eslint-disable-line @azure/azure-sdk/ts-naming-options\n /**\n * The `EventHubProducerClient` 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?: EventHubClientOptions, // eslint-disable-line @azure/azure-sdk/ts-naming-options\n );\n constructor(\n fullyQualifiedNamespaceOrConnectionString1: string,\n eventHubNameOrOptions2?: string | EventHubClientOptions,\n credentialOrOptions3?:\n | TokenCredential\n | NamedKeyCredential\n | SASCredential\n | EventHubClientOptions,\n options4?: EventHubClientOptions, // eslint-disable-line @azure/azure-sdk/ts-naming-options\n ) {\n this._context = createConnectionContext(\n fullyQualifiedNamespaceOrConnectionString1,\n eventHubNameOrOptions2,\n credentialOrOptions3,\n options4,\n );\n if (typeof eventHubNameOrOptions2 !== \"string\") {\n this._clientOptions = eventHubNameOrOptions2 || {};\n } else if (!isCredential(credentialOrOptions3)) {\n this._clientOptions = credentialOrOptions3 || {};\n } else {\n this._clientOptions = options4 || {};\n }\n this.identifier = this._clientOptions.identifier ?? getRandomName();\n this._sendersMap = new Map();\n }\n\n /**\n * Creates an instance of `EventDataBatch` to which one can add events until the maximum supported size is reached.\n * The batch can be passed to the {@link sendBatch} method of the `EventHubProducerClient` to be sent to Azure Event Hubs.\n *\n * Events with different values for partitionKey or partitionId will need to be put into different batches.\n * To simplify such batch management across partitions or to have the client automatically batch events\n * and send them in specific intervals, use `EventHubBufferedProducerClient` instead.\n *\n * The below example assumes you have an array of events at hand to be batched safely.\n * If you have events coming in one by one, `EventHubBufferedProducerClient` is recommended instead\n * for effecient management of batches.\n *\n * Example usage:\n * ```ts snippet:EventHubProducerClient_CreateBatch\n * import { EventHubProducerClient } from \"@azure/event-hubs\";\n *\n * const client = new EventHubProducerClient(\"my-connection-string\", \"my-event-hub\");\n *\n * const messages = [\n * { body: \"my-event-body1\" },\n * { body: \"my-event-body2\" },\n * { body: \"my-event-body3\" },\n * { body: \"my-event-body4\" },\n * { body: \"my-event-body5\" },\n * ];\n *\n * let batch = await client.createBatch();\n * for (let i = 0; i < messages.length; i++) {\n * if (!batch.tryAdd(messages[i])) {\n * await client.sendBatch(batch);\n * batch = await client.createBatch();\n * if (!batch.tryAdd(messages[i])) {\n * throw new Error(\"Message too big to fit\");\n * }\n * if (i === messages.length - 1) {\n * await client.sendBatch(batch);\n * }\n * }\n * }\n * ```\n *\n * @param options - Configures the behavior of the batch.\n * - `partitionKey` : A value that is hashed and used by the Azure Event Hubs service to determine the partition to which\n * the events need to be sent.\n * - `partitionId` : Id of the partition to which the batch of events need to be sent.\n * - `maxSizeInBytes`: The upper limit for the size of batch. The `tryAdd` function will return `false` after this limit is reached.\n * - `abortSignal` : A signal the request to cancel the operation.\n * @returns Promise<EventDataBatch>\n * @throws Error if both `partitionId` and `partitionKey` are set in the options.\n * @throws Error if the underlying connection has been closed, create a new EventHubProducerClient.\n * @throws AbortError if the operation is cancelled via the abortSignal in the options.\n */\n async createBatch(options: CreateBatchOptions = {}): Promise<EventDataBatch> {\n throwErrorIfConnectionClosed(this._context);\n\n const partitionId = isDefined(options.partitionId) ? String(options.partitionId) : undefined;\n\n validateProducerPartitionSettings({\n enableIdempotentRetries: this._enableIdempotentRetries,\n partitionId,\n partitionKey: options.partitionKey,\n });\n\n let sender = this._sendersMap.get(partitionId || \"\");\n if (!sender) {\n const partitionPublishingOptions = isDefined(partitionId)\n ? this._partitionOptions?.[partitionId]\n : undefined;\n sender = EventHubSender.create(this._context, this.identifier, {\n enableIdempotentProducer: Boolean(this._enableIdempotentRetries),\n partitionId,\n partitionPublishingOptions,\n });\n this._sendersMap.set(partitionId || \"\", sender);\n }\n\n let maxMessageSize = await sender.getMaxMessageSize({\n retryOptions: this._clientOptions.retryOptions,\n abortSignal: options.abortSignal,\n });\n\n if (options.maxSizeInBytes) {\n if (options.maxSizeInBytes > maxMessageSize) {\n const error = new Error(\n `Max message size (${options.maxSizeInBytes} bytes) is greater than maximum message size (${maxMessageSize} bytes) on the AMQP sender link.`,\n );\n logger.warning(`[${this._context.connectionId}] ${error.message}`);\n logErrorStackTrace(error);\n throw error;\n }\n maxMessageSize = options.maxSizeInBytes;\n }\n return new EventDataBatchImpl(\n this._context,\n maxMessageSize,\n Boolean(this._enableIdempotentRetries),\n options.partitionKey,\n partitionId,\n );\n }\n\n /**\n * Get the information about the state of publishing for a partition as observed by the `EventHubProducerClient`.\n * This data can always be read, but will only be populated with information relevant to the active features\n * for the producer client.\n *\n * @param partitionId - Id of the partition from which to retrieve publishing properties.\n * @param options - The set of options to apply to the operation call.\n * - `abortSignal` : A signal the request to cancel the send operation.\n * @returns Promise<void>\n * @throws AbortError if the operation is cancelled via the abortSignal.\n */\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore this is called in EventHubBufferedProducerClient via cast-to-any workaround\n private async getPartitionPublishingProperties(\n partitionId: string,\n options: OperationOptions = {},\n ): Promise<PartitionPublishingProperties> {\n if (!isDefined(partitionId)) {\n throw new TypeError(\n `getPartitionPublishingProperties called without required argument \"partitionId\"`,\n );\n }\n\n if (typeof partitionId === \"number\") {\n partitionId = String(partitionId);\n }\n\n let sender = this._sendersMap.get(partitionId);\n if (!sender) {\n sender = EventHubSender.create(this._context, this.identifier, {\n enableIdempotentProducer: Boolean(this._enableIdempotentRetries),\n partitionId,\n partitionPublishingOptions: this._partitionOptions?.[partitionId],\n });\n this._sendersMap.set(partitionId, sender);\n }\n\n return sender.getPartitionPublishingProperties(options);\n }\n\n /**\n * Sends an array of events as a batch to the associated Event Hub.\n *\n * Azure Event Hubs has a limit on the size of the batch that can be sent which if exceeded\n * will result in an error with code `MessageTooLargeError`.\n * To safely send within batch size limits, use `EventHubProducerClient.createBatch()` or\n * `EventHubBufferedProducerClient` instead.\n *\n * Example usage:\n * ```ts snippet:EventHubProducerClient_SendBatch\n * import { EventHubProducerClient } from \"@azure/event-hubs\";\n *\n * const client = new EventHubProducerClient(\"my-connection-string\", \"my-event-hub\");\n *\n * const messages = [\n * { body: \"my-event-body1\" },\n * { body: \"my-event-body2\" },\n * { body: \"my-event-body3\" },\n * { body: \"my-event-body4\" },\n * { body: \"my-event-body5\" },\n * ];\n *\n * await client.sendBatch(messages);\n * ```\n *\n * @param batch - 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 the request to cancel the send operation.\n * - `partitionId` : The partition this batch 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 *\n * @returns Promise<void>\n * @throws MessageTooLargeError if all the events in the input array cannot be fit into a batch.\n * @throws AbortError if the operation is cancelled via the abortSignal.\n * @throws MessagingError if an error is encountered while sending a message.\n * @throws Error if the underlying connection or sender has been closed.\n */\n async sendBatch(\n batch: EventData[] | AmqpAnnotatedMessage[],\n options?: SendBatchOptions,\n ): Promise<void>;\n /**\n * Sends a batch of events created using `EventHubProducerClient.createBatch()` to the associated Event Hub.\n *\n * Events with different values for partitionKey or partitionId will need to be put into different batches.\n * To simplify such batch management across partitions or to have the client automatically batch events\n * and send them in specific intervals, use `EventHubBufferedProducerClient` instead.\n *\n * The below example assumes you have an array of events at hand to be batched safely.\n * If you have events coming in one by one, `EventHubBufferedProducerClient` is recommended instead\n * for effecient management of batches.\n *\n * Example usage:\n * ```ts snippet:EventHubProducerClient_SendBatchPartitioned\n * import { EventHubProducerClient } from \"@azure/event-hubs\";\n *\n * const client = new EventHubProducerClient(\"my-connection-string\", \"my-event-hub\");\n *\n * const messages = [\n * { body: \"my-event-body1\" },\n * { body: \"my-event-body2\" },\n * { body: \"my-event-body3\" },\n * { body: \"my-event-body4\" },\n * { body: \"my-event-body5\" },\n * ];\n *\n * let batch = await client.createBatch();\n * for (let i = 0; i < messages.length; i++) {\n * if (!batch.tryAdd(messages[i])) {\n * await client.sendBatch(batch);\n * batch = await client.createBatch();\n * if (!batch.tryAdd(messages[i])) {\n * throw new Error(\"Message too big to fit\");\n * }\n * if (i === messages.length - 1) {\n * await client.sendBatch(batch);\n * }\n * }\n * }\n * ```\n * @param batch - A batch of events that you can create using the {@link createBatch} method.\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 the request to cancel the send operation.\n *\n * @returns Promise<void>\n * @throws AbortError if the operation is cancelled via the abortSignal.\n * @throws MessagingError if an error is encountered while sending a message.\n * @throws Error if the underlying connection or sender has been closed.\n */\n async sendBatch(batch: EventDataBatch, options?: OperationOptions): Promise<void>;\n async sendBatch(\n batch: EventDataBatch | EventData[],\n options: SendBatchOptions | OperationOptions = {},\n ): Promise<void> {\n throwErrorIfConnectionClosed(this._context);\n throwTypeErrorIfParameterMissing(this._context.connectionId, \"sendBatch\", \"batch\", batch);\n\n let partitionId: string | undefined;\n let partitionKey: string | undefined;\n\n // Holds an EventData properties object containing tracing properties.\n // This lets us avoid cloning batch when it is EventData[], which is\n // important as the idempotent EventHubSender needs to decorate the\n // original EventData passed through.\n const eventDataTracingProperties: Array<EventData[\"properties\"]> = [];\n\n // link message span contexts\n let spanContextsToLink: TracingContext[] = [];\n\n if (isEventDataBatch(batch)) {\n if (\n this._enableIdempotentRetries &&\n isDefined((batch as EventDataBatchImpl).startingPublishedSequenceNumber)\n ) {\n throw new Error(idempotentAlreadyPublished);\n }\n const partitionAssignment = extractPartitionAssignmentFromBatch(batch, options);\n partitionId = partitionAssignment.partitionId;\n partitionKey = partitionAssignment.partitionKey;\n spanContextsToLink = (batch as EventDataBatchImpl)._messageSpanContexts;\n } else {\n if (!Array.isArray(batch)) {\n batch = [batch];\n }\n batch.forEach(assertIsEventData);\n if (batch.some((event) => isDefined((event as EventDataInternal)._publishedSequenceNumber))) {\n throw new Error(idempotentSomeAlreadyPublished);\n }\n const partitionAssignment = extractPartitionAssignmentFromOptions(options);\n partitionId = partitionAssignment.partitionId;\n partitionKey = partitionAssignment.partitionKey;\n\n for (let i = 0; i < batch.length; i++) {\n batch[i] = instrumentEventData(\n batch[i],\n options,\n this._context.config.entityPath,\n this._context.config.host,\n \"publish\",\n ).event;\n eventDataTracingProperties[i] = batch[i].properties;\n }\n }\n\n validateProducerPartitionSettings({\n enableIdempotentRetries: this._enableIdempotentRetries,\n partitionId,\n partitionKey,\n });\n\n return tracingClient.withSpan(\n `${EventHubProducerClient.name}.${this.sendBatch.name}`,\n options,\n (updatedOptions) => {\n let sender = this._sendersMap.get(partitionId || \"\");\n if (!sender) {\n const partitionPublishingOptions = isDefined(partitionId)\n ? this._partitionOptions?.[partitionId]\n : undefined;\n sender = EventHubSender.create(this._context, this.identifier, {\n enableIdempotentProducer: Boolean(this._enableIdempotentRetries),\n partitionId,\n partitionPublishingOptions,\n });\n this._sendersMap.set(partitionId || \"\", sender);\n }\n\n return sender.send(batch, {\n ...updatedOptions,\n partitionId,\n partitionKey,\n retryOptions: this._clientOptions.retryOptions,\n });\n },\n {\n spanLinks: spanContextsToLink.map<TracingSpanLink>((tracingContext) => {\n return { tracingContext };\n }),\n ...toSpanOptions(this._context.config, \"publish\", \"client\"),\n },\n );\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 * @returns Promise<void>\n * @throws Error if the underlying connection encounters an error while closing.\n */\n async close(): Promise<void> {\n await this._context.close();\n\n for (const pair of this._sendersMap) {\n await pair[1].close();\n }\n this._sendersMap.clear();\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 EventHubProducerClient.\n * @throws AbortError if the operation is cancelled via the abortSignal.\n */\n getEventHubProperties(options: GetEventHubPropertiesOptions = {}): Promise<EventHubProperties> {\n return this._context.managementSession!.getEventHubProperties({\n ...options,\n retryOptions: this._clientOptions.retryOptions,\n });\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 EventHubProducerClient.\n * @throws AbortError if the operation is cancelled via the abortSignal.\n */\n async getPartitionIds(options: GetPartitionIdsOptions = {}): Promise<Array<string>> {\n const eventHubProperties = await this._context.managementSession!.getEventHubProperties({\n ...options,\n retryOptions: this._clientOptions.retryOptions,\n });\n return eventHubProperties.partitionIds;\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 EventHubProducerClient.\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._context.managementSession!.getPartitionProperties(partitionId, {\n ...options,\n retryOptions: this._clientOptions.retryOptions,\n });\n }\n}\n\n/**\n * @internal\n */\nfunction extractPartitionAssignmentFromOptions(options: SendBatchOptions = {}): {\n partitionKey?: string;\n partitionId?: string;\n} {\n const result: ReturnType<typeof extractPartitionAssignmentFromOptions> = {};\n const { partitionId, partitionKey } = options;\n\n if (isDefined(partitionId)) {\n result.partitionId = String(partitionId);\n }\n if (isDefined(partitionKey)) {\n result.partitionKey = String(partitionKey);\n }\n\n return result;\n}\n\n/**\n * @internal\n */\nfunction extractPartitionAssignmentFromBatch(\n batch: EventDataBatch,\n options: SendBatchOptions,\n): { partitionKey?: string; partitionId?: string } {\n const result: ReturnType<typeof extractPartitionAssignmentFromBatch> = {};\n const partitionId = batch.partitionId;\n const partitionKey = batch.partitionKey;\n\n const { partitionId: unexpectedPartitionId, partitionKey: unexpectedPartitionKey } =\n extractPartitionAssignmentFromOptions(options);\n if (unexpectedPartitionKey && partitionKey !== unexpectedPartitionKey) {\n throw new Error(\n `The partitionKey (${unexpectedPartitionKey}) set on sendBatch does not match the partitionKey (${partitionKey}) set when creating the batch.`,\n );\n }\n if (unexpectedPartitionId && unexpectedPartitionId !== partitionId) {\n throw new Error(\n `The partitionId (${unexpectedPartitionId}) set on sendBatch does not match the partitionId (${partitionId}) set when creating the batch.`,\n );\n }\n\n if (isDefined(partitionId)) {\n result.partitionId = String(partitionId);\n }\n if (isDefined(partitionKey)) {\n result.partitionKey = String(partitionKey);\n }\n\n return result;\n}\n"]}