@azure/event-hubs 6.0.1-alpha.20250619.1 → 6.0.1-alpha.20250804.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 (140) hide show
  1. package/dist/browser/batchingPartitionChannel.js +23 -17
  2. package/dist/browser/batchingPartitionChannel.js.map +1 -1
  3. package/dist/browser/connectionContext.js +18 -32
  4. package/dist/browser/connectionContext.js.map +1 -1
  5. package/dist/browser/diagnostics/instrumentEventData.js +6 -7
  6. package/dist/browser/diagnostics/instrumentEventData.js.map +1 -1
  7. package/dist/browser/eventData.js +6 -4
  8. package/dist/browser/eventData.js.map +1 -1
  9. package/dist/browser/eventDataAdapter.js +5 -2
  10. package/dist/browser/eventDataAdapter.js.map +1 -1
  11. package/dist/browser/eventDataBatch.js +61 -9
  12. package/dist/browser/eventDataBatch.js.map +1 -1
  13. package/dist/browser/eventHubBufferedProducerClient.js +65 -50
  14. package/dist/browser/eventHubBufferedProducerClient.js.map +1 -1
  15. package/dist/browser/eventHubConsumerClient.js +70 -24
  16. package/dist/browser/eventHubConsumerClient.js.map +1 -1
  17. package/dist/browser/eventHubProducerClient.js +58 -15
  18. package/dist/browser/eventHubProducerClient.js.map +1 -1
  19. package/dist/browser/eventHubSender.js +118 -35
  20. package/dist/browser/eventHubSender.js.map +1 -1
  21. package/dist/browser/eventProcessor.js +27 -5
  22. package/dist/browser/eventProcessor.js.map +1 -1
  23. package/dist/browser/impl/awaitableQueue.js +6 -2
  24. package/dist/browser/impl/awaitableQueue.js.map +1 -1
  25. package/dist/browser/impl/partitionAssigner.js +2 -4
  26. package/dist/browser/impl/partitionAssigner.js.map +1 -1
  27. package/dist/browser/impl/partitionGate.js +1 -3
  28. package/dist/browser/impl/partitionGate.js.map +1 -1
  29. package/dist/browser/inMemoryCheckpointStore.js +10 -8
  30. package/dist/browser/inMemoryCheckpointStore.js.map +1 -1
  31. package/dist/browser/loadBalancerStrategies/balancedStrategy.js +1 -0
  32. package/dist/browser/loadBalancerStrategies/balancedStrategy.js.map +1 -1
  33. package/dist/browser/loadBalancerStrategies/greedyStrategy.js +1 -0
  34. package/dist/browser/loadBalancerStrategies/greedyStrategy.js.map +1 -1
  35. package/dist/browser/managementClient.js +53 -19
  36. package/dist/browser/managementClient.js.map +1 -1
  37. package/dist/browser/partitionProcessor.js +5 -2
  38. package/dist/browser/partitionProcessor.js.map +1 -1
  39. package/dist/browser/partitionPump.js +15 -6
  40. package/dist/browser/partitionPump.js.map +1 -1
  41. package/dist/browser/partitionReceiver.js +30 -25
  42. package/dist/browser/partitionReceiver.js.map +1 -1
  43. package/dist/browser/pumpManager.js +3 -1
  44. package/dist/browser/pumpManager.js.map +1 -1
  45. package/dist/browser/util/delayWithoutThrow.js +1 -1
  46. package/dist/browser/util/delayWithoutThrow.js.map +1 -1
  47. package/dist/commonjs/batchingPartitionChannel.js +23 -17
  48. package/dist/commonjs/batchingPartitionChannel.js.map +1 -1
  49. package/dist/commonjs/connectionContext.js +18 -32
  50. package/dist/commonjs/connectionContext.js.map +1 -1
  51. package/dist/commonjs/diagnostics/instrumentEventData.js +6 -7
  52. package/dist/commonjs/diagnostics/instrumentEventData.js.map +1 -1
  53. package/dist/commonjs/eventData.js +6 -4
  54. package/dist/commonjs/eventData.js.map +1 -1
  55. package/dist/commonjs/eventDataAdapter.js +5 -2
  56. package/dist/commonjs/eventDataAdapter.js.map +1 -1
  57. package/dist/commonjs/eventDataBatch.js +61 -9
  58. package/dist/commonjs/eventDataBatch.js.map +1 -1
  59. package/dist/commonjs/eventHubBufferedProducerClient.js +65 -50
  60. package/dist/commonjs/eventHubBufferedProducerClient.js.map +1 -1
  61. package/dist/commonjs/eventHubConsumerClient.js +70 -24
  62. package/dist/commonjs/eventHubConsumerClient.js.map +1 -1
  63. package/dist/commonjs/eventHubProducerClient.js +58 -15
  64. package/dist/commonjs/eventHubProducerClient.js.map +1 -1
  65. package/dist/commonjs/eventHubSender.js +118 -35
  66. package/dist/commonjs/eventHubSender.js.map +1 -1
  67. package/dist/commonjs/eventProcessor.js +27 -5
  68. package/dist/commonjs/eventProcessor.js.map +1 -1
  69. package/dist/commonjs/impl/awaitableQueue.js +6 -2
  70. package/dist/commonjs/impl/awaitableQueue.js.map +1 -1
  71. package/dist/commonjs/impl/partitionAssigner.js +2 -4
  72. package/dist/commonjs/impl/partitionAssigner.js.map +1 -1
  73. package/dist/commonjs/impl/partitionGate.js +1 -3
  74. package/dist/commonjs/impl/partitionGate.js.map +1 -1
  75. package/dist/commonjs/inMemoryCheckpointStore.js +10 -8
  76. package/dist/commonjs/inMemoryCheckpointStore.js.map +1 -1
  77. package/dist/commonjs/loadBalancerStrategies/balancedStrategy.js +1 -0
  78. package/dist/commonjs/loadBalancerStrategies/balancedStrategy.js.map +1 -1
  79. package/dist/commonjs/loadBalancerStrategies/greedyStrategy.js +1 -0
  80. package/dist/commonjs/loadBalancerStrategies/greedyStrategy.js.map +1 -1
  81. package/dist/commonjs/managementClient.js +53 -19
  82. package/dist/commonjs/managementClient.js.map +1 -1
  83. package/dist/commonjs/partitionProcessor.js +5 -2
  84. package/dist/commonjs/partitionProcessor.js.map +1 -1
  85. package/dist/commonjs/partitionPump.js +15 -6
  86. package/dist/commonjs/partitionPump.js.map +1 -1
  87. package/dist/commonjs/partitionReceiver.js +30 -25
  88. package/dist/commonjs/partitionReceiver.js.map +1 -1
  89. package/dist/commonjs/pumpManager.js +3 -1
  90. package/dist/commonjs/pumpManager.js.map +1 -1
  91. package/dist/commonjs/tsdoc-metadata.json +11 -11
  92. package/dist/commonjs/util/delayWithoutThrow.js +1 -1
  93. package/dist/commonjs/util/delayWithoutThrow.js.map +1 -1
  94. package/dist/esm/batchingPartitionChannel.js +23 -17
  95. package/dist/esm/batchingPartitionChannel.js.map +1 -1
  96. package/dist/esm/connectionContext.js +18 -32
  97. package/dist/esm/connectionContext.js.map +1 -1
  98. package/dist/esm/diagnostics/instrumentEventData.js +6 -7
  99. package/dist/esm/diagnostics/instrumentEventData.js.map +1 -1
  100. package/dist/esm/eventData.js +6 -4
  101. package/dist/esm/eventData.js.map +1 -1
  102. package/dist/esm/eventDataAdapter.js +5 -2
  103. package/dist/esm/eventDataAdapter.js.map +1 -1
  104. package/dist/esm/eventDataBatch.js +61 -9
  105. package/dist/esm/eventDataBatch.js.map +1 -1
  106. package/dist/esm/eventHubBufferedProducerClient.js +65 -50
  107. package/dist/esm/eventHubBufferedProducerClient.js.map +1 -1
  108. package/dist/esm/eventHubConsumerClient.js +70 -24
  109. package/dist/esm/eventHubConsumerClient.js.map +1 -1
  110. package/dist/esm/eventHubProducerClient.js +58 -15
  111. package/dist/esm/eventHubProducerClient.js.map +1 -1
  112. package/dist/esm/eventHubSender.js +118 -35
  113. package/dist/esm/eventHubSender.js.map +1 -1
  114. package/dist/esm/eventProcessor.js +27 -5
  115. package/dist/esm/eventProcessor.js.map +1 -1
  116. package/dist/esm/impl/awaitableQueue.js +6 -2
  117. package/dist/esm/impl/awaitableQueue.js.map +1 -1
  118. package/dist/esm/impl/partitionAssigner.js +2 -4
  119. package/dist/esm/impl/partitionAssigner.js.map +1 -1
  120. package/dist/esm/impl/partitionGate.js +1 -3
  121. package/dist/esm/impl/partitionGate.js.map +1 -1
  122. package/dist/esm/inMemoryCheckpointStore.js +10 -8
  123. package/dist/esm/inMemoryCheckpointStore.js.map +1 -1
  124. package/dist/esm/loadBalancerStrategies/balancedStrategy.js +1 -0
  125. package/dist/esm/loadBalancerStrategies/balancedStrategy.js.map +1 -1
  126. package/dist/esm/loadBalancerStrategies/greedyStrategy.js +1 -0
  127. package/dist/esm/loadBalancerStrategies/greedyStrategy.js.map +1 -1
  128. package/dist/esm/managementClient.js +53 -19
  129. package/dist/esm/managementClient.js.map +1 -1
  130. package/dist/esm/partitionProcessor.js +5 -2
  131. package/dist/esm/partitionProcessor.js.map +1 -1
  132. package/dist/esm/partitionPump.js +15 -6
  133. package/dist/esm/partitionPump.js.map +1 -1
  134. package/dist/esm/partitionReceiver.js +30 -25
  135. package/dist/esm/partitionReceiver.js.map +1 -1
  136. package/dist/esm/pumpManager.js +3 -1
  137. package/dist/esm/pumpManager.js.map +1 -1
  138. package/dist/esm/util/delayWithoutThrow.js +1 -1
  139. package/dist/esm/util/delayWithoutThrow.js.map +1 -1
  140. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"eventHubConsumerClient.js","sourceRoot":"","sources":["../../src/eventHubConsumerClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAejE,OAAO,EAAE,6BAA6B,EAAE,MAAM,8CAA8C,CAAC;AAC7F,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,2BAA2B,EAAE,MAAM,4CAA4C,CAAC;AACzF,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,+BAA+B,EAAE,MAAM,gDAAgD,CAAC;AACjG,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,4BAA4B,GAE9B;IACF,sFAAsF;IACtF,yCAAyC;IACzC,YAAY,EAAE,CAAC;IACf,oBAAoB,EAAE,EAAE;CACzB,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,sBAAsB;IA+BjC;;;OAGG;IACH,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC;IACzC,CAAC;IAED;;;;OAIG;IACH,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AAwB,GAAW,SAAS,CAAC,oBAAoB,AAAzC,CAA0C;AAgkB3E;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,QAA+B;IAC/D,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,eAAe,GAAG,QAA2B,CAAC;IAEpD,OAAO,CACL,OAAO,eAAe,CAAC,cAAc,KAAK,UAAU;QACpD,OAAO,eAAe,CAAC,eAAe,KAAK,UAAU;QACrD,OAAO,eAAe,CAAC,aAAa,KAAK,UAAU;QACnD,OAAO,eAAe,CAAC,gBAAgB,KAAK,UAAU,CACvD,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,2BAA2B,CAClC,QAAyC;IAEzC,OAAO,OAAQ,QAAsC,CAAC,aAAa,KAAK,UAAU,CAAC;AACrF,CAAC;AAED,SAAS,aAAa,CACpB,OAAqC,EACrC,wBAAiC;IAEjC,IAAI,OAAO,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;QAClC,OAAO,OAAO,CAAC,UAAU,CAAC;IAC5B,CAAC;IAED,IAAI,wBAAwB,EAAE,CAAC;QAC7B,OAAO,CAAC,CAAC;IACX,CAAC;SAAM,CAAC;QACN,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { CheckpointStore, FullEventProcessorOptions } from \"./eventProcessor.js\";\nimport { EventProcessor } from \"./eventProcessor.js\";\nimport type { ConnectionContext } from \"./connectionContext.js\";\nimport { createConnectionContext } from \"./connectionContext.js\";\nimport type {\n EventHubConsumerClientOptions,\n GetEventHubPropertiesOptions,\n GetPartitionIdsOptions,\n GetPartitionPropertiesOptions,\n LoadBalancingOptions,\n} from \"./models/public.js\";\nimport type { EventHubProperties, PartitionProperties } from \"./managementClient.js\";\nimport type { NamedKeyCredential, SASCredential, TokenCredential } from \"@azure/core-auth\";\nimport type {\n SubscribeOptions,\n Subscription,\n SubscriptionEventHandlers,\n} from \"./eventHubConsumerClientModels.js\";\nimport { BalancedLoadBalancingStrategy } from \"./loadBalancerStrategies/balancedStrategy.js\";\nimport { Constants } from \"@azure/core-amqp\";\nimport { GreedyLoadBalancingStrategy } from \"./loadBalancerStrategies/greedyStrategy.js\";\nimport { InMemoryCheckpointStore } from \"./inMemoryCheckpointStore.js\";\nimport type { LoadBalancingStrategy } from \"./loadBalancerStrategies/loadBalancingStrategy.js\";\nimport { PartitionGate } from \"./impl/partitionGate.js\";\nimport { UnbalancedLoadBalancingStrategy } from \"./loadBalancerStrategies/unbalancedStrategy.js\";\nimport { isCredential } from \"./util/typeGuards.js\";\nimport { logger } from \"./logger.js\";\nimport { validateEventPositions } from \"./eventPosition.js\";\nimport { getRandomName } from \"./util/utils.js\";\n\nconst defaultConsumerClientOptions: Required<\n Pick<FullEventProcessorOptions, \"maxWaitTimeInSeconds\" | \"maxBatchSize\">\n> = {\n // to support our current \"process single event only\" workflow we'll also purposefully\n // only request a single event at a time.\n maxBatchSize: 1,\n maxWaitTimeInSeconds: 60,\n};\n\n/**\n * The `EventHubConsumerClient` class is used to consume events from an Event Hub.\n *\n * There are multiple ways to create an `EventHubConsumerClient`\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:\n * - An options bag to configure the retry policy or proxy settings.\n * - A checkpoint store that is used by the client to read checkpoints to determine the position from where it should\n * resume receiving events when your application gets restarted. The checkpoint store is also used by the client\n * to load balance multiple instances of your application.\n */\nexport class EventHubConsumerClient {\n /**\n * Describes the amqp connection context for the client.\n */\n private _context: ConnectionContext;\n /**\n * The options passed by the user when creating the EventHubClient instance.\n */\n private _clientOptions: EventHubConsumerClientOptions;\n private _partitionGate = new PartitionGate();\n\n /**\n * The Subscriptions that were spawned by calling `subscribe()`.\n * Subscriptions that have been stopped by the user will not\n * be present in this set.\n */\n private _subscriptions = new Set<Subscription>();\n\n /**\n * The name of the default consumer group in the Event Hubs service.\n */\n static defaultConsumerGroupName: string = Constants.defaultConsumerGroup;\n\n private _checkpointStore: CheckpointStore;\n private _userChoseCheckpointStore: boolean;\n\n /**\n * Options for configuring load balancing.\n */\n private readonly _loadBalancingOptions: Required<LoadBalancingOptions>;\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._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 EventHubConsumerClient.\n * If not specified or empty, a random unique one will be generated.\n */\n public readonly identifier: string;\n\n /**\n * The `EventHubConsumerClient` class is used to consume events from an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param consumerGroup - The name of the consumer group from which you want to process events.\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(\n consumerGroup: string,\n connectionString: string,\n options?: EventHubConsumerClientOptions,\n ); // #1\n /**\n * The `EventHubConsumerClient` class is used to consume events from an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param consumerGroup - The name of the consumer group from which you want to process events.\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 checkpointStore - A checkpoint store that is used by the client to read checkpoints to determine\n * the position from where it should resume receiving events when your application gets restarted.\n * It is also used by the client to load balance multiple instances of your application.\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 consumerGroup: string,\n connectionString: string,\n checkpointStore: CheckpointStore,\n options?: EventHubConsumerClientOptions,\n ); // #1.1\n /**\n * The `EventHubConsumerClient` class is used to consume events from an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param consumerGroup - The name of the consumer group from which you want to process events.\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 consumerGroup: string,\n connectionString: string,\n eventHubName: string,\n options?: EventHubConsumerClientOptions,\n ); // #2\n /**\n * The `EventHubConsumerClient` class is used to consume events from an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param consumerGroup - The name of the consumer group from which you want to process events.\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 checkpointStore - A checkpoint store that is used by the client to read checkpoints to determine\n * the position from where it should resume receiving events when your application gets restarted.\n * It is also used by the client to load balance multiple instances of your application.\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 consumerGroup: string,\n connectionString: string,\n eventHubName: string,\n checkpointStore: CheckpointStore,\n options?: EventHubConsumerClientOptions,\n ); // #2.1\n /**\n * The `EventHubConsumerClient` class is used to consume events from an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param consumerGroup - The name of the consumer group from which you want to process events.\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 consumerGroup: string,\n fullyQualifiedNamespace: string,\n eventHubName: string,\n credential: TokenCredential | NamedKeyCredential | SASCredential,\n options?: EventHubConsumerClientOptions,\n ); // #3\n /**\n * The `EventHubConsumerClient` class is used to consume events from an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param consumerGroup - The name of the consumer group from which you want to process events.\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 checkpointStore - A checkpoint store that is used by the client to read checkpoints to determine\n * the position from where it should resume receiving events when your application gets restarted.\n * It is also used by the client to load balance multiple instances of your application.\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 consumerGroup: string,\n fullyQualifiedNamespace: string,\n eventHubName: string,\n credential: TokenCredential | NamedKeyCredential | SASCredential,\n checkpointStore: CheckpointStore,\n options?: EventHubConsumerClientOptions,\n ); // #3.1\n constructor(\n private _consumerGroup: string,\n connectionStringOrFullyQualifiedNamespace2: string,\n checkpointStoreOrEventHubNameOrOptions3?:\n | CheckpointStore\n | EventHubConsumerClientOptions\n | string,\n checkpointStoreOrCredentialOrOptions4?:\n | CheckpointStore\n | EventHubConsumerClientOptions\n | TokenCredential\n | NamedKeyCredential\n | SASCredential,\n checkpointStoreOrOptions5?: CheckpointStore | EventHubConsumerClientOptions,\n options6?: EventHubConsumerClientOptions,\n ) {\n if (isCredential(checkpointStoreOrCredentialOrOptions4)) {\n // #3 or 3.1\n logger.info(\"Creating EventHubConsumerClient with TokenCredential.\");\n\n if (isCheckpointStore(checkpointStoreOrOptions5)) {\n // 3.1\n this._checkpointStore = checkpointStoreOrOptions5;\n this._userChoseCheckpointStore = true;\n this._clientOptions = options6 || {};\n } else {\n this._checkpointStore = new InMemoryCheckpointStore();\n this._userChoseCheckpointStore = false;\n this._clientOptions = checkpointStoreOrOptions5 || {};\n }\n\n this._context = createConnectionContext(\n connectionStringOrFullyQualifiedNamespace2,\n checkpointStoreOrEventHubNameOrOptions3 as string,\n checkpointStoreOrCredentialOrOptions4,\n this._clientOptions,\n );\n } else if (typeof checkpointStoreOrEventHubNameOrOptions3 === \"string\") {\n // #2 or 2.1\n logger.info(\"Creating EventHubConsumerClient with connection string and event hub name.\");\n\n if (isCheckpointStore(checkpointStoreOrCredentialOrOptions4)) {\n // 2.1\n this._checkpointStore = checkpointStoreOrCredentialOrOptions4;\n this._userChoseCheckpointStore = true;\n this._clientOptions = (checkpointStoreOrOptions5 as EventHubConsumerClientOptions) || {};\n } else {\n // 2\n this._checkpointStore = new InMemoryCheckpointStore();\n this._userChoseCheckpointStore = false;\n this._clientOptions = checkpointStoreOrCredentialOrOptions4 || {};\n }\n\n this._context = createConnectionContext(\n connectionStringOrFullyQualifiedNamespace2,\n checkpointStoreOrEventHubNameOrOptions3,\n this._clientOptions,\n );\n } else {\n // #1 or 1.1\n logger.info(\"Creating EventHubConsumerClient with connection string.\");\n\n if (isCheckpointStore(checkpointStoreOrEventHubNameOrOptions3)) {\n // 1.1\n this._checkpointStore = checkpointStoreOrEventHubNameOrOptions3;\n this._userChoseCheckpointStore = true;\n this._clientOptions =\n (checkpointStoreOrCredentialOrOptions4 as EventHubConsumerClientOptions) || {};\n } else {\n // 1\n this._checkpointStore = new InMemoryCheckpointStore();\n this._userChoseCheckpointStore = false;\n this._clientOptions =\n (checkpointStoreOrEventHubNameOrOptions3 as EventHubConsumerClientOptions) || {};\n }\n\n this._context = createConnectionContext(\n connectionStringOrFullyQualifiedNamespace2,\n this._clientOptions,\n );\n }\n this.identifier = this._clientOptions.identifier ?? getRandomName();\n this._loadBalancingOptions = {\n // default options\n strategy: \"balanced\",\n updateIntervalInMs: 10000,\n partitionOwnershipExpirationIntervalInMs: 60000,\n // options supplied by user\n ...this._clientOptions?.loadBalancingOptions,\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 // Stop all the actively running subscriptions.\n const activeSubscriptions = Array.from(this._subscriptions);\n await Promise.all(\n activeSubscriptions.map((subscription) => {\n return subscription.close();\n }),\n );\n // Close the connection via the connection context.\n return this._context.close();\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 EventHubConsumerClient.\n * @throws AbortError if the operation is cancelled via the abortSignal.\n */\n getPartitionIds(options: GetPartitionIdsOptions = {}): Promise<Array<string>> {\n return this._context\n .managementSession!.getEventHubProperties({\n ...options,\n retryOptions: this._clientOptions.retryOptions,\n })\n .then((eventHubProperties) => {\n return eventHubProperties.partitionIds;\n });\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 EventHubConsumerClient.\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 * 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 EventHubConsumerClient.\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 * Subscribe to events from all partitions.\n *\n * If checkpoint store is provided to the `EventHubConsumerClient` and there are multiple\n * instances of your application, then each instance will subscribe to a subset of the\n * partitions such that the load is balanced amongst them.\n *\n * Call close() on the returned object to stop receiving events.\n *\n * Example usage:\n * ```ts snippet:EventHubConsumerClient_Subscribe\n * import { EventHubConsumerClient, earliestEventPosition } from \"@azure/event-hubs\";\n *\n * const client = new EventHubConsumerClient(\"my-consumer-group\", \"connectionString\", \"eventHubName\");\n *\n * const subscription = client.subscribe(\n * {\n * processEvents: async (events, context) => {\n * console.log(\"Received event count: \", events.length);\n * },\n * processError: async (err, context) => {\n * console.log(\"Error: \", err);\n * },\n * },\n * { startPosition: earliestEventPosition },\n * );\n * ```\n *\n * @param handlers - Handlers for the lifecycle of the subscription - subscription initialization\n * per partition, receiving events, handling errors and the closing\n * of a subscription per partition.\n * @param options - Configures the way events are received.\n * Most common are `maxBatchSize` and `maxWaitTimeInSeconds` that control the flow of\n * events to the handler provided to receive events as well as the start position. For example,\n * `{ maxBatchSize: 20, maxWaitTimeInSeconds: 120, startPosition: { sequenceNumber: 123 } }`\n */\n subscribe(handlers: SubscriptionEventHandlers, options?: SubscribeOptions): Subscription; // #1\n /**\n * Subscribe to events from a single partition.\n * Call close() on the returned object to stop receiving events.\n *\n * Example usage:\n * ```ts snippet:EventHubConsumerClient_SubscribeSinglePartition\n * import { EventHubConsumerClient, earliestEventPosition } from \"@azure/event-hubs\";\n *\n * const client = new EventHubConsumerClient(\"my-consumer-group\", \"connectionString\", \"eventHubName\");\n *\n * const partitionIds = await client.getPartitionIds();\n *\n * const subscription = client.subscribe(\n * partitionIds[0],\n * {\n * processEvents: async (events, context) => {\n * console.log(\"Received event count: \", events.length);\n * },\n * processError: async (err, context) => {\n * console.log(\"Error: \", err);\n * },\n * },\n * { startPosition: earliestEventPosition },\n * );\n * ```\n *\n * @param partitionId - The id of the partition to subscribe to.\n * @param handlers - Handlers for the lifecycle of the subscription - subscription initialization\n * of the partition, receiving events, handling errors and the closing\n * of a subscription to the partition.\n * @param options - Configures the way events are received.\n * Most common are `maxBatchSize` and `maxWaitTimeInSeconds` that control the flow of\n * events to the handler provided to receive events as well as the start position. For example,\n * `{ maxBatchSize: 20, maxWaitTimeInSeconds: 120, startPosition: { sequenceNumber: 123 } }`\n */\n\n subscribe(\n partitionId: string,\n handlers: SubscriptionEventHandlers,\n options?: SubscribeOptions,\n ): Subscription; // #2\n subscribe(\n handlersOrPartitionId1?: SubscriptionEventHandlers | string,\n optionsOrHandlers2?: SubscribeOptions | SubscriptionEventHandlers,\n possibleOptions3?: SubscribeOptions,\n ): Subscription {\n let eventProcessor: EventProcessor;\n let targetedPartitionId: string;\n\n if (isSubscriptionEventHandlers(handlersOrPartitionId1)) {\n // #1: subscribe overload - read from all partitions\n const options = optionsOrHandlers2 as SubscribeOptions | undefined;\n if (options && options.startPosition) {\n validateEventPositions(options.startPosition);\n }\n ({ targetedPartitionId, eventProcessor } = this.createEventProcessorForAllPartitions(\n handlersOrPartitionId1,\n options,\n ));\n } else if (isSubscriptionEventHandlers(optionsOrHandlers2)) {\n // #2: subscribe overload (read from specific partition IDs), don't coordinate\n const options = possibleOptions3 as SubscribeOptions | undefined;\n if (options && options.startPosition) {\n validateEventPositions(options.startPosition);\n }\n ({ targetedPartitionId, eventProcessor } = this.createEventProcessorForSinglePartition(\n // cast to string as downstream code expects partitionId to be string, but JS users could have given us anything.\n // we don't validate the user input and instead rely on service throwing errors if any\n String(handlersOrPartitionId1),\n optionsOrHandlers2,\n possibleOptions3,\n ));\n } else {\n throw new TypeError(\"Unhandled subscribe() overload\");\n }\n\n eventProcessor.start();\n\n const subscription = {\n get isRunning() {\n return eventProcessor.isRunning();\n },\n close: () => {\n this._partitionGate.remove(targetedPartitionId);\n this._subscriptions.delete(subscription);\n return eventProcessor.stop();\n },\n };\n this._subscriptions.add(subscription);\n return subscription;\n }\n\n /**\n * Gets the LoadBalancing strategy that should be used based on what the user provided.\n */\n private _getLoadBalancingStrategy(): LoadBalancingStrategy {\n if (!this._userChoseCheckpointStore) {\n // The default behavior when a checkpointstore isn't provided\n // is to always grab all the partitions.\n return new UnbalancedLoadBalancingStrategy();\n }\n\n const partitionOwnershipExpirationIntervalInMs =\n this._loadBalancingOptions.partitionOwnershipExpirationIntervalInMs;\n if (this._loadBalancingOptions?.strategy === \"greedy\") {\n return new GreedyLoadBalancingStrategy(partitionOwnershipExpirationIntervalInMs);\n }\n\n // The default behavior when a checkpointstore is provided is\n // to grab one partition at a time.\n return new BalancedLoadBalancingStrategy(partitionOwnershipExpirationIntervalInMs);\n }\n\n private createEventProcessorForAllPartitions(\n subscriptionEventHandlers: SubscriptionEventHandlers,\n options?: SubscribeOptions,\n ): { targetedPartitionId: string; eventProcessor: EventProcessor } {\n this._partitionGate.add(\"all\");\n\n if (this._userChoseCheckpointStore) {\n logger.verbose(\n \"EventHubConsumerClient subscribing to all partitions, using a checkpoint store.\",\n );\n } else {\n logger.verbose(\"EventHubConsumerClient subscribing to all partitions, no checkpoint store.\");\n }\n\n const loadBalancingStrategy = this._getLoadBalancingStrategy();\n const eventProcessor = this._createEventProcessor(\n this._context,\n subscriptionEventHandlers,\n this._checkpointStore,\n {\n ...defaultConsumerClientOptions,\n ...(options as SubscribeOptions),\n ownerLevel: getOwnerLevel(options, this._userChoseCheckpointStore),\n // make it so all the event processors process work with the same overarching owner ID\n // this allows the EventHubConsumer to unify all the work for any processors that it spawns\n ownerId: this.identifier,\n retryOptions: this._clientOptions.retryOptions,\n loadBalancingStrategy,\n loopIntervalInMs: this._loadBalancingOptions.updateIntervalInMs,\n },\n );\n\n return { targetedPartitionId: \"all\", eventProcessor };\n }\n\n private createEventProcessorForSinglePartition(\n partitionId: string,\n eventHandlers: SubscriptionEventHandlers,\n options?: SubscribeOptions,\n ): { targetedPartitionId: string; eventProcessor: EventProcessor } {\n this._partitionGate.add(partitionId);\n\n const subscribeOptions = options as SubscribeOptions | undefined;\n\n if (this._userChoseCheckpointStore) {\n logger.verbose(\n `EventHubConsumerClient subscribing to specific partition (${partitionId}), using a checkpoint store.`,\n );\n } else {\n logger.verbose(\n `EventHubConsumerClient subscribing to specific partition (${partitionId}), no checkpoint store.`,\n );\n }\n\n const eventProcessor = this._createEventProcessor(\n this._context,\n eventHandlers,\n this._checkpointStore,\n {\n ...defaultConsumerClientOptions,\n ...options,\n processingTarget: partitionId,\n ownerLevel: getOwnerLevel(subscribeOptions, this._userChoseCheckpointStore),\n retryOptions: this._clientOptions.retryOptions,\n loadBalancingStrategy: new UnbalancedLoadBalancingStrategy(),\n loopIntervalInMs: this._loadBalancingOptions.updateIntervalInMs ?? 10000,\n },\n );\n\n return { targetedPartitionId: partitionId, eventProcessor };\n }\n\n private _createEventProcessor(\n connectionContext: ConnectionContext,\n subscriptionEventHandlers: SubscriptionEventHandlers,\n checkpointStore: CheckpointStore,\n options: FullEventProcessorOptions,\n ): EventProcessor {\n return new EventProcessor(\n this._consumerGroup,\n connectionContext,\n subscriptionEventHandlers,\n checkpointStore,\n options,\n );\n }\n}\n\n/**\n * @internal\n */\nexport function isCheckpointStore(possible: CheckpointStore | any): possible is CheckpointStore {\n if (!possible) {\n return false;\n }\n\n const checkpointStore = possible as CheckpointStore;\n\n return (\n typeof checkpointStore.claimOwnership === \"function\" &&\n typeof checkpointStore.listCheckpoints === \"function\" &&\n typeof checkpointStore.listOwnership === \"function\" &&\n typeof checkpointStore.updateCheckpoint === \"function\"\n );\n}\n\n/**\n * @internal\n */\nfunction isSubscriptionEventHandlers(\n possible: any | SubscriptionEventHandlers,\n): possible is SubscriptionEventHandlers {\n return typeof (possible as SubscriptionEventHandlers).processEvents === \"function\";\n}\n\nfunction getOwnerLevel(\n options: SubscribeOptions | undefined,\n userChoseCheckpointStore: boolean,\n): number | undefined {\n if (options && options.ownerLevel) {\n return options.ownerLevel;\n }\n\n if (userChoseCheckpointStore) {\n return 0;\n } else {\n return undefined;\n }\n}\n"]}
1
+ {"version":3,"file":"eventHubConsumerClient.js","sourceRoot":"","sources":["../../src/eventHubConsumerClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAejE,OAAO,EAAE,6BAA6B,EAAE,MAAM,8CAA8C,CAAC;AAC7F,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,2BAA2B,EAAE,MAAM,4CAA4C,CAAC;AACzF,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,+BAA+B,EAAE,MAAM,gDAAgD,CAAC;AACjG,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD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IAAI,wBAAwB,EAAE,CAAC;QAC7B,OAAO,CAAC,CAAC;IACX,CAAC;SAAM,CAAC;QACN,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { CheckpointStore, FullEventProcessorOptions } from \"./eventProcessor.js\";\nimport { EventProcessor } from \"./eventProcessor.js\";\nimport type { ConnectionContext } from \"./connectionContext.js\";\nimport { createConnectionContext } from \"./connectionContext.js\";\nimport type {\n EventHubConsumerClientOptions,\n GetEventHubPropertiesOptions,\n GetPartitionIdsOptions,\n GetPartitionPropertiesOptions,\n LoadBalancingOptions,\n} from \"./models/public.js\";\nimport type { EventHubProperties, PartitionProperties } from \"./managementClient.js\";\nimport type { NamedKeyCredential, SASCredential, TokenCredential } from \"@azure/core-auth\";\nimport type {\n SubscribeOptions,\n Subscription,\n SubscriptionEventHandlers,\n} from \"./eventHubConsumerClientModels.js\";\nimport { BalancedLoadBalancingStrategy } from \"./loadBalancerStrategies/balancedStrategy.js\";\nimport { Constants } from \"@azure/core-amqp\";\nimport { GreedyLoadBalancingStrategy } from \"./loadBalancerStrategies/greedyStrategy.js\";\nimport { InMemoryCheckpointStore } from \"./inMemoryCheckpointStore.js\";\nimport type { LoadBalancingStrategy } from \"./loadBalancerStrategies/loadBalancingStrategy.js\";\nimport { PartitionGate } from \"./impl/partitionGate.js\";\nimport { UnbalancedLoadBalancingStrategy } from \"./loadBalancerStrategies/unbalancedStrategy.js\";\nimport { isCredential } from \"./util/typeGuards.js\";\nimport { logger } from \"./logger.js\";\nimport { validateEventPositions } from \"./eventPosition.js\";\nimport { getRandomName } from \"./util/utils.js\";\n\nconst defaultConsumerClientOptions: Required<\n Pick<FullEventProcessorOptions, \"maxWaitTimeInSeconds\" | \"maxBatchSize\">\n> = {\n // to support our current \"process single event only\" workflow we'll also purposefully\n // only request a single event at a time.\n maxBatchSize: 1,\n maxWaitTimeInSeconds: 60,\n};\n\n/**\n * The `EventHubConsumerClient` class is used to consume events from an Event Hub.\n *\n * There are multiple ways to create an `EventHubConsumerClient`\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:\n * - An options bag to configure the retry policy or proxy settings.\n * - A checkpoint store that is used by the client to read checkpoints to determine the position from where it should\n * resume receiving events when your application gets restarted. The checkpoint store is also used by the client\n * to load balance multiple instances of your application.\n */\nexport class EventHubConsumerClient {\n /**\n * Describes the amqp connection context for the client.\n */\n private _context: ConnectionContext;\n /**\n * The options passed by the user when creating the EventHubClient instance.\n */\n private _clientOptions: EventHubConsumerClientOptions;\n private _partitionGate = new PartitionGate();\n\n /**\n * The Subscriptions that were spawned by calling `subscribe()`.\n * Subscriptions that have been stopped by the user will not\n * be present in this set.\n */\n private _subscriptions = new Set<Subscription>();\n\n /**\n * The name of the default consumer group in the Event Hubs service.\n */\n static defaultConsumerGroupName: string = Constants.defaultConsumerGroup;\n\n private _checkpointStore: CheckpointStore;\n private _userChoseCheckpointStore: boolean;\n\n /**\n * Options for configuring load balancing.\n */\n private readonly _loadBalancingOptions: Required<LoadBalancingOptions>;\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._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 EventHubConsumerClient.\n * If not specified or empty, a random unique one will be generated.\n */\n public readonly identifier: string;\n\n /**\n * The `EventHubConsumerClient` class is used to consume events from an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param consumerGroup - The name of the consumer group from which you want to process events.\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(\n consumerGroup: string,\n connectionString: string,\n options?: EventHubConsumerClientOptions,\n ); // #1\n /**\n * The `EventHubConsumerClient` class is used to consume events from an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param consumerGroup - The name of the consumer group from which you want to process events.\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 checkpointStore - A checkpoint store that is used by the client to read checkpoints to determine\n * the position from where it should resume receiving events when your application gets restarted.\n * It is also used by the client to load balance multiple instances of your application.\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 consumerGroup: string,\n connectionString: string,\n checkpointStore: CheckpointStore,\n options?: EventHubConsumerClientOptions,\n ); // #1.1\n /**\n * The `EventHubConsumerClient` class is used to consume events from an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param consumerGroup - The name of the consumer group from which you want to process events.\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 consumerGroup: string,\n connectionString: string,\n eventHubName: string,\n options?: EventHubConsumerClientOptions,\n ); // #2\n /**\n * The `EventHubConsumerClient` class is used to consume events from an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param consumerGroup - The name of the consumer group from which you want to process events.\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 checkpointStore - A checkpoint store that is used by the client to read checkpoints to determine\n * the position from where it should resume receiving events when your application gets restarted.\n * It is also used by the client to load balance multiple instances of your application.\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 consumerGroup: string,\n connectionString: string,\n eventHubName: string,\n checkpointStore: CheckpointStore,\n options?: EventHubConsumerClientOptions,\n ); // #2.1\n /**\n * The `EventHubConsumerClient` class is used to consume events from an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param consumerGroup - The name of the consumer group from which you want to process events.\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 consumerGroup: string,\n fullyQualifiedNamespace: string,\n eventHubName: string,\n credential: TokenCredential | NamedKeyCredential | SASCredential,\n options?: EventHubConsumerClientOptions,\n ); // #3\n /**\n * The `EventHubConsumerClient` class is used to consume events from an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param consumerGroup - The name of the consumer group from which you want to process events.\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 checkpointStore - A checkpoint store that is used by the client to read checkpoints to determine\n * the position from where it should resume receiving events when your application gets restarted.\n * It is also used by the client to load balance multiple instances of your application.\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 consumerGroup: string,\n fullyQualifiedNamespace: string,\n eventHubName: string,\n credential: TokenCredential | NamedKeyCredential | SASCredential,\n checkpointStore: CheckpointStore,\n options?: EventHubConsumerClientOptions,\n ); // #3.1\n constructor(\n private _consumerGroup: string,\n connectionStringOrFullyQualifiedNamespace2: string,\n checkpointStoreOrEventHubNameOrOptions3?:\n | CheckpointStore\n | EventHubConsumerClientOptions\n | string,\n checkpointStoreOrCredentialOrOptions4?:\n | CheckpointStore\n | EventHubConsumerClientOptions\n | TokenCredential\n | NamedKeyCredential\n | SASCredential,\n checkpointStoreOrOptions5?: CheckpointStore | EventHubConsumerClientOptions,\n options6?: EventHubConsumerClientOptions,\n ) {\n if (isCredential(checkpointStoreOrCredentialOrOptions4)) {\n // #3 or 3.1\n logger.info(\"Creating EventHubConsumerClient with TokenCredential.\");\n\n if (isCheckpointStore(checkpointStoreOrOptions5)) {\n // 3.1\n this._checkpointStore = checkpointStoreOrOptions5;\n this._userChoseCheckpointStore = true;\n this._clientOptions = options6 || {};\n } else {\n this._checkpointStore = new InMemoryCheckpointStore();\n this._userChoseCheckpointStore = false;\n this._clientOptions = checkpointStoreOrOptions5 || {};\n }\n\n this._context = createConnectionContext(\n connectionStringOrFullyQualifiedNamespace2,\n checkpointStoreOrEventHubNameOrOptions3 as string,\n checkpointStoreOrCredentialOrOptions4,\n this._clientOptions,\n );\n } else if (typeof checkpointStoreOrEventHubNameOrOptions3 === \"string\") {\n // #2 or 2.1\n logger.info(\"Creating EventHubConsumerClient with connection string and event hub name.\");\n\n if (isCheckpointStore(checkpointStoreOrCredentialOrOptions4)) {\n // 2.1\n this._checkpointStore = checkpointStoreOrCredentialOrOptions4;\n this._userChoseCheckpointStore = true;\n this._clientOptions = (checkpointStoreOrOptions5 as EventHubConsumerClientOptions) || {};\n } else {\n // 2\n this._checkpointStore = new InMemoryCheckpointStore();\n this._userChoseCheckpointStore = false;\n this._clientOptions = checkpointStoreOrCredentialOrOptions4 || {};\n }\n\n this._context = createConnectionContext(\n connectionStringOrFullyQualifiedNamespace2,\n checkpointStoreOrEventHubNameOrOptions3,\n this._clientOptions,\n );\n } else {\n // #1 or 1.1\n logger.info(\"Creating EventHubConsumerClient with connection string.\");\n\n if (isCheckpointStore(checkpointStoreOrEventHubNameOrOptions3)) {\n // 1.1\n this._checkpointStore = checkpointStoreOrEventHubNameOrOptions3;\n this._userChoseCheckpointStore = true;\n this._clientOptions =\n (checkpointStoreOrCredentialOrOptions4 as EventHubConsumerClientOptions) || {};\n } else {\n // 1\n this._checkpointStore = new InMemoryCheckpointStore();\n this._userChoseCheckpointStore = false;\n this._clientOptions =\n (checkpointStoreOrEventHubNameOrOptions3 as EventHubConsumerClientOptions) || {};\n }\n\n this._context = createConnectionContext(\n connectionStringOrFullyQualifiedNamespace2,\n this._clientOptions,\n );\n }\n this.identifier = this._clientOptions.identifier ?? getRandomName();\n this._loadBalancingOptions = {\n // default options\n strategy: \"balanced\",\n updateIntervalInMs: 10000,\n partitionOwnershipExpirationIntervalInMs: 60000,\n // options supplied by user\n ...this._clientOptions?.loadBalancingOptions,\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 // Stop all the actively running subscriptions.\n const activeSubscriptions = Array.from(this._subscriptions);\n await Promise.all(\n activeSubscriptions.map((subscription) => {\n return subscription.close();\n }),\n );\n // Close the connection via the connection context.\n return this._context.close();\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 EventHubConsumerClient.\n * @throws AbortError if the operation is cancelled via the abortSignal.\n */\n getPartitionIds(options: GetPartitionIdsOptions = {}): Promise<Array<string>> {\n return this._context\n .managementSession!.getEventHubProperties({\n ...options,\n retryOptions: this._clientOptions.retryOptions,\n })\n .then((eventHubProperties) => {\n return eventHubProperties.partitionIds;\n });\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 EventHubConsumerClient.\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 * 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 EventHubConsumerClient.\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 * Subscribe to events from all partitions.\n *\n * If checkpoint store is provided to the `EventHubConsumerClient` and there are multiple\n * instances of your application, then each instance will subscribe to a subset of the\n * partitions such that the load is balanced amongst them.\n *\n * Call close() on the returned object to stop receiving events.\n *\n * Example usage:\n * ```ts snippet:EventHubConsumerClient_Subscribe\n * import { EventHubConsumerClient, earliestEventPosition } from \"@azure/event-hubs\";\n *\n * const client = new EventHubConsumerClient(\"my-consumer-group\", \"connectionString\", \"eventHubName\");\n *\n * const subscription = client.subscribe(\n * {\n * processEvents: async (events, context) => {\n * console.log(\"Received event count: \", events.length);\n * },\n * processError: async (err, context) => {\n * console.log(\"Error: \", err);\n * },\n * },\n * { startPosition: earliestEventPosition },\n * );\n * ```\n *\n * @param handlers - Handlers for the lifecycle of the subscription - subscription initialization\n * per partition, receiving events, handling errors and the closing\n * of a subscription per partition.\n * @param options - Configures the way events are received.\n * Most common are `maxBatchSize` and `maxWaitTimeInSeconds` that control the flow of\n * events to the handler provided to receive events as well as the start position. For example,\n * `{ maxBatchSize: 20, maxWaitTimeInSeconds: 120, startPosition: { sequenceNumber: 123 } }`\n */\n subscribe(handlers: SubscriptionEventHandlers, options?: SubscribeOptions): Subscription; // #1\n /**\n * Subscribe to events from a single partition.\n * Call close() on the returned object to stop receiving events.\n *\n * Example usage:\n * ```ts snippet:EventHubConsumerClient_SubscribeSinglePartition\n * import { EventHubConsumerClient, earliestEventPosition } from \"@azure/event-hubs\";\n *\n * const client = new EventHubConsumerClient(\"my-consumer-group\", \"connectionString\", \"eventHubName\");\n *\n * const partitionIds = await client.getPartitionIds();\n *\n * const subscription = client.subscribe(\n * partitionIds[0],\n * {\n * processEvents: async (events, context) => {\n * console.log(\"Received event count: \", events.length);\n * },\n * processError: async (err, context) => {\n * console.log(\"Error: \", err);\n * },\n * },\n * { startPosition: earliestEventPosition },\n * );\n * ```\n *\n * @param partitionId - The id of the partition to subscribe to.\n * @param handlers - Handlers for the lifecycle of the subscription - subscription initialization\n * of the partition, receiving events, handling errors and the closing\n * of a subscription to the partition.\n * @param options - Configures the way events are received.\n * Most common are `maxBatchSize` and `maxWaitTimeInSeconds` that control the flow of\n * events to the handler provided to receive events as well as the start position. For example,\n * `{ maxBatchSize: 20, maxWaitTimeInSeconds: 120, startPosition: { sequenceNumber: 123 } }`\n */\n\n subscribe(\n partitionId: string,\n handlers: SubscriptionEventHandlers,\n options?: SubscribeOptions,\n ): Subscription; // #2\n subscribe(\n handlersOrPartitionId1?: SubscriptionEventHandlers | string,\n optionsOrHandlers2?: SubscribeOptions | SubscriptionEventHandlers,\n possibleOptions3?: SubscribeOptions,\n ): Subscription {\n let eventProcessor: EventProcessor;\n let targetedPartitionId: string;\n\n if (isSubscriptionEventHandlers(handlersOrPartitionId1)) {\n // #1: subscribe overload - read from all partitions\n const options = optionsOrHandlers2 as SubscribeOptions | undefined;\n if (options && options.startPosition) {\n validateEventPositions(options.startPosition);\n }\n ({ targetedPartitionId, eventProcessor } = this.createEventProcessorForAllPartitions(\n handlersOrPartitionId1,\n options,\n ));\n } else if (isSubscriptionEventHandlers(optionsOrHandlers2)) {\n // #2: subscribe overload (read from specific partition IDs), don't coordinate\n const options = possibleOptions3 as SubscribeOptions | undefined;\n if (options && options.startPosition) {\n validateEventPositions(options.startPosition);\n }\n ({ targetedPartitionId, eventProcessor } = this.createEventProcessorForSinglePartition(\n // cast to string as downstream code expects partitionId to be string, but JS users could have given us anything.\n // we don't validate the user input and instead rely on service throwing errors if any\n String(handlersOrPartitionId1),\n optionsOrHandlers2,\n possibleOptions3,\n ));\n } else {\n throw new TypeError(\"Unhandled subscribe() overload\");\n }\n\n eventProcessor.start();\n\n const subscription = {\n get isRunning() {\n return eventProcessor.isRunning();\n },\n close: () => {\n this._partitionGate.remove(targetedPartitionId);\n this._subscriptions.delete(subscription);\n return eventProcessor.stop();\n },\n };\n this._subscriptions.add(subscription);\n return subscription;\n }\n\n /**\n * Gets the LoadBalancing strategy that should be used based on what the user provided.\n */\n private _getLoadBalancingStrategy(): LoadBalancingStrategy {\n if (!this._userChoseCheckpointStore) {\n // The default behavior when a checkpointstore isn't provided\n // is to always grab all the partitions.\n return new UnbalancedLoadBalancingStrategy();\n }\n\n const partitionOwnershipExpirationIntervalInMs =\n this._loadBalancingOptions.partitionOwnershipExpirationIntervalInMs;\n if (this._loadBalancingOptions?.strategy === \"greedy\") {\n return new GreedyLoadBalancingStrategy(partitionOwnershipExpirationIntervalInMs);\n }\n\n // The default behavior when a checkpointstore is provided is\n // to grab one partition at a time.\n return new BalancedLoadBalancingStrategy(partitionOwnershipExpirationIntervalInMs);\n }\n\n private createEventProcessorForAllPartitions(\n subscriptionEventHandlers: SubscriptionEventHandlers,\n options?: SubscribeOptions,\n ): { targetedPartitionId: string; eventProcessor: EventProcessor } {\n this._partitionGate.add(\"all\");\n\n if (this._userChoseCheckpointStore) {\n logger.verbose(\n \"EventHubConsumerClient subscribing to all partitions, using a checkpoint store.\",\n );\n } else {\n logger.verbose(\"EventHubConsumerClient subscribing to all partitions, no checkpoint store.\");\n }\n\n const loadBalancingStrategy = this._getLoadBalancingStrategy();\n const eventProcessor = this._createEventProcessor(\n this._context,\n subscriptionEventHandlers,\n this._checkpointStore,\n {\n ...defaultConsumerClientOptions,\n ...(options as SubscribeOptions),\n ownerLevel: getOwnerLevel(options, this._userChoseCheckpointStore),\n // make it so all the event processors process work with the same overarching owner ID\n // this allows the EventHubConsumer to unify all the work for any processors that it spawns\n ownerId: this.identifier,\n retryOptions: this._clientOptions.retryOptions,\n loadBalancingStrategy,\n loopIntervalInMs: this._loadBalancingOptions.updateIntervalInMs,\n },\n );\n\n return { targetedPartitionId: \"all\", eventProcessor };\n }\n\n private createEventProcessorForSinglePartition(\n partitionId: string,\n eventHandlers: SubscriptionEventHandlers,\n options?: SubscribeOptions,\n ): { targetedPartitionId: string; eventProcessor: EventProcessor } {\n this._partitionGate.add(partitionId);\n\n const subscribeOptions = options as SubscribeOptions | undefined;\n\n if (this._userChoseCheckpointStore) {\n logger.verbose(\n `EventHubConsumerClient subscribing to specific partition (${partitionId}), using a checkpoint store.`,\n );\n } else {\n logger.verbose(\n `EventHubConsumerClient subscribing to specific partition (${partitionId}), no checkpoint store.`,\n );\n }\n\n const eventProcessor = this._createEventProcessor(\n this._context,\n eventHandlers,\n this._checkpointStore,\n {\n ...defaultConsumerClientOptions,\n ...options,\n processingTarget: partitionId,\n ownerLevel: getOwnerLevel(subscribeOptions, this._userChoseCheckpointStore),\n retryOptions: this._clientOptions.retryOptions,\n loadBalancingStrategy: new UnbalancedLoadBalancingStrategy(),\n loopIntervalInMs: this._loadBalancingOptions.updateIntervalInMs ?? 10000,\n },\n );\n\n return { targetedPartitionId: partitionId, eventProcessor };\n }\n\n private _createEventProcessor(\n connectionContext: ConnectionContext,\n subscriptionEventHandlers: SubscriptionEventHandlers,\n checkpointStore: CheckpointStore,\n options: FullEventProcessorOptions,\n ): EventProcessor {\n return new EventProcessor(\n this._consumerGroup,\n connectionContext,\n subscriptionEventHandlers,\n checkpointStore,\n options,\n );\n }\n}\n\n/**\n * @internal\n */\nexport function isCheckpointStore(possible: CheckpointStore | any): possible is CheckpointStore {\n if (!possible) {\n return false;\n }\n\n const checkpointStore = possible as CheckpointStore;\n\n return (\n typeof checkpointStore.claimOwnership === \"function\" &&\n typeof checkpointStore.listCheckpoints === \"function\" &&\n typeof checkpointStore.listOwnership === \"function\" &&\n typeof checkpointStore.updateCheckpoint === \"function\"\n );\n}\n\n/**\n * @internal\n */\nfunction isSubscriptionEventHandlers(\n possible: any | SubscriptionEventHandlers,\n): possible is SubscriptionEventHandlers {\n return typeof (possible as SubscriptionEventHandlers).processEvents === \"function\";\n}\n\nfunction getOwnerLevel(\n options: SubscribeOptions | undefined,\n userChoseCheckpointStore: boolean,\n): number | undefined {\n if (options && options.ownerLevel) {\n return options.ownerLevel;\n }\n\n if (userChoseCheckpointStore) {\n return 0;\n } else {\n return undefined;\n }\n}\n"]}
@@ -24,6 +24,32 @@ import { getRandomName } from "./util/utils.js";
24
24
  *
25
25
  */
26
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;
27
53
  /**
28
54
  * @readonly
29
55
  * The name of the Event Hub instance for which this client is created.
@@ -39,8 +65,12 @@ export class EventHubProducerClient {
39
65
  get fullyQualifiedNamespace() {
40
66
  return this._context.config.host;
41
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;
42
73
  constructor(fullyQualifiedNamespaceOrConnectionString1, eventHubNameOrOptions2, credentialOrOptions3, options4) {
43
- var _a;
44
74
  this._context = createConnectionContext(fullyQualifiedNamespaceOrConnectionString1, eventHubNameOrOptions2, credentialOrOptions3, options4);
45
75
  if (typeof eventHubNameOrOptions2 !== "string") {
46
76
  this._clientOptions = eventHubNameOrOptions2 || {};
@@ -51,7 +81,7 @@ export class EventHubProducerClient {
51
81
  else {
52
82
  this._clientOptions = options4 || {};
53
83
  }
54
- this.identifier = (_a = this._clientOptions.identifier) !== null && _a !== void 0 ? _a : getRandomName();
84
+ this.identifier = this._clientOptions.identifier ?? getRandomName();
55
85
  this._sendersMap = new Map();
56
86
  }
57
87
  /**
@@ -107,7 +137,6 @@ export class EventHubProducerClient {
107
137
  * @throws AbortError if the operation is cancelled via the abortSignal in the options.
108
138
  */
109
139
  async createBatch(options = {}) {
110
- var _a;
111
140
  throwErrorIfConnectionClosed(this._context);
112
141
  const partitionId = isDefined(options.partitionId) ? String(options.partitionId) : undefined;
113
142
  validateProducerPartitionSettings({
@@ -118,7 +147,7 @@ export class EventHubProducerClient {
118
147
  let sender = this._sendersMap.get(partitionId || "");
119
148
  if (!sender) {
120
149
  const partitionPublishingOptions = isDefined(partitionId)
121
- ? (_a = this._partitionOptions) === null || _a === void 0 ? void 0 : _a[partitionId]
150
+ ? this._partitionOptions?.[partitionId]
122
151
  : undefined;
123
152
  sender = EventHubSender.create(this._context, this.identifier, {
124
153
  enableIdempotentProducer: Boolean(this._enableIdempotentRetries),
@@ -156,7 +185,6 @@ export class EventHubProducerClient {
156
185
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
157
186
  // @ts-ignore this is called in EventHubBufferedProducerClient via cast-to-any workaround
158
187
  async getPartitionPublishingProperties(partitionId, options = {}) {
159
- var _a;
160
188
  if (!isDefined(partitionId)) {
161
189
  throw new TypeError(`getPartitionPublishingProperties called without required argument "partitionId"`);
162
190
  }
@@ -168,7 +196,7 @@ export class EventHubProducerClient {
168
196
  sender = EventHubSender.create(this._context, this.identifier, {
169
197
  enableIdempotentProducer: Boolean(this._enableIdempotentRetries),
170
198
  partitionId,
171
- partitionPublishingOptions: (_a = this._partitionOptions) === null || _a === void 0 ? void 0 : _a[partitionId],
199
+ partitionPublishingOptions: this._partitionOptions?.[partitionId],
172
200
  });
173
201
  this._sendersMap.set(partitionId, sender);
174
202
  }
@@ -218,11 +246,10 @@ export class EventHubProducerClient {
218
246
  partitionKey,
219
247
  });
220
248
  return tracingClient.withSpan(`${EventHubProducerClient.name}.${this.sendBatch.name}`, options, (updatedOptions) => {
221
- var _a;
222
249
  let sender = this._sendersMap.get(partitionId || "");
223
250
  if (!sender) {
224
251
  const partitionPublishingOptions = isDefined(partitionId)
225
- ? (_a = this._partitionOptions) === null || _a === void 0 ? void 0 : _a[partitionId]
252
+ ? this._partitionOptions?.[partitionId]
226
253
  : undefined;
227
254
  sender = EventHubSender.create(this._context, this.identifier, {
228
255
  enableIdempotentProducer: Boolean(this._enableIdempotentRetries),
@@ -231,11 +258,18 @@ export class EventHubProducerClient {
231
258
  });
232
259
  this._sendersMap.set(partitionId || "", sender);
233
260
  }
234
- return sender.send(batch, Object.assign(Object.assign({}, updatedOptions), { partitionId,
235
- partitionKey, retryOptions: this._clientOptions.retryOptions }));
236
- }, Object.assign({ spanLinks: spanContextsToLink.map((tracingContext) => {
261
+ return sender.send(batch, {
262
+ ...updatedOptions,
263
+ partitionId,
264
+ partitionKey,
265
+ retryOptions: this._clientOptions.retryOptions,
266
+ });
267
+ }, {
268
+ spanLinks: spanContextsToLink.map((tracingContext) => {
237
269
  return { tracingContext };
238
- }) }, toSpanOptions(this._context.config, "publish", "client")));
270
+ }),
271
+ ...toSpanOptions(this._context.config, "publish", "client"),
272
+ });
239
273
  }
240
274
  /**
241
275
  * Closes the AMQP connection to the Event Hub instance,
@@ -258,7 +292,10 @@ export class EventHubProducerClient {
258
292
  * @throws AbortError if the operation is cancelled via the abortSignal.
259
293
  */
260
294
  getEventHubProperties(options = {}) {
261
- return this._context.managementSession.getEventHubProperties(Object.assign(Object.assign({}, options), { retryOptions: this._clientOptions.retryOptions }));
295
+ return this._context.managementSession.getEventHubProperties({
296
+ ...options,
297
+ retryOptions: this._clientOptions.retryOptions,
298
+ });
262
299
  }
263
300
  /**
264
301
  * Provides the id for each partition associated with the Event Hub.
@@ -270,7 +307,10 @@ export class EventHubProducerClient {
270
307
  */
271
308
  getPartitionIds(options = {}) {
272
309
  return this._context
273
- .managementSession.getEventHubProperties(Object.assign(Object.assign({}, options), { retryOptions: this._clientOptions.retryOptions }))
310
+ .managementSession.getEventHubProperties({
311
+ ...options,
312
+ retryOptions: this._clientOptions.retryOptions,
313
+ })
274
314
  .then((eventHubProperties) => {
275
315
  return eventHubProperties.partitionIds;
276
316
  });
@@ -284,7 +324,10 @@ export class EventHubProducerClient {
284
324
  * @throws AbortError if the operation is cancelled via the abortSignal.
285
325
  */
286
326
  getPartitionProperties(partitionId, options = {}) {
287
- return this._context.managementSession.getPartitionProperties(partitionId, Object.assign(Object.assign({}, options), { retryOptions: this._clientOptions.retryOptions }));
327
+ return this._context.managementSession.getPartitionProperties(partitionId, {
328
+ ...options,
329
+ retryOptions: this._clientOptions.retryOptions,
330
+ });
288
331
  }
289
332
  }
290
333
  /**
@@ -1 +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,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAI3E,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EACL,0BAA0B,EAC1B,8BAA8B,EAC9B,4BAA4B,EAC5B,gCAAgC,EAChC,iCAAiC,GAClC,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,sBAAsB;IA4BjC;;;OAGG;IACH,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC;IACzC,CAAC;IAED;;;;OAIG;IACH,IAAI,uBAAuB;QACzB,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC;IACn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// 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 getPartitionIds(options: GetPartitionIdsOptions = {}): Promise<Array<string>> {\n return this._context\n .managementSession!.getEventHubProperties({\n ...options,\n retryOptions: this._clientOptions.retryOptions,\n })\n .then((eventHubProperties) => {\n return eventHubProperties.partitionIds;\n });\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"]}
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,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAI3E,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EACL,0BAA0B,EAC1B,8BAA8B,EAC9B,4BAA4B,EAC5B,gCAAgC,EAChC,iCAAiC,GAClC,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,sBAAsB;IACjC;;OAEG;IACK,QAAQ,CAAoB;IAEpC;;OAEG;IACK,cAAc,CAAwB;IAC9C;;OAEG;IACK,WAAW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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 getPartitionIds(options: GetPartitionIdsOptions = {}): Promise<Array<string>> {\n return this._context\n .managementSession!.getEventHubProperties({\n ...options,\n retryOptions: this._clientOptions.retryOptions,\n })\n .then((eventHubProperties) => {\n return eventHubProperties.partitionIds;\n });\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"]}