@azure/event-hubs 5.13.0-alpha.20241022.1 → 5.13.0-alpha.20241115.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.
- package/dist/browser/batchingPartitionChannel.d.ts +3 -3
- package/dist/browser/batchingPartitionChannel.d.ts.map +1 -1
- package/dist/browser/batchingPartitionChannel.js.map +1 -1
- package/dist/browser/connectionContext.d.ts +8 -7
- package/dist/browser/connectionContext.d.ts.map +1 -1
- package/dist/browser/connectionContext.js +2 -4
- package/dist/browser/connectionContext.js.map +1 -1
- package/dist/browser/diagnostics/instrumentEventData.d.ts +5 -5
- package/dist/browser/diagnostics/instrumentEventData.d.ts.map +1 -1
- package/dist/browser/diagnostics/instrumentEventData.js.map +1 -1
- package/dist/browser/diagnostics/tracing.d.ts +2 -2
- package/dist/browser/diagnostics/tracing.d.ts.map +1 -1
- package/dist/browser/diagnostics/tracing.js.map +1 -1
- package/dist/browser/eventData.d.ts +2 -2
- package/dist/browser/eventData.d.ts.map +1 -1
- package/dist/browser/eventData.js +2 -2
- package/dist/browser/eventData.js.map +1 -1
- package/dist/browser/eventDataAdapter.d.ts +1 -1
- package/dist/browser/eventDataAdapter.d.ts.map +1 -1
- package/dist/browser/eventDataAdapter.js.map +1 -1
- package/dist/browser/eventDataBatch.d.ts +5 -5
- package/dist/browser/eventDataBatch.d.ts.map +1 -1
- package/dist/browser/eventDataBatch.js.map +1 -1
- package/dist/browser/eventHubBufferedProducerClient.d.ts +6 -6
- package/dist/browser/eventHubBufferedProducerClient.d.ts.map +1 -1
- package/dist/browser/eventHubBufferedProducerClient.js.map +1 -1
- package/dist/browser/eventHubConsumerClient.d.ts +5 -5
- package/dist/browser/eventHubConsumerClient.d.ts.map +1 -1
- package/dist/browser/eventHubConsumerClient.js.map +1 -1
- package/dist/browser/eventHubConsumerClientModels.d.ts +6 -6
- package/dist/browser/eventHubConsumerClientModels.d.ts.map +1 -1
- package/dist/browser/eventHubConsumerClientModels.js.map +1 -1
- package/dist/browser/eventHubProducerClient.d.ts +7 -7
- package/dist/browser/eventHubProducerClient.d.ts.map +1 -1
- package/dist/browser/eventHubProducerClient.js.map +1 -1
- package/dist/browser/eventHubSender.d.ts +8 -8
- package/dist/browser/eventHubSender.d.ts.map +1 -1
- package/dist/browser/eventHubSender.js +3 -3
- package/dist/browser/eventHubSender.js.map +1 -1
- package/dist/browser/eventProcessor.d.ts +6 -6
- package/dist/browser/eventProcessor.d.ts.map +1 -1
- package/dist/browser/eventProcessor.js.map +1 -1
- package/dist/browser/impl/awaitableQueue.d.ts +1 -1
- package/dist/browser/impl/awaitableQueue.d.ts.map +1 -1
- package/dist/browser/impl/awaitableQueue.js.map +1 -1
- package/dist/browser/inMemoryCheckpointStore.d.ts +2 -2
- package/dist/browser/inMemoryCheckpointStore.d.ts.map +1 -1
- package/dist/browser/inMemoryCheckpointStore.js.map +1 -1
- package/dist/browser/loadBalancerStrategies/balancedStrategy.d.ts +2 -2
- package/dist/browser/loadBalancerStrategies/balancedStrategy.d.ts.map +1 -1
- package/dist/browser/loadBalancerStrategies/balancedStrategy.js.map +1 -1
- package/dist/browser/loadBalancerStrategies/greedyStrategy.d.ts +2 -2
- package/dist/browser/loadBalancerStrategies/greedyStrategy.d.ts.map +1 -1
- package/dist/browser/loadBalancerStrategies/greedyStrategy.js.map +1 -1
- package/dist/browser/loadBalancerStrategies/loadBalancingStrategy.d.ts +1 -1
- package/dist/browser/loadBalancerStrategies/loadBalancingStrategy.d.ts.map +1 -1
- package/dist/browser/loadBalancerStrategies/loadBalancingStrategy.js.map +1 -1
- package/dist/browser/loadBalancerStrategies/unbalancedStrategy.d.ts +2 -2
- package/dist/browser/loadBalancerStrategies/unbalancedStrategy.d.ts.map +1 -1
- package/dist/browser/loadBalancerStrategies/unbalancedStrategy.js.map +1 -1
- package/dist/browser/logger.d.ts +1 -1
- package/dist/browser/logger.d.ts.map +1 -1
- package/dist/browser/logger.js.map +1 -1
- package/dist/browser/managementClient.d.ts +4 -4
- package/dist/browser/managementClient.d.ts.map +1 -1
- package/dist/browser/managementClient.js +1 -1
- package/dist/browser/managementClient.js.map +1 -1
- package/dist/browser/models/private.d.ts +5 -5
- package/dist/browser/models/private.d.ts.map +1 -1
- package/dist/browser/models/private.js +1 -1
- package/dist/browser/models/private.js.map +1 -1
- package/dist/browser/models/public.d.ts +2 -2
- package/dist/browser/models/public.d.ts.map +1 -1
- package/dist/browser/models/public.js.map +1 -1
- package/dist/browser/partitionProcessor.d.ts +5 -5
- package/dist/browser/partitionProcessor.d.ts.map +1 -1
- package/dist/browser/partitionProcessor.js.map +1 -1
- package/dist/browser/partitionPump.d.ts +7 -7
- package/dist/browser/partitionPump.d.ts.map +1 -1
- package/dist/browser/partitionPump.js.map +1 -1
- package/dist/browser/partitionReceiver.d.ts +6 -6
- package/dist/browser/partitionReceiver.d.ts.map +1 -1
- package/dist/browser/partitionReceiver.js +1 -1
- package/dist/browser/partitionReceiver.js.map +1 -1
- package/dist/browser/pumpManager.d.ts +5 -5
- package/dist/browser/pumpManager.d.ts.map +1 -1
- package/dist/browser/pumpManager.js.map +1 -1
- package/dist/browser/util/delayWithoutThrow.d.ts +1 -1
- package/dist/browser/util/delayWithoutThrow.d.ts.map +1 -1
- package/dist/browser/util/delayWithoutThrow.js.map +1 -1
- package/dist/browser/util/error.d.ts +3 -3
- package/dist/browser/util/error.d.ts.map +1 -1
- package/dist/browser/util/error.js.map +1 -1
- package/dist/browser/util/operationOptions.d.ts +2 -2
- package/dist/browser/util/operationOptions.d.ts.map +1 -1
- package/dist/browser/util/operationOptions.js.map +1 -1
- package/dist/browser/util/retries.d.ts +1 -1
- package/dist/browser/util/retries.d.ts.map +1 -1
- package/dist/browser/util/retries.js.map +1 -1
- package/dist/browser/util/typeGuards.d.ts +1 -1
- package/dist/browser/util/typeGuards.d.ts.map +1 -1
- package/dist/browser/util/typeGuards.js +1 -1
- package/dist/browser/util/typeGuards.js.map +1 -1
- package/dist/browser/withAuth.d.ts +5 -5
- package/dist/browser/withAuth.d.ts.map +1 -1
- package/dist/browser/withAuth.js +1 -1
- package/dist/browser/withAuth.js.map +1 -1
- package/dist/commonjs/batchingPartitionChannel.d.ts +3 -3
- package/dist/commonjs/batchingPartitionChannel.d.ts.map +1 -1
- package/dist/commonjs/batchingPartitionChannel.js.map +1 -1
- package/dist/commonjs/connectionContext.d.ts +8 -7
- package/dist/commonjs/connectionContext.d.ts.map +1 -1
- package/dist/commonjs/connectionContext.js +0 -2
- package/dist/commonjs/connectionContext.js.map +1 -1
- package/dist/commonjs/diagnostics/instrumentEventData.d.ts +5 -5
- package/dist/commonjs/diagnostics/instrumentEventData.d.ts.map +1 -1
- package/dist/commonjs/diagnostics/instrumentEventData.js.map +1 -1
- package/dist/commonjs/diagnostics/tracing.d.ts +2 -2
- package/dist/commonjs/diagnostics/tracing.d.ts.map +1 -1
- package/dist/commonjs/diagnostics/tracing.js.map +1 -1
- package/dist/commonjs/eventData.d.ts +2 -2
- package/dist/commonjs/eventData.d.ts.map +1 -1
- package/dist/commonjs/eventData.js.map +1 -1
- package/dist/commonjs/eventDataAdapter.d.ts +1 -1
- package/dist/commonjs/eventDataAdapter.d.ts.map +1 -1
- package/dist/commonjs/eventDataAdapter.js.map +1 -1
- package/dist/commonjs/eventDataBatch.d.ts +5 -5
- package/dist/commonjs/eventDataBatch.d.ts.map +1 -1
- package/dist/commonjs/eventDataBatch.js.map +1 -1
- package/dist/commonjs/eventHubBufferedProducerClient.d.ts +6 -6
- package/dist/commonjs/eventHubBufferedProducerClient.d.ts.map +1 -1
- package/dist/commonjs/eventHubBufferedProducerClient.js.map +1 -1
- package/dist/commonjs/eventHubConsumerClient.d.ts +5 -5
- package/dist/commonjs/eventHubConsumerClient.d.ts.map +1 -1
- package/dist/commonjs/eventHubConsumerClient.js.map +1 -1
- package/dist/commonjs/eventHubConsumerClientModels.d.ts +6 -6
- package/dist/commonjs/eventHubConsumerClientModels.d.ts.map +1 -1
- package/dist/commonjs/eventHubConsumerClientModels.js.map +1 -1
- package/dist/commonjs/eventHubProducerClient.d.ts +7 -7
- package/dist/commonjs/eventHubProducerClient.d.ts.map +1 -1
- package/dist/commonjs/eventHubProducerClient.js.map +1 -1
- package/dist/commonjs/eventHubSender.d.ts +8 -8
- package/dist/commonjs/eventHubSender.d.ts.map +1 -1
- package/dist/commonjs/eventHubSender.js.map +1 -1
- package/dist/commonjs/eventProcessor.d.ts +6 -6
- package/dist/commonjs/eventProcessor.d.ts.map +1 -1
- package/dist/commonjs/eventProcessor.js.map +1 -1
- package/dist/commonjs/impl/awaitableQueue.d.ts +1 -1
- package/dist/commonjs/impl/awaitableQueue.d.ts.map +1 -1
- package/dist/commonjs/impl/awaitableQueue.js.map +1 -1
- package/dist/commonjs/inMemoryCheckpointStore.d.ts +2 -2
- package/dist/commonjs/inMemoryCheckpointStore.d.ts.map +1 -1
- package/dist/commonjs/inMemoryCheckpointStore.js.map +1 -1
- package/dist/commonjs/loadBalancerStrategies/balancedStrategy.d.ts +2 -2
- package/dist/commonjs/loadBalancerStrategies/balancedStrategy.d.ts.map +1 -1
- package/dist/commonjs/loadBalancerStrategies/balancedStrategy.js.map +1 -1
- package/dist/commonjs/loadBalancerStrategies/greedyStrategy.d.ts +2 -2
- package/dist/commonjs/loadBalancerStrategies/greedyStrategy.d.ts.map +1 -1
- package/dist/commonjs/loadBalancerStrategies/greedyStrategy.js.map +1 -1
- package/dist/commonjs/loadBalancerStrategies/loadBalancingStrategy.d.ts +1 -1
- package/dist/commonjs/loadBalancerStrategies/loadBalancingStrategy.d.ts.map +1 -1
- package/dist/commonjs/loadBalancerStrategies/loadBalancingStrategy.js.map +1 -1
- package/dist/commonjs/loadBalancerStrategies/unbalancedStrategy.d.ts +2 -2
- package/dist/commonjs/loadBalancerStrategies/unbalancedStrategy.d.ts.map +1 -1
- package/dist/commonjs/loadBalancerStrategies/unbalancedStrategy.js.map +1 -1
- package/dist/commonjs/logger.d.ts +1 -1
- package/dist/commonjs/logger.d.ts.map +1 -1
- package/dist/commonjs/logger.js.map +1 -1
- package/dist/commonjs/managementClient.d.ts +4 -4
- package/dist/commonjs/managementClient.d.ts.map +1 -1
- package/dist/commonjs/managementClient.js.map +1 -1
- package/dist/commonjs/models/private.d.ts +5 -5
- package/dist/commonjs/models/private.d.ts.map +1 -1
- package/dist/commonjs/models/private.js +0 -1
- package/dist/commonjs/models/private.js.map +1 -1
- package/dist/commonjs/models/public.d.ts +2 -2
- package/dist/commonjs/models/public.d.ts.map +1 -1
- package/dist/commonjs/models/public.js.map +1 -1
- package/dist/commonjs/partitionProcessor.d.ts +5 -5
- package/dist/commonjs/partitionProcessor.d.ts.map +1 -1
- package/dist/commonjs/partitionProcessor.js.map +1 -1
- package/dist/commonjs/partitionPump.d.ts +7 -7
- package/dist/commonjs/partitionPump.d.ts.map +1 -1
- package/dist/commonjs/partitionPump.js.map +1 -1
- package/dist/commonjs/partitionReceiver.d.ts +6 -6
- package/dist/commonjs/partitionReceiver.d.ts.map +1 -1
- package/dist/commonjs/partitionReceiver.js.map +1 -1
- package/dist/commonjs/pumpManager.d.ts +5 -5
- package/dist/commonjs/pumpManager.d.ts.map +1 -1
- package/dist/commonjs/pumpManager.js.map +1 -1
- package/dist/commonjs/util/delayWithoutThrow.d.ts +1 -1
- package/dist/commonjs/util/delayWithoutThrow.d.ts.map +1 -1
- package/dist/commonjs/util/delayWithoutThrow.js.map +1 -1
- package/dist/commonjs/util/error.d.ts +3 -3
- package/dist/commonjs/util/error.d.ts.map +1 -1
- package/dist/commonjs/util/error.js.map +1 -1
- package/dist/commonjs/util/operationOptions.d.ts +2 -2
- package/dist/commonjs/util/operationOptions.d.ts.map +1 -1
- package/dist/commonjs/util/operationOptions.js.map +1 -1
- package/dist/commonjs/util/retries.d.ts +1 -1
- package/dist/commonjs/util/retries.d.ts.map +1 -1
- package/dist/commonjs/util/retries.js.map +1 -1
- package/dist/commonjs/util/typeGuards.d.ts +1 -1
- package/dist/commonjs/util/typeGuards.d.ts.map +1 -1
- package/dist/commonjs/util/typeGuards.js.map +1 -1
- package/dist/commonjs/withAuth.d.ts +5 -5
- package/dist/commonjs/withAuth.d.ts.map +1 -1
- package/dist/commonjs/withAuth.js.map +1 -1
- package/dist/esm/batchingPartitionChannel.d.ts +3 -3
- package/dist/esm/batchingPartitionChannel.d.ts.map +1 -1
- package/dist/esm/batchingPartitionChannel.js.map +1 -1
- package/dist/esm/connectionContext.d.ts +8 -7
- package/dist/esm/connectionContext.d.ts.map +1 -1
- package/dist/esm/connectionContext.js +2 -4
- package/dist/esm/connectionContext.js.map +1 -1
- package/dist/esm/diagnostics/instrumentEventData.d.ts +5 -5
- package/dist/esm/diagnostics/instrumentEventData.d.ts.map +1 -1
- package/dist/esm/diagnostics/instrumentEventData.js.map +1 -1
- package/dist/esm/diagnostics/tracing.d.ts +2 -2
- package/dist/esm/diagnostics/tracing.d.ts.map +1 -1
- package/dist/esm/diagnostics/tracing.js.map +1 -1
- package/dist/esm/eventData.d.ts +2 -2
- package/dist/esm/eventData.d.ts.map +1 -1
- package/dist/esm/eventData.js +2 -2
- package/dist/esm/eventData.js.map +1 -1
- package/dist/esm/eventDataAdapter.d.ts +1 -1
- package/dist/esm/eventDataAdapter.d.ts.map +1 -1
- package/dist/esm/eventDataAdapter.js.map +1 -1
- package/dist/esm/eventDataBatch.d.ts +5 -5
- package/dist/esm/eventDataBatch.d.ts.map +1 -1
- package/dist/esm/eventDataBatch.js.map +1 -1
- package/dist/esm/eventHubBufferedProducerClient.d.ts +6 -6
- package/dist/esm/eventHubBufferedProducerClient.d.ts.map +1 -1
- package/dist/esm/eventHubBufferedProducerClient.js.map +1 -1
- package/dist/esm/eventHubConsumerClient.d.ts +5 -5
- package/dist/esm/eventHubConsumerClient.d.ts.map +1 -1
- package/dist/esm/eventHubConsumerClient.js.map +1 -1
- package/dist/esm/eventHubConsumerClientModels.d.ts +6 -6
- package/dist/esm/eventHubConsumerClientModels.d.ts.map +1 -1
- package/dist/esm/eventHubConsumerClientModels.js.map +1 -1
- package/dist/esm/eventHubProducerClient.d.ts +7 -7
- package/dist/esm/eventHubProducerClient.d.ts.map +1 -1
- package/dist/esm/eventHubProducerClient.js.map +1 -1
- package/dist/esm/eventHubSender.d.ts +8 -8
- package/dist/esm/eventHubSender.d.ts.map +1 -1
- package/dist/esm/eventHubSender.js +3 -3
- package/dist/esm/eventHubSender.js.map +1 -1
- package/dist/esm/eventProcessor.d.ts +6 -6
- package/dist/esm/eventProcessor.d.ts.map +1 -1
- package/dist/esm/eventProcessor.js.map +1 -1
- package/dist/esm/impl/awaitableQueue.d.ts +1 -1
- package/dist/esm/impl/awaitableQueue.d.ts.map +1 -1
- package/dist/esm/impl/awaitableQueue.js.map +1 -1
- package/dist/esm/inMemoryCheckpointStore.d.ts +2 -2
- package/dist/esm/inMemoryCheckpointStore.d.ts.map +1 -1
- package/dist/esm/inMemoryCheckpointStore.js.map +1 -1
- package/dist/esm/loadBalancerStrategies/balancedStrategy.d.ts +2 -2
- package/dist/esm/loadBalancerStrategies/balancedStrategy.d.ts.map +1 -1
- package/dist/esm/loadBalancerStrategies/balancedStrategy.js.map +1 -1
- package/dist/esm/loadBalancerStrategies/greedyStrategy.d.ts +2 -2
- package/dist/esm/loadBalancerStrategies/greedyStrategy.d.ts.map +1 -1
- package/dist/esm/loadBalancerStrategies/greedyStrategy.js.map +1 -1
- package/dist/esm/loadBalancerStrategies/loadBalancingStrategy.d.ts +1 -1
- package/dist/esm/loadBalancerStrategies/loadBalancingStrategy.d.ts.map +1 -1
- package/dist/esm/loadBalancerStrategies/loadBalancingStrategy.js.map +1 -1
- package/dist/esm/loadBalancerStrategies/unbalancedStrategy.d.ts +2 -2
- package/dist/esm/loadBalancerStrategies/unbalancedStrategy.d.ts.map +1 -1
- package/dist/esm/loadBalancerStrategies/unbalancedStrategy.js.map +1 -1
- package/dist/esm/logger.d.ts +1 -1
- package/dist/esm/logger.d.ts.map +1 -1
- package/dist/esm/logger.js.map +1 -1
- package/dist/esm/managementClient.d.ts +4 -4
- package/dist/esm/managementClient.d.ts.map +1 -1
- package/dist/esm/managementClient.js +1 -1
- package/dist/esm/managementClient.js.map +1 -1
- package/dist/esm/models/private.d.ts +5 -5
- package/dist/esm/models/private.d.ts.map +1 -1
- package/dist/esm/models/private.js +1 -1
- package/dist/esm/models/private.js.map +1 -1
- package/dist/esm/models/public.d.ts +2 -2
- package/dist/esm/models/public.d.ts.map +1 -1
- package/dist/esm/models/public.js.map +1 -1
- package/dist/esm/partitionProcessor.d.ts +5 -5
- package/dist/esm/partitionProcessor.d.ts.map +1 -1
- package/dist/esm/partitionProcessor.js.map +1 -1
- package/dist/esm/partitionPump.d.ts +7 -7
- package/dist/esm/partitionPump.d.ts.map +1 -1
- package/dist/esm/partitionPump.js.map +1 -1
- package/dist/esm/partitionReceiver.d.ts +6 -6
- package/dist/esm/partitionReceiver.d.ts.map +1 -1
- package/dist/esm/partitionReceiver.js +1 -1
- package/dist/esm/partitionReceiver.js.map +1 -1
- package/dist/esm/pumpManager.d.ts +5 -5
- package/dist/esm/pumpManager.d.ts.map +1 -1
- package/dist/esm/pumpManager.js.map +1 -1
- package/dist/esm/util/delayWithoutThrow.d.ts +1 -1
- package/dist/esm/util/delayWithoutThrow.d.ts.map +1 -1
- package/dist/esm/util/delayWithoutThrow.js.map +1 -1
- package/dist/esm/util/error.d.ts +3 -3
- package/dist/esm/util/error.d.ts.map +1 -1
- package/dist/esm/util/error.js.map +1 -1
- package/dist/esm/util/operationOptions.d.ts +2 -2
- package/dist/esm/util/operationOptions.d.ts.map +1 -1
- package/dist/esm/util/operationOptions.js.map +1 -1
- package/dist/esm/util/retries.d.ts +1 -1
- package/dist/esm/util/retries.d.ts.map +1 -1
- package/dist/esm/util/retries.js.map +1 -1
- package/dist/esm/util/typeGuards.d.ts +1 -1
- package/dist/esm/util/typeGuards.d.ts.map +1 -1
- package/dist/esm/util/typeGuards.js +1 -1
- package/dist/esm/util/typeGuards.js.map +1 -1
- package/dist/esm/withAuth.d.ts +5 -5
- package/dist/esm/withAuth.d.ts.map +1 -1
- package/dist/esm/withAuth.js +1 -1
- package/dist/esm/withAuth.js.map +1 -1
- package/dist/event-hubs.d.ts +5 -5
- package/package.json +5 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eventDataBatch.js","sourceRoot":"","sources":["../../src/eventDataBatch.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EACL,iBAAiB,EAEjB,sBAAsB,EACtB,oCAAoC,EACpC,aAAa,GACd,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAsB,OAAO,EAA0B,MAAM,cAAc,CAAC;AACnF,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAErE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,gCAAgC,EAAE,MAAM,iBAAiB,CAAC;AAGnE;;GAEG;AACH,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAC/B;;GAEG;AACH,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAC/B;;GAEG;AACH,MAAM,oBAAoB,GAAG,GAAG,CAAC;AAEjC;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,cAAuB;IACtD,OAAO,CACL,sBAAsB,CAAC,cAAc,EAAE,CAAC,OAAO,EAAE,aAAa,EAAE,QAAQ,CAAC,CAAC;QAC1E,OAAO,cAAc,CAAC,MAAM,KAAK,UAAU;QAC3C,OAAO,cAAc,CAAC,KAAK,KAAK,QAAQ;QACxC,OAAO,cAAc,CAAC,WAAW,KAAK,QAAQ,CAC/C,CAAC;AACJ,CAAC;AAsED;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;IA4D7B;;;;OAIG;IACH,YACE,OAA0B,EAC1B,cAAsB,EACtB,YAAqB,EACrB,YAAqB,EACrB,WAAoB;QA9CtB;;WAEG;QACK,qBAAgB,GAAa,EAAE,CAAC;QAKxC;;WAEG;QACK,kBAA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microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { AmqpAnnotatedMessage } from \"@azure/core-amqp\";\nimport {\n assertIsEventData,\n EventData,\n isAmqpAnnotatedMessage,\n populateIdempotentMessageAnnotations,\n toRheaMessage,\n} from \"./eventData.js\";\nimport { ConnectionContext } from \"./connectionContext.js\";\nimport { MessageAnnotations, message, Message as RheaMessage } from \"rhea-promise\";\nimport { isDefined, isObjectWithProperties } from \"@azure/core-util\";\nimport { OperationTracingOptions, TracingContext } from \"@azure/core-tracing\";\nimport { instrumentEventData } from \"./diagnostics/instrumentEventData.js\";\nimport { throwTypeErrorIfParameterMissing } from \"./util/error.js\";\nimport { PartitionPublishingProperties } from \"./models/private.js\";\n\n/**\n * The amount of bytes to reserve as overhead for a small message.\n */\nconst smallMessageOverhead = 5;\n/**\n * The amount of bytes to reserve as overhead for a large message.\n */\nconst largeMessageOverhead = 8;\n/**\n * The maximum number of bytes that a message may be to be considered small.\n */\nconst smallMessageMaxBytes = 255;\n\n/**\n * Checks if the provided eventDataBatch is an instance of `EventDataBatch`.\n * @param eventDataBatch - The instance of `EventDataBatch` to verify.\n * @internal\n */\nexport function isEventDataBatch(eventDataBatch: unknown): eventDataBatch is EventDataBatch {\n return (\n isObjectWithProperties(eventDataBatch, [\"count\", \"sizeInBytes\", \"tryAdd\"]) &&\n typeof eventDataBatch.tryAdd === \"function\" &&\n typeof eventDataBatch.count === \"number\" &&\n typeof eventDataBatch.sizeInBytes === \"number\"\n );\n}\n\n/**\n * Options to configure the behavior of the `tryAdd` method on the `EventDataBatch` class.\n */\nexport interface TryAddOptions {\n /**\n * The options to use when creating Spans for tracing.\n */\n tracingOptions?: OperationTracingOptions;\n}\n\n/**\n * An interface representing a batch of events which can be used to send events to Event Hub.\n *\n * To create the batch, use the `createBatch()` method on the `EventHubProducerClient`.\n * To send the batch, use the `sendBatch()` method on the same client.\n * To fill the batch, use the `tryAdd()` method on the batch itself.\n *\n */\nexport interface EventDataBatch {\n /**\n * A value that is hashed and used by the Azure Event Hubs service to determine the partition to\n * which the events are sent. Use the `createBatch()` method on the `EventHubProducerClient` to\n * set the partitionKey.\n * @readonly\n * @internal\n */\n readonly partitionKey?: string;\n\n /**\n * Id of the partition to which the batch of events are sent. Use the `createBatch()` method on\n * the `EventHubProducerClient` to set the partitionId.\n * @readonly\n * @internal\n */\n readonly partitionId?: string;\n\n /**\n * Size of the batch in bytes after the events added to it have been encoded into a single AMQP\n * message.\n * @readonly\n */\n readonly sizeInBytes: number;\n\n /**\n * Number of events added to the batch.\n * @readonly\n */\n readonly count: number;\n\n /**\n * The maximum size of the batch, in bytes. The `tryAdd` function on the batch will return `false`\n * if the event being added causes the size of the batch to exceed this limit. Use the `createBatch()` method on\n * the `EventHubProducerClient` to set the maxSizeInBytes.\n * @readonly\n */\n readonly maxSizeInBytes: number;\n\n /**\n * Adds an event to the batch if permitted by the batch's size limit.\n * **NOTE**: Always remember to check the return value of this method, before calling it again\n * for the next event.\n *\n * @param eventData - An individual event data object or AmqpAnnotatedMessage.\n * @returns A boolean value indicating if the event data has been added to the batch or not.\n */\n tryAdd(eventData: EventData | AmqpAnnotatedMessage, options?: TryAddOptions): boolean;\n}\n\n/**\n * An internal class representing a batch of events which can be used to send events to Event Hub.\n *\n * @internal\n */\nexport class EventDataBatchImpl implements EventDataBatch {\n /**\n * Describes the amqp connection context for the Client.\n */\n private _context: ConnectionContext;\n /**\n * The Id of the partition to which the batch is expected to be sent to.\n * Specifying this will throw an error if the batch was created using a `partitionKey`.\n */\n private _partitionId?: string;\n /**\n * A value that is hashed to produce a partition assignment.\n * It guarantees that messages with the same partitionKey end up in the same partition.\n * Specifying this will throw an error if the batch was created using a `partitionId`.\n */\n private _partitionKey?: string;\n /**\n * The maximum size allowed for the batch.\n */\n private _maxSizeInBytes: number;\n /**\n * Current size of the batch in bytes.\n */\n private _sizeInBytes: number;\n /**\n * Encoded amqp messages.\n */\n private _encodedMessages: Buffer[] = [];\n /**\n * Number of events in the batch.\n */\n private _count: number;\n /**\n * List of 'message' span contexts.\n */\n private _spanContexts: TracingContext[] = [];\n /**\n * The message annotations to apply on the batch envelope.\n * This will reflect the message annotations on the first event\n * that was added to the batch.\n * A common annotation is the partition key.\n */\n private _batchAnnotations?: MessageAnnotations;\n /**\n * Indicates that the batch should be treated as idempotent.\n */\n private _isIdempotent: boolean;\n /**\n * The sequence number assigned to the first event in the batch while\n * the batch is being sent to the service.\n */\n private _pendingStartingSequenceNumber?: number;\n /**\n * The publishing sequence number assigned to the first event in the batch at the time\n * the batch was successfully published.\n * If the producer was not configured to apply sequence numbering or if the batch\n * has not yet been successfully published, the value will be `undefined`.\n */\n private _startingPublishSequenceNumber?: number;\n\n /**\n * EventDataBatch should not be constructed using `new EventDataBatch()`\n * Use the `createBatch()` method on your `EventHubProducer` instead.\n * @internal\n */\n constructor(\n context: ConnectionContext,\n maxSizeInBytes: number,\n isIdempotent: boolean,\n partitionKey?: string,\n partitionId?: string,\n ) {\n this._context = context;\n this._maxSizeInBytes = maxSizeInBytes;\n this._isIdempotent = isIdempotent;\n this._partitionKey = isDefined(partitionKey) ? String(partitionKey) : partitionKey;\n this._partitionId = isDefined(partitionId) ? String(partitionId) : partitionId;\n this._sizeInBytes = 0;\n this._count = 0;\n }\n\n /**\n * The maximum size of the batch, in bytes.\n * @readonly\n */\n get maxSizeInBytes(): number {\n return this._maxSizeInBytes;\n }\n\n /**\n * The partitionKey set during `EventDataBatch` creation. This value is hashed to\n * produce a partition assignment when the producer is created without a `partitionId`\n * @readonly\n */\n get partitionKey(): string | undefined {\n return this._partitionKey;\n }\n\n /**\n * The partitionId set during `EventDataBatch` creation.\n * If this value is set then partitionKey can not be set.\n * @readonly\n */\n get partitionId(): string | undefined {\n return this._partitionId;\n }\n\n /**\n * Size of the `EventDataBatch` instance after the events added to it have been\n * encoded into a single AMQP message.\n * @readonly\n */\n get sizeInBytes(): number {\n return this._sizeInBytes;\n }\n\n /**\n * Number of events in the `EventDataBatch` instance.\n * @readonly\n */\n get count(): number {\n return this._count;\n }\n\n /**\n * The publishing sequence number assigned to the first event in the batch at the time\n * the batch was successfully published.\n * If the producer was not configured to apply sequence numbering or if the batch\n * has not yet been successfully published, the value will be `undefined`.\n */\n get startingPublishedSequenceNumber(): number | undefined {\n return this._startingPublishSequenceNumber;\n }\n\n /**\n * Gets the \"message\" span contexts that were created when adding events to the batch.\n * @internal\n */\n get _messageSpanContexts(): TracingContext[] {\n return this._spanContexts;\n }\n\n /**\n * Generates an AMQP message that contains the provided encoded events and annotations.\n * @param encodedEvents - The already encoded events to include in the AMQP batch.\n * @param annotations - The message annotations to set on the batch.\n * @param publishingProps - Idempotent publishing properties used to decorate the events in the batch while sending.\n */\n private _generateBatch(\n encodedEvents: Buffer[],\n annotations: MessageAnnotations | undefined,\n publishingProps?: PartitionPublishingProperties,\n ): Buffer {\n if (this._isIdempotent && publishingProps) {\n // We need to decode the encoded events, add the idempotent annotations, and re-encode them.\n // We can't lazily encode the events because we rely on `message.encode` to capture the\n // byte length of anything not in `event.body`.\n // Events can't be decorated ahead of time because the publishing properties aren't known\n // until the events are being sent to the service.\n const decodedEvents = encodedEvents.map(message.decode) as unknown as RheaMessage[];\n const decoratedEvents = this._decorateRheaMessagesWithPublishingProps(\n decodedEvents,\n publishingProps,\n );\n encodedEvents = decoratedEvents.map(message.encode);\n }\n\n const batchEnvelope: RheaMessage = {\n body: message.data_sections(encodedEvents),\n };\n if (annotations) {\n batchEnvelope.message_annotations = annotations;\n }\n return message.encode(batchEnvelope);\n }\n\n /**\n * Uses the publishingProps to add idempotent properties as message annotations to rhea messages.\n */\n private _decorateRheaMessagesWithPublishingProps(\n events: RheaMessage[],\n publishingProps: PartitionPublishingProperties,\n ): RheaMessage[] {\n if (!this._isIdempotent) {\n return events;\n }\n\n const { lastPublishedSequenceNumber = 0, ownerLevel, producerGroupId } = publishingProps;\n const startingSequenceNumber = lastPublishedSequenceNumber + 1;\n for (let i = 0; i < events.length; i++) {\n const event = events[i];\n populateIdempotentMessageAnnotations(event, {\n isIdempotentPublishingEnabled: this._isIdempotent,\n ownerLevel,\n producerGroupId,\n publishSequenceNumber: startingSequenceNumber + i,\n });\n }\n\n this._pendingStartingSequenceNumber = startingSequenceNumber;\n return events;\n }\n\n /**\n * Annotates a rhea message with placeholder idempotent properties if the batch is idempotent.\n * This is necessary so that we can accurately calculate the size of the batch while adding events.\n * Placeholder values are used because real values won't be known until we attempt to send the batch.\n */\n private _decorateRheaMessageWithPlaceholderIdempotencyProps(event: RheaMessage): RheaMessage {\n if (!this._isIdempotent) {\n return event;\n }\n\n if (!event.message_annotations) {\n event.message_annotations = {};\n }\n\n // Set placeholder values for these annotations.\n populateIdempotentMessageAnnotations(event, {\n isIdempotentPublishingEnabled: this._isIdempotent,\n ownerLevel: 0,\n publishSequenceNumber: 0,\n producerGroupId: 0,\n });\n\n return event;\n }\n\n /**\n * Generates the single AMQP message which is the result of encoding all the events\n * added into the `EventDataBatch` instance.\n *\n * This is not meant for the user to use directly.\n *\n * When the `EventDataBatch` instance is passed to the `send()` method on the `EventHubProducer`,\n * this single batched AMQP message is what gets sent over the wire to the service.\n * @readonly\n */\n _generateMessage(publishingProps?: PartitionPublishingProperties): Buffer {\n return this._generateBatch(this._encodedMessages, this._batchAnnotations, publishingProps);\n }\n\n /**\n * Sets startingPublishSequenceNumber to the pending publish sequence number.\n */\n _commitPublish(): void {\n this._startingPublishSequenceNumber = this._pendingStartingSequenceNumber;\n }\n\n /**\n * Tries to add an event data to the batch if permitted by the batch's size limit.\n * **NOTE**: Always remember to check the return value of this method, before calling it again\n * for the next event.\n *\n * @param eventData - An individual event data object.\n * @returns A boolean value indicating if the event data has been added to the batch or not.\n */\n public tryAdd(eventData: EventData | AmqpAnnotatedMessage, options: TryAddOptions = {}): boolean {\n throwTypeErrorIfParameterMissing(this._context.connectionId, \"tryAdd\", \"eventData\", eventData);\n if (!isAmqpAnnotatedMessage(eventData)) {\n assertIsEventData(eventData);\n }\n\n const { entityPath, host } = this._context.config;\n const { event: instrumentedEvent, spanContext } = instrumentEventData(\n eventData,\n options,\n entityPath,\n host,\n );\n\n // Convert EventData to RheaMessage.\n const amqpMessage = toRheaMessage(instrumentedEvent, this._partitionKey);\n const originalAnnotations = amqpMessage.message_annotations && {\n ...amqpMessage.message_annotations,\n };\n this._decorateRheaMessageWithPlaceholderIdempotencyProps(amqpMessage);\n const encodedMessage = message.encode(amqpMessage);\n\n let currentSize = this._sizeInBytes;\n // The first time an event is added, we need to calculate\n // the overhead of creating an AMQP batch, including the\n // message_annotations that are taken from the 1st message.\n if (this.count === 0) {\n if (originalAnnotations) {\n this._batchAnnotations = originalAnnotations;\n }\n\n // Figure out the overhead of creating a batch by generating an empty batch\n // with the expected batch annotations.\n currentSize += this._generateBatch([], this._batchAnnotations).length;\n }\n\n const messageSize = encodedMessage.length;\n const messageOverhead =\n messageSize <= smallMessageMaxBytes ? smallMessageOverhead : largeMessageOverhead;\n currentSize += messageSize + messageOverhead;\n\n // Check if the size of the batch exceeds the maximum allowed size\n // once we add the new event to it.\n if (currentSize > this._maxSizeInBytes) {\n return false;\n }\n\n // The event will fit in the batch, so it is now safe to store it.\n this._encodedMessages.push(encodedMessage);\n if (spanContext) {\n this._spanContexts.push(spanContext);\n }\n\n this._sizeInBytes = currentSize;\n this._count++;\n return true;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"eventDataBatch.js","sourceRoot":"","sources":["../../src/eventDataBatch.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,oCAAoC,EACpC,aAAa,GACd,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAErE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,gCAAgC,EAAE,MAAM,iBAAiB,CAAC;A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,CAAC,MAAM,CAAC;QACxE,CAAC;QAED,MAAM,WAAW,GAAG,cAAc,CAAC,MAAM,CAAC;QAC1C,MAAM,eAAe,GACnB,WAAW,IAAI,oBAAoB,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,oBAAoB,CAAC;QACpF,WAAW,IAAI,WAAW,GAAG,eAAe,CAAC;QAE7C,kEAAkE;QAClE,mCAAmC;QACnC,IAAI,WAAW,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;YACvC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,kEAAkE;QAClE,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAC3C,IAAI,WAAW,EAAE,CAAC;YAChB,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACvC,CAAC;QAED,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,MAAM,EAAE,CAAC;QACd,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AmqpAnnotatedMessage } from \"@azure/core-amqp\";\nimport type { EventData } from \"./eventData.js\";\nimport {\n assertIsEventData,\n isAmqpAnnotatedMessage,\n populateIdempotentMessageAnnotations,\n toRheaMessage,\n} from \"./eventData.js\";\nimport type { ConnectionContext } from \"./connectionContext.js\";\nimport type { MessageAnnotations, Message as RheaMessage } from \"rhea-promise\";\nimport { message } from \"rhea-promise\";\nimport { isDefined, isObjectWithProperties } from \"@azure/core-util\";\nimport type { OperationTracingOptions, TracingContext } from \"@azure/core-tracing\";\nimport { instrumentEventData } from \"./diagnostics/instrumentEventData.js\";\nimport { throwTypeErrorIfParameterMissing } from \"./util/error.js\";\nimport type { PartitionPublishingProperties } from \"./models/private.js\";\n\n/**\n * The amount of bytes to reserve as overhead for a small message.\n */\nconst smallMessageOverhead = 5;\n/**\n * The amount of bytes to reserve as overhead for a large message.\n */\nconst largeMessageOverhead = 8;\n/**\n * The maximum number of bytes that a message may be to be considered small.\n */\nconst smallMessageMaxBytes = 255;\n\n/**\n * Checks if the provided eventDataBatch is an instance of `EventDataBatch`.\n * @param eventDataBatch - The instance of `EventDataBatch` to verify.\n * @internal\n */\nexport function isEventDataBatch(eventDataBatch: unknown): eventDataBatch is EventDataBatch {\n return (\n isObjectWithProperties(eventDataBatch, [\"count\", \"sizeInBytes\", \"tryAdd\"]) &&\n typeof eventDataBatch.tryAdd === \"function\" &&\n typeof eventDataBatch.count === \"number\" &&\n typeof eventDataBatch.sizeInBytes === \"number\"\n );\n}\n\n/**\n * Options to configure the behavior of the `tryAdd` method on the `EventDataBatch` class.\n */\nexport interface TryAddOptions {\n /**\n * The options to use when creating Spans for tracing.\n */\n tracingOptions?: OperationTracingOptions;\n}\n\n/**\n * An interface representing a batch of events which can be used to send events to Event Hub.\n *\n * To create the batch, use the `createBatch()` method on the `EventHubProducerClient`.\n * To send the batch, use the `sendBatch()` method on the same client.\n * To fill the batch, use the `tryAdd()` method on the batch itself.\n *\n */\nexport interface EventDataBatch {\n /**\n * A value that is hashed and used by the Azure Event Hubs service to determine the partition to\n * which the events are sent. Use the `createBatch()` method on the `EventHubProducerClient` to\n * set the partitionKey.\n * @readonly\n * @internal\n */\n readonly partitionKey?: string;\n\n /**\n * Id of the partition to which the batch of events are sent. Use the `createBatch()` method on\n * the `EventHubProducerClient` to set the partitionId.\n * @readonly\n * @internal\n */\n readonly partitionId?: string;\n\n /**\n * Size of the batch in bytes after the events added to it have been encoded into a single AMQP\n * message.\n * @readonly\n */\n readonly sizeInBytes: number;\n\n /**\n * Number of events added to the batch.\n * @readonly\n */\n readonly count: number;\n\n /**\n * The maximum size of the batch, in bytes. The `tryAdd` function on the batch will return `false`\n * if the event being added causes the size of the batch to exceed this limit. Use the `createBatch()` method on\n * the `EventHubProducerClient` to set the maxSizeInBytes.\n * @readonly\n */\n readonly maxSizeInBytes: number;\n\n /**\n * Adds an event to the batch if permitted by the batch's size limit.\n * **NOTE**: Always remember to check the return value of this method, before calling it again\n * for the next event.\n *\n * @param eventData - An individual event data object or AmqpAnnotatedMessage.\n * @returns A boolean value indicating if the event data has been added to the batch or not.\n */\n tryAdd(eventData: EventData | AmqpAnnotatedMessage, options?: TryAddOptions): boolean;\n}\n\n/**\n * An internal class representing a batch of events which can be used to send events to Event Hub.\n *\n * @internal\n */\nexport class EventDataBatchImpl implements EventDataBatch {\n /**\n * Describes the amqp connection context for the Client.\n */\n private _context: ConnectionContext;\n /**\n * The Id of the partition to which the batch is expected to be sent to.\n * Specifying this will throw an error if the batch was created using a `partitionKey`.\n */\n private _partitionId?: string;\n /**\n * A value that is hashed to produce a partition assignment.\n * It guarantees that messages with the same partitionKey end up in the same partition.\n * Specifying this will throw an error if the batch was created using a `partitionId`.\n */\n private _partitionKey?: string;\n /**\n * The maximum size allowed for the batch.\n */\n private _maxSizeInBytes: number;\n /**\n * Current size of the batch in bytes.\n */\n private _sizeInBytes: number;\n /**\n * Encoded amqp messages.\n */\n private _encodedMessages: Buffer[] = [];\n /**\n * Number of events in the batch.\n */\n private _count: number;\n /**\n * List of 'message' span contexts.\n */\n private _spanContexts: TracingContext[] = [];\n /**\n * The message annotations to apply on the batch envelope.\n * This will reflect the message annotations on the first event\n * that was added to the batch.\n * A common annotation is the partition key.\n */\n private _batchAnnotations?: MessageAnnotations;\n /**\n * Indicates that the batch should be treated as idempotent.\n */\n private _isIdempotent: boolean;\n /**\n * The sequence number assigned to the first event in the batch while\n * the batch is being sent to the service.\n */\n private _pendingStartingSequenceNumber?: number;\n /**\n * The publishing sequence number assigned to the first event in the batch at the time\n * the batch was successfully published.\n * If the producer was not configured to apply sequence numbering or if the batch\n * has not yet been successfully published, the value will be `undefined`.\n */\n private _startingPublishSequenceNumber?: number;\n\n /**\n * EventDataBatch should not be constructed using `new EventDataBatch()`\n * Use the `createBatch()` method on your `EventHubProducer` instead.\n * @internal\n */\n constructor(\n context: ConnectionContext,\n maxSizeInBytes: number,\n isIdempotent: boolean,\n partitionKey?: string,\n partitionId?: string,\n ) {\n this._context = context;\n this._maxSizeInBytes = maxSizeInBytes;\n this._isIdempotent = isIdempotent;\n this._partitionKey = isDefined(partitionKey) ? String(partitionKey) : partitionKey;\n this._partitionId = isDefined(partitionId) ? String(partitionId) : partitionId;\n this._sizeInBytes = 0;\n this._count = 0;\n }\n\n /**\n * The maximum size of the batch, in bytes.\n * @readonly\n */\n get maxSizeInBytes(): number {\n return this._maxSizeInBytes;\n }\n\n /**\n * The partitionKey set during `EventDataBatch` creation. This value is hashed to\n * produce a partition assignment when the producer is created without a `partitionId`\n * @readonly\n */\n get partitionKey(): string | undefined {\n return this._partitionKey;\n }\n\n /**\n * The partitionId set during `EventDataBatch` creation.\n * If this value is set then partitionKey can not be set.\n * @readonly\n */\n get partitionId(): string | undefined {\n return this._partitionId;\n }\n\n /**\n * Size of the `EventDataBatch` instance after the events added to it have been\n * encoded into a single AMQP message.\n * @readonly\n */\n get sizeInBytes(): number {\n return this._sizeInBytes;\n }\n\n /**\n * Number of events in the `EventDataBatch` instance.\n * @readonly\n */\n get count(): number {\n return this._count;\n }\n\n /**\n * The publishing sequence number assigned to the first event in the batch at the time\n * the batch was successfully published.\n * If the producer was not configured to apply sequence numbering or if the batch\n * has not yet been successfully published, the value will be `undefined`.\n */\n get startingPublishedSequenceNumber(): number | undefined {\n return this._startingPublishSequenceNumber;\n }\n\n /**\n * Gets the \"message\" span contexts that were created when adding events to the batch.\n * @internal\n */\n get _messageSpanContexts(): TracingContext[] {\n return this._spanContexts;\n }\n\n /**\n * Generates an AMQP message that contains the provided encoded events and annotations.\n * @param encodedEvents - The already encoded events to include in the AMQP batch.\n * @param annotations - The message annotations to set on the batch.\n * @param publishingProps - Idempotent publishing properties used to decorate the events in the batch while sending.\n */\n private _generateBatch(\n encodedEvents: Buffer[],\n annotations: MessageAnnotations | undefined,\n publishingProps?: PartitionPublishingProperties,\n ): Buffer {\n if (this._isIdempotent && publishingProps) {\n // We need to decode the encoded events, add the idempotent annotations, and re-encode them.\n // We can't lazily encode the events because we rely on `message.encode` to capture the\n // byte length of anything not in `event.body`.\n // Events can't be decorated ahead of time because the publishing properties aren't known\n // until the events are being sent to the service.\n const decodedEvents = encodedEvents.map(message.decode) as unknown as RheaMessage[];\n const decoratedEvents = this._decorateRheaMessagesWithPublishingProps(\n decodedEvents,\n publishingProps,\n );\n encodedEvents = decoratedEvents.map(message.encode);\n }\n\n const batchEnvelope: RheaMessage = {\n body: message.data_sections(encodedEvents),\n };\n if (annotations) {\n batchEnvelope.message_annotations = annotations;\n }\n return message.encode(batchEnvelope);\n }\n\n /**\n * Uses the publishingProps to add idempotent properties as message annotations to rhea messages.\n */\n private _decorateRheaMessagesWithPublishingProps(\n events: RheaMessage[],\n publishingProps: PartitionPublishingProperties,\n ): RheaMessage[] {\n if (!this._isIdempotent) {\n return events;\n }\n\n const { lastPublishedSequenceNumber = 0, ownerLevel, producerGroupId } = publishingProps;\n const startingSequenceNumber = lastPublishedSequenceNumber + 1;\n for (let i = 0; i < events.length; i++) {\n const event = events[i];\n populateIdempotentMessageAnnotations(event, {\n isIdempotentPublishingEnabled: this._isIdempotent,\n ownerLevel,\n producerGroupId,\n publishSequenceNumber: startingSequenceNumber + i,\n });\n }\n\n this._pendingStartingSequenceNumber = startingSequenceNumber;\n return events;\n }\n\n /**\n * Annotates a rhea message with placeholder idempotent properties if the batch is idempotent.\n * This is necessary so that we can accurately calculate the size of the batch while adding events.\n * Placeholder values are used because real values won't be known until we attempt to send the batch.\n */\n private _decorateRheaMessageWithPlaceholderIdempotencyProps(event: RheaMessage): RheaMessage {\n if (!this._isIdempotent) {\n return event;\n }\n\n if (!event.message_annotations) {\n event.message_annotations = {};\n }\n\n // Set placeholder values for these annotations.\n populateIdempotentMessageAnnotations(event, {\n isIdempotentPublishingEnabled: this._isIdempotent,\n ownerLevel: 0,\n publishSequenceNumber: 0,\n producerGroupId: 0,\n });\n\n return event;\n }\n\n /**\n * Generates the single AMQP message which is the result of encoding all the events\n * added into the `EventDataBatch` instance.\n *\n * This is not meant for the user to use directly.\n *\n * When the `EventDataBatch` instance is passed to the `send()` method on the `EventHubProducer`,\n * this single batched AMQP message is what gets sent over the wire to the service.\n * @readonly\n */\n _generateMessage(publishingProps?: PartitionPublishingProperties): Buffer {\n return this._generateBatch(this._encodedMessages, this._batchAnnotations, publishingProps);\n }\n\n /**\n * Sets startingPublishSequenceNumber to the pending publish sequence number.\n */\n _commitPublish(): void {\n this._startingPublishSequenceNumber = this._pendingStartingSequenceNumber;\n }\n\n /**\n * Tries to add an event data to the batch if permitted by the batch's size limit.\n * **NOTE**: Always remember to check the return value of this method, before calling it again\n * for the next event.\n *\n * @param eventData - An individual event data object.\n * @returns A boolean value indicating if the event data has been added to the batch or not.\n */\n public tryAdd(eventData: EventData | AmqpAnnotatedMessage, options: TryAddOptions = {}): boolean {\n throwTypeErrorIfParameterMissing(this._context.connectionId, \"tryAdd\", \"eventData\", eventData);\n if (!isAmqpAnnotatedMessage(eventData)) {\n assertIsEventData(eventData);\n }\n\n const { entityPath, host } = this._context.config;\n const { event: instrumentedEvent, spanContext } = instrumentEventData(\n eventData,\n options,\n entityPath,\n host,\n );\n\n // Convert EventData to RheaMessage.\n const amqpMessage = toRheaMessage(instrumentedEvent, this._partitionKey);\n const originalAnnotations = amqpMessage.message_annotations && {\n ...amqpMessage.message_annotations,\n };\n this._decorateRheaMessageWithPlaceholderIdempotencyProps(amqpMessage);\n const encodedMessage = message.encode(amqpMessage);\n\n let currentSize = this._sizeInBytes;\n // The first time an event is added, we need to calculate\n // the overhead of creating an AMQP batch, including the\n // message_annotations that are taken from the 1st message.\n if (this.count === 0) {\n if (originalAnnotations) {\n this._batchAnnotations = originalAnnotations;\n }\n\n // Figure out the overhead of creating a batch by generating an empty batch\n // with the expected batch annotations.\n currentSize += this._generateBatch([], this._batchAnnotations).length;\n }\n\n const messageSize = encodedMessage.length;\n const messageOverhead =\n messageSize <= smallMessageMaxBytes ? smallMessageOverhead : largeMessageOverhead;\n currentSize += messageSize + messageOverhead;\n\n // Check if the size of the batch exceeds the maximum allowed size\n // once we add the new event to it.\n if (currentSize > this._maxSizeInBytes) {\n return false;\n }\n\n // The event will fit in the batch, so it is now safe to store it.\n this._encodedMessages.push(encodedMessage);\n if (spanContext) {\n this._spanContexts.push(spanContext);\n }\n\n this._sizeInBytes = currentSize;\n this._count++;\n return true;\n }\n}\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { EventData } from "./eventData.js";
|
|
2
|
-
import { OperationOptions } from "./util/operationOptions.js";
|
|
3
|
-
import { EventHubClientOptions, GetEventHubPropertiesOptions, GetPartitionIdsOptions, GetPartitionPropertiesOptions, SendBatchOptions } from "./models/public.js";
|
|
4
|
-
import { EventHubProperties, PartitionProperties } from "./managementClient.js";
|
|
5
|
-
import { NamedKeyCredential, SASCredential, TokenCredential } from "@azure/core-auth";
|
|
6
|
-
import { AmqpAnnotatedMessage } from "@azure/core-amqp";
|
|
1
|
+
import type { EventData } from "./eventData.js";
|
|
2
|
+
import type { OperationOptions } from "./util/operationOptions.js";
|
|
3
|
+
import type { EventHubClientOptions, GetEventHubPropertiesOptions, GetPartitionIdsOptions, GetPartitionPropertiesOptions, SendBatchOptions } from "./models/public.js";
|
|
4
|
+
import type { EventHubProperties, PartitionProperties } from "./managementClient.js";
|
|
5
|
+
import type { NamedKeyCredential, SASCredential, TokenCredential } from "@azure/core-auth";
|
|
6
|
+
import type { AmqpAnnotatedMessage } from "@azure/core-amqp";
|
|
7
7
|
/**
|
|
8
8
|
* Contains the events that were successfully sent to the Event Hub,
|
|
9
9
|
* and the partition they were assigned to.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eventHubBufferedProducerClient.d.ts","sourceRoot":"","sources":["../../src/eventHubBufferedProducerClient.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file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CAAC;QACH,CAAC;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { EventData } from \"./eventData.js\";\nimport { EventHubProducerClient } from \"./eventHubProducerClient.js\";\nimport { OperationOptions } from \"./util/operationOptions.js\";\nimport {\n EventHubClientOptions,\n GetEventHubPropertiesOptions,\n GetPartitionIdsOptions,\n GetPartitionPropertiesOptions,\n SendBatchOptions,\n} from \"./models/public.js\";\nimport { EventHubProperties, PartitionProperties } from \"./managementClient.js\";\nimport { NamedKeyCredential, SASCredential, TokenCredential } from \"@azure/core-auth\";\nimport { isDefined } from \"@azure/core-util\";\nimport { isCredential } from \"./util/typeGuards.js\";\nimport { AmqpAnnotatedMessage, delay } from \"@azure/core-amqp\";\nimport { BatchingPartitionChannel } from \"./batchingPartitionChannel.js\";\nimport { PartitionAssigner } from \"./impl/partitionAssigner.js\";\nimport { logger } from \"./logger.js\";\nimport { getRandomName } from \"./util/utils.js\";\n\n/**\n * Contains the events that were successfully sent to the Event Hub,\n * and the partition they were assigned to.\n */\nexport interface OnSendEventsSuccessContext {\n /**\n * The partition each event was assigned.\n */\n partitionId: string;\n /**\n * The array of {@link EventData} and/or `AmqpAnnotatedMessage` that were successfully sent to the Event Hub.\n */\n events: Array<EventData | AmqpAnnotatedMessage>;\n}\n\n/**\n * Contains the events that were not successfully sent to the Event Hub,\n * the partition they were assigned to, and the error that was encountered while sending.\n */\nexport interface OnSendEventsErrorContext {\n /**\n * The partition each event was assigned.\n */\n partitionId: string;\n /**\n * The array of {@link EventData} and/or `AmqpAnnotatedMessage` that were not successfully sent to the Event Hub.\n */\n events: Array<EventData | AmqpAnnotatedMessage>;\n /**\n * The error that occurred when sending the associated events to the Event Hub.\n */\n error: Error;\n}\n\n/**\n * Describes the options that can be provided while creating the `EventHubBufferedProducerClient`.\n */\nexport interface EventHubBufferedProducerClientOptions extends EventHubClientOptions {\n /**\n * The total number of events that can be buffered for publishing at a given time for a given partition.\n *\n * Default: 1500\n */\n maxEventBufferLengthPerPartition?: number;\n /**\n * The amount of time to wait for a new event to be enqueued in the buffer before publishing a partially full batch.\n *\n * Default: 1 second.\n */\n maxWaitTimeInMs?: number;\n /**\n * The handler to call once a batch has successfully published.\n */\n onSendEventsSuccessHandler?: (ctx: OnSendEventsSuccessContext) => void;\n /**\n * The handler to call when a batch fails to publish.\n */\n onSendEventsErrorHandler: (ctx: OnSendEventsErrorContext) => void;\n /**\n * Indicates whether or not the EventHubProducerClient should enable idempotent publishing to Event Hub partitions.\n * If enabled, the producer will only be able to publish directly to partitions;\n * it will not be able to publish to the Event Hubs gateway for automatic partition routing\n * nor will it be able to use a partition key.\n * Default: false\n */\n enableIdempotentRetries?: boolean;\n}\n\n/**\n * Options to configure the `flush` method on the `EventHubBufferedProducerClient`.\n */\nexport interface BufferedFlushOptions extends OperationOptions {}\n\n/**\n * Options to configure the `close` method on the `EventHubBufferedProducerClient`.\n */\nexport interface BufferedCloseOptions extends OperationOptions {\n /**\n * When `true`, all buffered events that are pending should be sent before closing.\n * When `false`, abandon all buffered events and close immediately.\n * Defaults to `true`.\n */\n flush?: boolean;\n}\n\n/**\n * Options to configure the `enqueueEvents` method on the `EventHubBufferedProducerClient`.\n */\nexport interface EnqueueEventOptions extends SendBatchOptions {}\n\n/**\n * The `EventHubBufferedProducerClient`is used to publish events to a specific Event Hub.\n *\n * The `EventHubBufferedProducerClient` does not publish events immediately.\n * Instead, events are buffered so they can be efficiently batched and published\n * when the batch is full or the `maxWaitTimeInMs` has elapsed with no new events\n * enqueued.\n *\n * Depending on the options specified when events are enqueued, they may be\n * automatically assigned to a partition, grouped according to the specified partition key,\n * or assigned a specifically requested partition.\n *\n * This model is intended to shift the burden of batch management from callers, at the cost of\n * non-deterministic timing, for when events will be published. There are additional trade-offs\n * to consider, as well:\n * - If the application crashes, events in the buffer will not have been published. To prevent\n * data loss, callers are encouraged to track publishing progress using the\n * `onSendEventsSuccessHandler` and `onSendEventsErrorHandler` handlers.\n * - Events specifying a partition key may be assigned a different partition than those using\n * the same key with other producers.\n * - In the unlikely event that a partition becomes temporarily unavailable, the\n * `EventHubBufferedProducerClient` may take longer to recover than other producers.\n *\n * In scenarios where it is important to have events published immediately with a deterministic\n * outcome, ensure that partition keys are assigned to a partition consistent with other\n * publishers, or where maximizing availability is a requirement, using the\n * `EventHubProducerClient` is recommended.\n */\nexport class EventHubBufferedProducerClient {\n /**\n * Controls the `abortSignal` passed to each `BatchingPartitionChannel`.\n * Used to signal when a channel should stop waiting for events.\n */\n private _abortController = new AbortController();\n\n /**\n * Indicates whether the client has been explicitly closed.\n */\n private _isClosed: boolean = false;\n\n /**\n * Handles assigning partitions.\n */\n private _partitionAssigner = new PartitionAssigner();\n\n /**\n * The known partitionIds that will be used when assigning events to partitions.\n */\n private _partitionIds: string[] = [];\n\n /**\n * The EventHubProducerClient to use when creating and sending batches to the Event Hub.\n */\n private _producer: EventHubProducerClient;\n\n /**\n * Mapping of partitionIds to `BatchingPartitionChannels`.\n * Each `BatchingPartitionChannel` handles buffering events and backpressure independently.\n */\n private _partitionChannels = new Map<string, BatchingPartitionChannel>();\n\n /**\n * The options passed by the user when creating the EventHubBufferedProducerClient instance.\n */\n private _clientOptions: EventHubBufferedProducerClientOptions;\n\n /**\n * The interval at which the background management operation should run.\n */\n private _backgroundManagementInterval = 10000; // 10 seconds\n\n /**\n * Indicates whether the background management loop is running.\n */\n private _isBackgroundManagementRunning = false;\n\n /**\n * @readonly\n * The name of the Event Hub instance for which this client is created.\n */\n get eventHubName(): string {\n return this._producer.eventHubName;\n }\n\n /**\n * @readonly\n * The fully qualified namespace of the Event Hub instance for which this client is created.\n * This is likely to be similar to <yournamespace>.servicebus.windows.net.\n */\n get fullyQualifiedNamespace(): string {\n return this._producer.fullyQualifiedNamespace;\n }\n\n /**\n * The name used to identify this EventHubBufferedProducerClient.\n * If not specified or empty, a random unique one will be generated.\n */\n public readonly identifier: string;\n\n /**\n * The `EventHubBufferedProducerClient` class is used to send events to an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param connectionString - The connection string to use for connecting to the Event Hub instance.\n * It is expected that the shared key properties and the Event Hub path are contained in this connection string.\n * e.g. 'Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key;EntityPath=my-event-hub-name'.\n * @param options - A set of options to apply when configuring the client.\n * - `retryOptions` : Configures the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n * - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.\n * - `userAgent` : A string to append to the built in user agent string that is passed to the service.\n */\n constructor(connectionString: string, options: EventHubBufferedProducerClientOptions);\n /**\n * The `EventHubBufferedProducerClient` class is used to send events to an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param connectionString - The connection string to use for connecting to the Event Hubs namespace.\n * It is expected that the shared key properties are contained in this connection string, but not the Event Hub path,\n * e.g. 'Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key;'.\n * @param eventHubName - The name of the specific Event Hub to connect the client to.\n * @param options - A set of options to apply when configuring the client.\n * - `retryOptions` : Configures the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n * - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.\n * - `userAgent` : A string to append to the built in user agent string that is passed to the service.\n */\n constructor(\n connectionString: string,\n eventHubName: string,\n options: EventHubBufferedProducerClientOptions,\n );\n /**\n * The `EventHubBufferedProducerClient` class is used to send events to an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param fullyQualifiedNamespace - The full namespace which is likely to be similar to\n * <yournamespace>.servicebus.windows.net\n * @param eventHubName - The name of the specific Event Hub to connect the client to.\n * @param credential - An credential object used by the client to get the token to authenticate the connection\n * with the Azure Event Hubs service.\n * See @azure/identity for creating credentials that support AAD auth.\n * Use the `AzureNamedKeyCredential` from @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 @azure/core-auth if you want to pass in a `SharedAccessSignature`\n * without using a connection string. This field maps to `signature` in `AzureSASCredential`.\n * @param options - A set of options to apply when configuring the client.\n * - `retryOptions` : Configures the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n * - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.\n * - `userAgent` : A string to append to the built in user agent string that is passed to the service.\n */\n constructor(\n fullyQualifiedNamespace: string,\n eventHubName: string,\n credential: TokenCredential | NamedKeyCredential | SASCredential,\n options: EventHubBufferedProducerClientOptions,\n );\n constructor(\n fullyQualifiedNamespaceOrConnectionString1: string,\n eventHubNameOrOptions2: string | EventHubBufferedProducerClientOptions,\n credentialOrOptions3?:\n | TokenCredential\n | NamedKeyCredential\n | SASCredential\n | EventHubBufferedProducerClientOptions,\n options4?: EventHubBufferedProducerClientOptions,\n ) {\n if (typeof eventHubNameOrOptions2 !== \"string\") {\n this.identifier = eventHubNameOrOptions2.identifier ?? getRandomName();\n this._producer = new EventHubProducerClient(fullyQualifiedNamespaceOrConnectionString1, {\n ...eventHubNameOrOptions2,\n identifier: this.identifier,\n });\n this._clientOptions = { ...eventHubNameOrOptions2 };\n } else if (!isCredential(credentialOrOptions3)) {\n this.identifier = credentialOrOptions3?.identifier ?? getRandomName();\n this._producer = new EventHubProducerClient(\n fullyQualifiedNamespaceOrConnectionString1,\n eventHubNameOrOptions2,\n { ...credentialOrOptions3, identifier: this.identifier },\n );\n this._clientOptions = { ...credentialOrOptions3! };\n } else {\n this.identifier = options4?.identifier ?? getRandomName();\n this._producer = new EventHubProducerClient(\n fullyQualifiedNamespaceOrConnectionString1,\n eventHubNameOrOptions2,\n credentialOrOptions3,\n { ...options4, identifier: this.identifier },\n );\n this._clientOptions = { ...options4! };\n }\n // setting internal idempotent publishing option on the standard producer.\n (this._producer as any)._enableIdempotentRetries = this._clientOptions.enableIdempotentRetries;\n }\n\n /**\n * Closes the AMQP connection to the Event Hub instance,\n * returning a promise that will be resolved when disconnection is completed.\n *\n * This will wait for enqueued events to be flushed to the service before closing\n * the connection.\n * To close without flushing, set the `flush` option to `false`.\n *\n * @param options - The set of options to apply to the operation call.\n * @returns Promise<void>\n * @throws Error if the underlying connection encounters an error while closing.\n */\n async close(options: BufferedCloseOptions = {}): Promise<void> {\n logger.verbose(\"closing buffered producer client...\");\n if (!isDefined(options.flush) || options.flush === true) {\n await this.flush(options);\n }\n // Calling abort signals to the BatchingPartitionChannels that they\n // should stop reading/sending events, and to the background management\n // loop that it should stop periodic partition id updates.\n this._abortController.abort();\n await this._producer.close();\n this._isClosed = true;\n }\n\n /**\n * Enqueues an event into the buffer to be published to the Event Hub.\n * If there is no capacity in the buffer when this method is invoked,\n * it will wait for space to become available and ensure that the event\n * has been enqueued.\n *\n * When this call returns, the event has been accepted into the buffer,\n * but it may not have been published yet.\n * Publishing will take place at a nondeterministic point in the future as the buffer is processed.\n *\n * @param events - An {@link EventData} or `AmqpAnnotatedMessage`.\n * @param options - A set of options that can be specified to influence the way in which\n * the event is sent to the associated Event Hub.\n * - `abortSignal` : A signal used to cancel the enqueueEvent operation.\n * - `partitionId` : The partition this set of events will be sent to. If set, `partitionKey` can not be set.\n * - `partitionKey` : A value that is hashed to produce a partition assignment. If set, `partitionId` can not be set.\n * @returns The total number of events that are currently buffered and waiting to be published, across all partitions.\n */\n async enqueueEvent(\n event: EventData | AmqpAnnotatedMessage,\n options: EnqueueEventOptions = {},\n ): Promise<number> {\n if (this._isClosed) {\n throw new Error(\n `This EventHubBufferedProducerClient has already been closed. Create a new client to enqueue events.`,\n );\n }\n\n if (!this._partitionIds.length) {\n await this._updatePartitionIds();\n }\n if (!this._isBackgroundManagementRunning) {\n this._startPartitionIdsUpdateLoop().catch((e) => {\n logger.error(\n `The following error occured during batch creation or sending: ${JSON.stringify(\n e,\n undefined,\n \" \",\n )}`,\n );\n });\n this._isBackgroundManagementRunning = true;\n }\n\n const partitionId = this._partitionAssigner.assignPartition({\n partitionId: options.partitionId,\n partitionKey: options.partitionKey,\n });\n\n const partitionChannel = this._getPartitionChannel(partitionId);\n await partitionChannel.enqueueEvent(event);\n return this._getTotalBufferedEventsCount();\n }\n\n /**\n * Enqueues events into the buffer to be published to the Event Hub.\n * If there is no capacity in the buffer when this method is invoked,\n * it will wait for space to become available and ensure that the events\n * have been enqueued.\n *\n * When this call returns, the events have been accepted into the buffer,\n * but it may not have been published yet.\n * Publishing will take place at a nondeterministic point in the future as the buffer is processed.\n *\n * @param events - An array of {@link EventData} or `AmqpAnnotatedMessage`.\n * @param options - A set of options that can be specified to influence the way in which\n * events are sent to the associated Event Hub.\n * - `abortSignal` : A signal used to cancel the enqueueEvents operation.\n * - `partitionId` : The partition this set of events will be sent to. If set, `partitionKey` can not be set.\n * - `partitionKey` : A value that is hashed to produce a partition assignment. If set, `partitionId` can not be set.\n * @returns The total number of events that are currently buffered and waiting to be published, across all partitions.\n */\n async enqueueEvents(\n events: EventData[] | AmqpAnnotatedMessage[],\n // eslint-disable-next-line @azure/azure-sdk/ts-naming-options\n options: EnqueueEventOptions = {},\n ): Promise<number> {\n for (const event of events) {\n await this.enqueueEvent(event, options);\n }\n\n return this._getTotalBufferedEventsCount();\n }\n\n /**\n * Attempts to publish all events in the buffer immediately.\n * This may result in multiple batches being published,\n * the outcome of each of which will be individually reported by\n * the `onSendEventsSuccessHandler` and `onSendEventsErrorHandler` handlers.\n *\n * @param options - The set of options to apply to the operation call.\n */\n async flush(options: BufferedFlushOptions = {}): Promise<void> {\n await Promise.all(\n Array.from(this._partitionChannels.values()).map((channel) => channel.flush(options)),\n );\n }\n\n /**\n * Provides the Event Hub runtime information.\n * @param options - The set of options to apply to the operation call.\n * @returns A promise that resolves with information about the Event Hub instance.\n * @throws Error if the underlying connection has been closed, create a new EventHubBufferedProducerClient.\n * @throws AbortError if the operation is cancelled via the abortSignal.\n */\n getEventHubProperties(options: GetEventHubPropertiesOptions = {}): Promise<EventHubProperties> {\n return this._producer.getEventHubProperties(options);\n }\n\n /**\n * Provides the id for each partition associated with the Event Hub.\n * @param options - The set of options to apply to the operation call.\n * @returns A promise that resolves with an Array of strings representing the id for\n * each partition associated with the Event Hub.\n * @throws Error if the underlying connection has been closed, create a new EventHubBufferedProducerClient.\n * @throws AbortError if the operation is cancelled via the abortSignal.\n */\n getPartitionIds(options: GetPartitionIdsOptions = {}): Promise<Array<string>> {\n return this._producer.getPartitionIds(options);\n }\n\n /**\n * Provides information about the state of the specified partition.\n * @param partitionId - The id of the partition for which information is required.\n * @param options - The set of options to apply to the operation call.\n * @returns A promise that resolves with information about the state of the partition .\n * @throws Error if the underlying connection has been closed, create a new EventHubBufferedProducerClient.\n * @throws AbortError if the operation is cancelled via the abortSignal.\n */\n getPartitionProperties(\n partitionId: string,\n options: GetPartitionPropertiesOptions = {},\n ): Promise<PartitionProperties> {\n return this._producer.getPartitionProperties(partitionId, options);\n }\n\n /**\n * Gets the `BatchingPartitionChannel` associated with the partitionId.\n *\n * If one does not exist, it is created.\n */\n private _getPartitionChannel(partitionId: string): BatchingPartitionChannel {\n const partitionChannel =\n this._partitionChannels.get(partitionId) ??\n new BatchingPartitionChannel({\n loopAbortSignal: this._abortController.signal,\n maxBufferSize: this._clientOptions.maxEventBufferLengthPerPartition || 1500,\n maxWaitTimeInMs: this._clientOptions.maxWaitTimeInMs || 1000,\n onSendEventsErrorHandler: this._clientOptions.onSendEventsErrorHandler,\n onSendEventsSuccessHandler: this._clientOptions.onSendEventsSuccessHandler,\n partitionId,\n producer: this._producer,\n });\n this._partitionChannels.set(partitionId, partitionChannel);\n return partitionChannel;\n }\n\n /**\n * Returns the total number of buffered events across all partitions.\n */\n private _getTotalBufferedEventsCount(): number {\n let total = 0;\n for (const [_, channel] of this._partitionChannels) {\n total += channel.getCurrentBufferedCount();\n }\n\n return total;\n }\n\n private async _updatePartitionIds(): Promise<void> {\n logger.verbose(\"Checking for partition Id updates...\");\n const queriedPartitionIds = await this.getPartitionIds();\n\n if (this._partitionIds.length !== queriedPartitionIds.length) {\n logger.verbose(\"Applying partition Id updates\");\n this._partitionIds = queriedPartitionIds;\n this._partitionAssigner.setPartitionIds(this._partitionIds);\n }\n }\n\n private async _startPartitionIdsUpdateLoop(): Promise<void> {\n logger.verbose(\"Starting a background loop to check and apply partition id updates...\");\n while (!this._abortController.signal.aborted && !this._isClosed) {\n await delay<void>(this._backgroundManagementInterval);\n if (!this._isClosed) {\n await this._updatePartitionIds();\n }\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"eventHubBufferedProducerClient.js","sourceRoot":"","sources":["../../src/eventHubBufferedProducerClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAWrE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AA4FhD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,OAAO,8BAA8B;IAgDzC;;;OAGG;IACH,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC;IACrC,CAAC;IAED;;;;OAIG;IACH,IA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AAO,KAAK,CAAC;IACf,CAAC;IAEO,KAAK,CAAC,mBAAmB;QAC/B,MAAM,CAAC,OAAO,CAAC,sCAAsC,CAAC,CAAC;QACvD,MAAM,mBAAmB,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;QAEzD,IAAI,IAAI,CAAC,aAAa,CAAC,MAAM,KAAK,mBAAmB,CAAC,MAAM,EAAE,CAAC;YAC7D,MAAM,CAAC,OAAO,CAAC,+BAA+B,CAAC,CAAC;YAChD,IAAI,CAAC,aAAa,GAAG,mBAAmB,CAAC;YACzC,IAAI,CAAC,kBAAkB,CAAC,eAAe,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,4BAA4B;QACxC,MAAM,CAAC,OAAO,CAAC,uEAAuE,CAAC,CAAC;QACxF,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YAChE,MAAM,KAAK,CAAO,IAAI,CAAC,6BAA6B,CAAC,CAAC;YACtD,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;gBACpB,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAC;YACnC,CAAC;QACH,CAAC;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { EventData } from \"./eventData.js\";\nimport { EventHubProducerClient } from \"./eventHubProducerClient.js\";\nimport type { OperationOptions } from \"./util/operationOptions.js\";\nimport type {\n EventHubClientOptions,\n GetEventHubPropertiesOptions,\n GetPartitionIdsOptions,\n GetPartitionPropertiesOptions,\n SendBatchOptions,\n} from \"./models/public.js\";\nimport type { EventHubProperties, PartitionProperties } from \"./managementClient.js\";\nimport type { NamedKeyCredential, SASCredential, TokenCredential } from \"@azure/core-auth\";\nimport { isDefined } from \"@azure/core-util\";\nimport { isCredential } from \"./util/typeGuards.js\";\nimport type { AmqpAnnotatedMessage } from \"@azure/core-amqp\";\nimport { delay } from \"@azure/core-amqp\";\nimport { BatchingPartitionChannel } from \"./batchingPartitionChannel.js\";\nimport { PartitionAssigner } from \"./impl/partitionAssigner.js\";\nimport { logger } from \"./logger.js\";\nimport { getRandomName } from \"./util/utils.js\";\n\n/**\n * Contains the events that were successfully sent to the Event Hub,\n * and the partition they were assigned to.\n */\nexport interface OnSendEventsSuccessContext {\n /**\n * The partition each event was assigned.\n */\n partitionId: string;\n /**\n * The array of {@link EventData} and/or `AmqpAnnotatedMessage` that were successfully sent to the Event Hub.\n */\n events: Array<EventData | AmqpAnnotatedMessage>;\n}\n\n/**\n * Contains the events that were not successfully sent to the Event Hub,\n * the partition they were assigned to, and the error that was encountered while sending.\n */\nexport interface OnSendEventsErrorContext {\n /**\n * The partition each event was assigned.\n */\n partitionId: string;\n /**\n * The array of {@link EventData} and/or `AmqpAnnotatedMessage` that were not successfully sent to the Event Hub.\n */\n events: Array<EventData | AmqpAnnotatedMessage>;\n /**\n * The error that occurred when sending the associated events to the Event Hub.\n */\n error: Error;\n}\n\n/**\n * Describes the options that can be provided while creating the `EventHubBufferedProducerClient`.\n */\nexport interface EventHubBufferedProducerClientOptions extends EventHubClientOptions {\n /**\n * The total number of events that can be buffered for publishing at a given time for a given partition.\n *\n * Default: 1500\n */\n maxEventBufferLengthPerPartition?: number;\n /**\n * The amount of time to wait for a new event to be enqueued in the buffer before publishing a partially full batch.\n *\n * Default: 1 second.\n */\n maxWaitTimeInMs?: number;\n /**\n * The handler to call once a batch has successfully published.\n */\n onSendEventsSuccessHandler?: (ctx: OnSendEventsSuccessContext) => void;\n /**\n * The handler to call when a batch fails to publish.\n */\n onSendEventsErrorHandler: (ctx: OnSendEventsErrorContext) => void;\n /**\n * Indicates whether or not the EventHubProducerClient should enable idempotent publishing to Event Hub partitions.\n * If enabled, the producer will only be able to publish directly to partitions;\n * it will not be able to publish to the Event Hubs gateway for automatic partition routing\n * nor will it be able to use a partition key.\n * Default: false\n */\n enableIdempotentRetries?: boolean;\n}\n\n/**\n * Options to configure the `flush` method on the `EventHubBufferedProducerClient`.\n */\nexport interface BufferedFlushOptions extends OperationOptions {}\n\n/**\n * Options to configure the `close` method on the `EventHubBufferedProducerClient`.\n */\nexport interface BufferedCloseOptions extends OperationOptions {\n /**\n * When `true`, all buffered events that are pending should be sent before closing.\n * When `false`, abandon all buffered events and close immediately.\n * Defaults to `true`.\n */\n flush?: boolean;\n}\n\n/**\n * Options to configure the `enqueueEvents` method on the `EventHubBufferedProducerClient`.\n */\nexport interface EnqueueEventOptions extends SendBatchOptions {}\n\n/**\n * The `EventHubBufferedProducerClient`is used to publish events to a specific Event Hub.\n *\n * The `EventHubBufferedProducerClient` does not publish events immediately.\n * Instead, events are buffered so they can be efficiently batched and published\n * when the batch is full or the `maxWaitTimeInMs` has elapsed with no new events\n * enqueued.\n *\n * Depending on the options specified when events are enqueued, they may be\n * automatically assigned to a partition, grouped according to the specified partition key,\n * or assigned a specifically requested partition.\n *\n * This model is intended to shift the burden of batch management from callers, at the cost of\n * non-deterministic timing, for when events will be published. There are additional trade-offs\n * to consider, as well:\n * - If the application crashes, events in the buffer will not have been published. To prevent\n * data loss, callers are encouraged to track publishing progress using the\n * `onSendEventsSuccessHandler` and `onSendEventsErrorHandler` handlers.\n * - Events specifying a partition key may be assigned a different partition than those using\n * the same key with other producers.\n * - In the unlikely event that a partition becomes temporarily unavailable, the\n * `EventHubBufferedProducerClient` may take longer to recover than other producers.\n *\n * In scenarios where it is important to have events published immediately with a deterministic\n * outcome, ensure that partition keys are assigned to a partition consistent with other\n * publishers, or where maximizing availability is a requirement, using the\n * `EventHubProducerClient` is recommended.\n */\nexport class EventHubBufferedProducerClient {\n /**\n * Controls the `abortSignal` passed to each `BatchingPartitionChannel`.\n * Used to signal when a channel should stop waiting for events.\n */\n private _abortController = new AbortController();\n\n /**\n * Indicates whether the client has been explicitly closed.\n */\n private _isClosed: boolean = false;\n\n /**\n * Handles assigning partitions.\n */\n private _partitionAssigner = new PartitionAssigner();\n\n /**\n * The known partitionIds that will be used when assigning events to partitions.\n */\n private _partitionIds: string[] = [];\n\n /**\n * The EventHubProducerClient to use when creating and sending batches to the Event Hub.\n */\n private _producer: EventHubProducerClient;\n\n /**\n * Mapping of partitionIds to `BatchingPartitionChannels`.\n * Each `BatchingPartitionChannel` handles buffering events and backpressure independently.\n */\n private _partitionChannels = new Map<string, BatchingPartitionChannel>();\n\n /**\n * The options passed by the user when creating the EventHubBufferedProducerClient instance.\n */\n private _clientOptions: EventHubBufferedProducerClientOptions;\n\n /**\n * The interval at which the background management operation should run.\n */\n private _backgroundManagementInterval = 10000; // 10 seconds\n\n /**\n * Indicates whether the background management loop is running.\n */\n private _isBackgroundManagementRunning = false;\n\n /**\n * @readonly\n * The name of the Event Hub instance for which this client is created.\n */\n get eventHubName(): string {\n return this._producer.eventHubName;\n }\n\n /**\n * @readonly\n * The fully qualified namespace of the Event Hub instance for which this client is created.\n * This is likely to be similar to <yournamespace>.servicebus.windows.net.\n */\n get fullyQualifiedNamespace(): string {\n return this._producer.fullyQualifiedNamespace;\n }\n\n /**\n * The name used to identify this EventHubBufferedProducerClient.\n * If not specified or empty, a random unique one will be generated.\n */\n public readonly identifier: string;\n\n /**\n * The `EventHubBufferedProducerClient` class is used to send events to an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param connectionString - The connection string to use for connecting to the Event Hub instance.\n * It is expected that the shared key properties and the Event Hub path are contained in this connection string.\n * e.g. 'Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key;EntityPath=my-event-hub-name'.\n * @param options - A set of options to apply when configuring the client.\n * - `retryOptions` : Configures the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n * - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.\n * - `userAgent` : A string to append to the built in user agent string that is passed to the service.\n */\n constructor(connectionString: string, options: EventHubBufferedProducerClientOptions);\n /**\n * The `EventHubBufferedProducerClient` class is used to send events to an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param connectionString - The connection string to use for connecting to the Event Hubs namespace.\n * It is expected that the shared key properties are contained in this connection string, but not the Event Hub path,\n * e.g. 'Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key;'.\n * @param eventHubName - The name of the specific Event Hub to connect the client to.\n * @param options - A set of options to apply when configuring the client.\n * - `retryOptions` : Configures the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n * - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.\n * - `userAgent` : A string to append to the built in user agent string that is passed to the service.\n */\n constructor(\n connectionString: string,\n eventHubName: string,\n options: EventHubBufferedProducerClientOptions,\n );\n /**\n * The `EventHubBufferedProducerClient` class is used to send events to an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param fullyQualifiedNamespace - The full namespace which is likely to be similar to\n * <yournamespace>.servicebus.windows.net\n * @param eventHubName - The name of the specific Event Hub to connect the client to.\n * @param credential - An credential object used by the client to get the token to authenticate the connection\n * with the Azure Event Hubs service.\n * See @azure/identity for creating credentials that support AAD auth.\n * Use the `AzureNamedKeyCredential` from @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 @azure/core-auth if you want to pass in a `SharedAccessSignature`\n * without using a connection string. This field maps to `signature` in `AzureSASCredential`.\n * @param options - A set of options to apply when configuring the client.\n * - `retryOptions` : Configures the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n * - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.\n * - `userAgent` : A string to append to the built in user agent string that is passed to the service.\n */\n constructor(\n fullyQualifiedNamespace: string,\n eventHubName: string,\n credential: TokenCredential | NamedKeyCredential | SASCredential,\n options: EventHubBufferedProducerClientOptions,\n );\n constructor(\n fullyQualifiedNamespaceOrConnectionString1: string,\n eventHubNameOrOptions2: string | EventHubBufferedProducerClientOptions,\n credentialOrOptions3?:\n | TokenCredential\n | NamedKeyCredential\n | SASCredential\n | EventHubBufferedProducerClientOptions,\n options4?: EventHubBufferedProducerClientOptions,\n ) {\n if (typeof eventHubNameOrOptions2 !== \"string\") {\n this.identifier = eventHubNameOrOptions2.identifier ?? getRandomName();\n this._producer = new EventHubProducerClient(fullyQualifiedNamespaceOrConnectionString1, {\n ...eventHubNameOrOptions2,\n identifier: this.identifier,\n });\n this._clientOptions = { ...eventHubNameOrOptions2 };\n } else if (!isCredential(credentialOrOptions3)) {\n this.identifier = credentialOrOptions3?.identifier ?? getRandomName();\n this._producer = new EventHubProducerClient(\n fullyQualifiedNamespaceOrConnectionString1,\n eventHubNameOrOptions2,\n { ...credentialOrOptions3, identifier: this.identifier },\n );\n this._clientOptions = { ...credentialOrOptions3! };\n } else {\n this.identifier = options4?.identifier ?? getRandomName();\n this._producer = new EventHubProducerClient(\n fullyQualifiedNamespaceOrConnectionString1,\n eventHubNameOrOptions2,\n credentialOrOptions3,\n { ...options4, identifier: this.identifier },\n );\n this._clientOptions = { ...options4! };\n }\n // setting internal idempotent publishing option on the standard producer.\n (this._producer as any)._enableIdempotentRetries = this._clientOptions.enableIdempotentRetries;\n }\n\n /**\n * Closes the AMQP connection to the Event Hub instance,\n * returning a promise that will be resolved when disconnection is completed.\n *\n * This will wait for enqueued events to be flushed to the service before closing\n * the connection.\n * To close without flushing, set the `flush` option to `false`.\n *\n * @param options - The set of options to apply to the operation call.\n * @returns Promise<void>\n * @throws Error if the underlying connection encounters an error while closing.\n */\n async close(options: BufferedCloseOptions = {}): Promise<void> {\n logger.verbose(\"closing buffered producer client...\");\n if (!isDefined(options.flush) || options.flush === true) {\n await this.flush(options);\n }\n // Calling abort signals to the BatchingPartitionChannels that they\n // should stop reading/sending events, and to the background management\n // loop that it should stop periodic partition id updates.\n this._abortController.abort();\n await this._producer.close();\n this._isClosed = true;\n }\n\n /**\n * Enqueues an event into the buffer to be published to the Event Hub.\n * If there is no capacity in the buffer when this method is invoked,\n * it will wait for space to become available and ensure that the event\n * has been enqueued.\n *\n * When this call returns, the event has been accepted into the buffer,\n * but it may not have been published yet.\n * Publishing will take place at a nondeterministic point in the future as the buffer is processed.\n *\n * @param events - An {@link EventData} or `AmqpAnnotatedMessage`.\n * @param options - A set of options that can be specified to influence the way in which\n * the event is sent to the associated Event Hub.\n * - `abortSignal` : A signal used to cancel the enqueueEvent operation.\n * - `partitionId` : The partition this set of events will be sent to. If set, `partitionKey` can not be set.\n * - `partitionKey` : A value that is hashed to produce a partition assignment. If set, `partitionId` can not be set.\n * @returns The total number of events that are currently buffered and waiting to be published, across all partitions.\n */\n async enqueueEvent(\n event: EventData | AmqpAnnotatedMessage,\n options: EnqueueEventOptions = {},\n ): Promise<number> {\n if (this._isClosed) {\n throw new Error(\n `This EventHubBufferedProducerClient has already been closed. Create a new client to enqueue events.`,\n );\n }\n\n if (!this._partitionIds.length) {\n await this._updatePartitionIds();\n }\n if (!this._isBackgroundManagementRunning) {\n this._startPartitionIdsUpdateLoop().catch((e) => {\n logger.error(\n `The following error occured during batch creation or sending: ${JSON.stringify(\n e,\n undefined,\n \" \",\n )}`,\n );\n });\n this._isBackgroundManagementRunning = true;\n }\n\n const partitionId = this._partitionAssigner.assignPartition({\n partitionId: options.partitionId,\n partitionKey: options.partitionKey,\n });\n\n const partitionChannel = this._getPartitionChannel(partitionId);\n await partitionChannel.enqueueEvent(event);\n return this._getTotalBufferedEventsCount();\n }\n\n /**\n * Enqueues events into the buffer to be published to the Event Hub.\n * If there is no capacity in the buffer when this method is invoked,\n * it will wait for space to become available and ensure that the events\n * have been enqueued.\n *\n * When this call returns, the events have been accepted into the buffer,\n * but it may not have been published yet.\n * Publishing will take place at a nondeterministic point in the future as the buffer is processed.\n *\n * @param events - An array of {@link EventData} or `AmqpAnnotatedMessage`.\n * @param options - A set of options that can be specified to influence the way in which\n * events are sent to the associated Event Hub.\n * - `abortSignal` : A signal used to cancel the enqueueEvents operation.\n * - `partitionId` : The partition this set of events will be sent to. If set, `partitionKey` can not be set.\n * - `partitionKey` : A value that is hashed to produce a partition assignment. If set, `partitionId` can not be set.\n * @returns The total number of events that are currently buffered and waiting to be published, across all partitions.\n */\n async enqueueEvents(\n events: EventData[] | AmqpAnnotatedMessage[],\n // eslint-disable-next-line @azure/azure-sdk/ts-naming-options\n options: EnqueueEventOptions = {},\n ): Promise<number> {\n for (const event of events) {\n await this.enqueueEvent(event, options);\n }\n\n return this._getTotalBufferedEventsCount();\n }\n\n /**\n * Attempts to publish all events in the buffer immediately.\n * This may result in multiple batches being published,\n * the outcome of each of which will be individually reported by\n * the `onSendEventsSuccessHandler` and `onSendEventsErrorHandler` handlers.\n *\n * @param options - The set of options to apply to the operation call.\n */\n async flush(options: BufferedFlushOptions = {}): Promise<void> {\n await Promise.all(\n Array.from(this._partitionChannels.values()).map((channel) => channel.flush(options)),\n );\n }\n\n /**\n * Provides the Event Hub runtime information.\n * @param options - The set of options to apply to the operation call.\n * @returns A promise that resolves with information about the Event Hub instance.\n * @throws Error if the underlying connection has been closed, create a new EventHubBufferedProducerClient.\n * @throws AbortError if the operation is cancelled via the abortSignal.\n */\n getEventHubProperties(options: GetEventHubPropertiesOptions = {}): Promise<EventHubProperties> {\n return this._producer.getEventHubProperties(options);\n }\n\n /**\n * Provides the id for each partition associated with the Event Hub.\n * @param options - The set of options to apply to the operation call.\n * @returns A promise that resolves with an Array of strings representing the id for\n * each partition associated with the Event Hub.\n * @throws Error if the underlying connection has been closed, create a new EventHubBufferedProducerClient.\n * @throws AbortError if the operation is cancelled via the abortSignal.\n */\n getPartitionIds(options: GetPartitionIdsOptions = {}): Promise<Array<string>> {\n return this._producer.getPartitionIds(options);\n }\n\n /**\n * Provides information about the state of the specified partition.\n * @param partitionId - The id of the partition for which information is required.\n * @param options - The set of options to apply to the operation call.\n * @returns A promise that resolves with information about the state of the partition .\n * @throws Error if the underlying connection has been closed, create a new EventHubBufferedProducerClient.\n * @throws AbortError if the operation is cancelled via the abortSignal.\n */\n getPartitionProperties(\n partitionId: string,\n options: GetPartitionPropertiesOptions = {},\n ): Promise<PartitionProperties> {\n return this._producer.getPartitionProperties(partitionId, options);\n }\n\n /**\n * Gets the `BatchingPartitionChannel` associated with the partitionId.\n *\n * If one does not exist, it is created.\n */\n private _getPartitionChannel(partitionId: string): BatchingPartitionChannel {\n const partitionChannel =\n this._partitionChannels.get(partitionId) ??\n new BatchingPartitionChannel({\n loopAbortSignal: this._abortController.signal,\n maxBufferSize: this._clientOptions.maxEventBufferLengthPerPartition || 1500,\n maxWaitTimeInMs: this._clientOptions.maxWaitTimeInMs || 1000,\n onSendEventsErrorHandler: this._clientOptions.onSendEventsErrorHandler,\n onSendEventsSuccessHandler: this._clientOptions.onSendEventsSuccessHandler,\n partitionId,\n producer: this._producer,\n });\n this._partitionChannels.set(partitionId, partitionChannel);\n return partitionChannel;\n }\n\n /**\n * Returns the total number of buffered events across all partitions.\n */\n private _getTotalBufferedEventsCount(): number {\n let total = 0;\n for (const [_, channel] of this._partitionChannels) {\n total += channel.getCurrentBufferedCount();\n }\n\n return total;\n }\n\n private async _updatePartitionIds(): Promise<void> {\n logger.verbose(\"Checking for partition Id updates...\");\n const queriedPartitionIds = await this.getPartitionIds();\n\n if (this._partitionIds.length !== queriedPartitionIds.length) {\n logger.verbose(\"Applying partition Id updates\");\n this._partitionIds = queriedPartitionIds;\n this._partitionAssigner.setPartitionIds(this._partitionIds);\n }\n }\n\n private async _startPartitionIdsUpdateLoop(): Promise<void> {\n logger.verbose(\"Starting a background loop to check and apply partition id updates...\");\n while (!this._abortController.signal.aborted && !this._isClosed) {\n await delay<void>(this._backgroundManagementInterval);\n if (!this._isClosed) {\n await this._updatePartitionIds();\n }\n }\n }\n}\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { CheckpointStore } from "./eventProcessor.js";
|
|
2
|
-
import { EventHubConsumerClientOptions, GetEventHubPropertiesOptions, GetPartitionIdsOptions, GetPartitionPropertiesOptions } from "./models/public.js";
|
|
3
|
-
import { EventHubProperties, PartitionProperties } from "./managementClient.js";
|
|
4
|
-
import { NamedKeyCredential, SASCredential, TokenCredential } from "@azure/core-auth";
|
|
5
|
-
import { SubscribeOptions, Subscription, SubscriptionEventHandlers } from "./eventHubConsumerClientModels.js";
|
|
1
|
+
import type { CheckpointStore } from "./eventProcessor.js";
|
|
2
|
+
import type { EventHubConsumerClientOptions, GetEventHubPropertiesOptions, GetPartitionIdsOptions, GetPartitionPropertiesOptions } from "./models/public.js";
|
|
3
|
+
import type { EventHubProperties, PartitionProperties } from "./managementClient.js";
|
|
4
|
+
import type { NamedKeyCredential, SASCredential, TokenCredential } from "@azure/core-auth";
|
|
5
|
+
import type { SubscribeOptions, Subscription, SubscriptionEventHandlers } from "./eventHubConsumerClientModels.js";
|
|
6
6
|
/**
|
|
7
7
|
* The `EventHubConsumerClient` class is used to consume events from an Event Hub.
|
|
8
8
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eventHubConsumerClient.d.ts","sourceRoot":"","sources":["../../src/eventHubConsumerClient.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"eventHubConsumerClient.d.ts","sourceRoot":"","sources":["../../src/eventHubConsumerClient.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAA6B,MAAM,qBAAqB,CAAC;AAItF,OAAO,KAAK,EACV,6BAA6B,EAC7B,4BAA4B,EAC5B,sBAAsB,EACtB,6BAA6B,EAE9B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,E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;IACJ,CAAC;;AAhjBD;;GAEG;AACI,+CAAwB,GAAW,SAAS,CAAC,oBAAoB,AAAzC,CAA0C;AAgjB3E;;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 { CheckpointStore, EventProcessor, FullEventProcessorOptions } from \"./eventProcessor.js\";\nimport { ConnectionContext, createConnectionContext } from \"./connectionContext.js\";\nimport {\n EventHubConsumerClientOptions,\n GetEventHubPropertiesOptions,\n GetPartitionIdsOptions,\n GetPartitionPropertiesOptions,\n LoadBalancingOptions,\n} from \"./models/public.js\";\nimport { EventHubProperties, PartitionProperties } from \"./managementClient.js\";\nimport { NamedKeyCredential, SASCredential, TokenCredential } from \"@azure/core-auth\";\nimport {\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 { 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 @azure/identity for creating credentials that support AAD auth.\n * Use the `AzureNamedKeyCredential` from @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 @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 @azure/identity for creating credentials that support AAD auth.\n * Use the `AzureNamedKeyCredential` from @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 @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\n * const client = new EventHubConsumerClient(consumerGroup, connectionString, eventHubName);\n * const subscription = client.subscribe(\n * {\n * processEvents: (events, context) => { console.log(\"Received event count: \", events.length) },\n * processError: (err, context) => { console.log(\"Error: \", err) }\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\n * const client = new EventHubConsumerClient(consumerGroup, connectionString, eventHubName);\n * const subscription = client.subscribe(\n * partitionId,\n * {\n * processEvents: (events, context) => { console.log(\"Received event count: \", events.length) },\n * processError: (err, context) => { console.log(\"Error: \", err) }\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,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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I,+CAAwB,GAAW,SAAS,CAAC,oBAAoB,AAAzC,CAA0C;AAgjB3E;;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 @azure/identity for creating credentials that support AAD auth.\n * Use the `AzureNamedKeyCredential` from @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 @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 @azure/identity for creating credentials that support AAD auth.\n * Use the `AzureNamedKeyCredential` from @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 @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\n * const client = new EventHubConsumerClient(consumerGroup, connectionString, eventHubName);\n * const subscription = client.subscribe(\n * {\n * processEvents: (events, context) => { console.log(\"Received event count: \", events.length) },\n * processError: (err, context) => { console.log(\"Error: \", err) }\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\n * const client = new EventHubConsumerClient(consumerGroup, connectionString, eventHubName);\n * const subscription = client.subscribe(\n * partitionId,\n * {\n * processEvents: (events, context) => { console.log(\"Received event count: \", events.length) },\n * processError: (err, context) => { console.log(\"Error: \", err) }\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,9 +1,9 @@
|
|
|
1
|
-
import { CloseReason } from "./models/public.js";
|
|
2
|
-
import { EventPosition } from "./eventPosition.js";
|
|
3
|
-
import { LastEnqueuedEventProperties } from "./partitionReceiver.js";
|
|
4
|
-
import { MessagingError } from "@azure/core-amqp";
|
|
5
|
-
import { OperationTracingOptions } from "@azure/core-tracing";
|
|
6
|
-
import { ReceivedEventData } from "./eventData.js";
|
|
1
|
+
import type { CloseReason } from "./models/public.js";
|
|
2
|
+
import type { EventPosition } from "./eventPosition.js";
|
|
3
|
+
import type { LastEnqueuedEventProperties } from "./partitionReceiver.js";
|
|
4
|
+
import type { MessagingError } from "@azure/core-amqp";
|
|
5
|
+
import type { OperationTracingOptions } from "@azure/core-tracing";
|
|
6
|
+
import type { ReceivedEventData } from "./eventData.js";
|
|
7
7
|
/**
|
|
8
8
|
* @internal
|
|
9
9
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eventHubConsumerClientModels.d.ts","sourceRoot":"","sources":["../../src/eventHubConsumerClientModels.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"eventHubConsumerClientModels.d.ts","sourceRoot":"","sources":["../../src/eventHubConsumerClientModels.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,KAA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H,MAAM,MAAM,mBAAmB,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,gBAAgB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEpG;;;;GAIG;AACH,MAAM,WAAW,yBAAyB;IACxC;;;;;;;;;;;;;OAaG;IACH,aAAa,EAAE,oBAAoB,CAAC;IACpC;;;;;;;;;OASG;IACH,YAAY,EAAE,mBAAmB,CAAC;IAClC;;;;;;;;OAQG;IACH,iBAAiB,CAAC,EAAE,wBAAwB,CAAC;IAC7C;;;;;;;;;;;;OAYG;IACH,YAAY,CAAC,EAAE,mBAAmB,CAAC;CACpC;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;OAIG;IACH,aAAa,CAAC,EAAE,aAAa,GAAG;QAAE,CAAC,WAAW,EAAE,MAAM,GAAG,aAAa,CAAA;KAAE,CAAC;IACzE;;;;;;;;OAQG;IACH,gCAAgC,CAAC,EAAE,OAAO,CAAC;IAC3C;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,cAAc,CAAC,EAAE,uBAAuB,CAAC;IACzC;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;;;;OAQG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB;;;;OAIG;IACH,SAAS,EAAE,OAAO,CAAC;CACpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eventHubConsumerClientModels.js","sourceRoot":"","sources":["../../src/eventHubConsumerClientModels.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { CloseReason } from \"./models/public.js\";\nimport { EventPosition } from \"./eventPosition.js\";\nimport { LastEnqueuedEventProperties } from \"./partitionReceiver.js\";\nimport { MessagingError } from \"@azure/core-amqp\";\nimport { OperationTracingOptions } from \"@azure/core-tracing\";\nimport { ReceivedEventData } from \"./eventData.js\";\n\n/**\n * @internal\n */\nexport interface BasicPartitionProperties {\n /**\n * The fully qualified Event Hubs namespace. This is likely to be similar to\n * <yournamespace>.servicebus.windows.net\n */\n fullyQualifiedNamespace: string;\n /**\n * The event hub name.\n */\n eventHubName: string;\n /**\n * The consumer group name.\n */\n consumerGroup: string;\n /**\n * The identifier of the Event Hub partition.\n */\n partitionId: string;\n}\n\n/**\n * Interface that describes the context passed to each of the functions that are a part\n * of the `SubscriptionEventHandlers`. When implementing any of these functions, use\n * the context object to get information about the partition as well as the\n * ability to checkpoint.\n */\nexport interface PartitionContext {\n /**\n * The fully qualified Event Hubs namespace. This is likely to be similar to\n * <yournamespace>.servicebus.windows.net\n */\n readonly fullyQualifiedNamespace: string;\n /**\n * The event hub name.\n */\n readonly eventHubName: string;\n /**\n * The consumer group name.\n */\n readonly consumerGroup: string;\n /**\n * The identifier of the Event Hub partition.\n */\n readonly partitionId: string;\n /**\n * Information on the last enqueued event in the partition that is being processed.\n * This property is only updated if the `trackLastEnqueuedEventProperties` option is set to true\n * when creating an instance of EventProcessor.\n * @readonly\n */\n readonly lastEnqueuedEventProperties?: LastEnqueuedEventProperties;\n /**\n * Updates the checkpoint using the event data.\n *\n * A checkpoint is meant to represent the last successfully processed event by the user from a particular\n * partition of a consumer group in an Event Hub instance.\n *\n * @param eventData - The event that you want to update the checkpoint with.\n */\n updateCheckpoint(eventData: ReceivedEventData): Promise<void>;\n}\n\n/**\n * Signature of the user provided function invoked by `EventHubConsumerClient` when a set of events is received.\n */\nexport type ProcessEventsHandler = (\n events: ReceivedEventData[],\n context: PartitionContext,\n) => Promise<void>;\n\n/**\n * Signature of the user provided function invoked by `EventHubConsumerClient` for errors that occur when\n * receiving events or when executing any of the user provided functions passed to the `subscribe()` method.\n */\nexport type ProcessErrorHandler = (\n error: Error | MessagingError,\n context: PartitionContext,\n) => Promise<void>;\n\n/**\n * Signature of the user provided function invoked by `EventHubConsumerClient` just before starting to receive\n * events from a partition.\n */\nexport type ProcessInitializeHandler = (context: PartitionContext) => Promise<void>;\n\n/**\n * Signature of the user provided function invoked by `EventHubConsumerClient` just after stopping to receive\n * events from a partition.\n */\nexport type ProcessCloseHandler = (reason: CloseReason, context: PartitionContext) => Promise<void>;\n\n/**\n * Interface that describes the functions to be implemented by the user which are invoked by\n * the `EventHubConsumerClient` when the `subscribe()` method is called to receive events\n * from Event Hub.\n */\nexport interface SubscriptionEventHandlers {\n /**\n * The function invoked by `EventHubConsumerClient` when a set of events is received. The\n * `PartitionContext` passed to this function can be used to determine which partition is being read from.\n *\n * The `updateCheckpoint()` method on the context can be used to update checkpoints in the `CheckpointStore`\n * (if one was provided to the client). Use this in frequent intervals to mark events that have been processed\n * so that the client can restart from such checkpoints in the event of a restart or error recovery.\n *\n * Note: It is possible for received events to be an empty array.\n * This can happen if there are no new events to receive\n * in the `maxWaitTimeInSeconds`, which is defaulted to 60 seconds.\n * The `maxWaitTimeInSeconds` can be changed by setting\n * it in the `options` passed to `subscribe()`.\n */\n processEvents: ProcessEventsHandler;\n /**\n * The function invoked by `EventHubConsumerClient` for errors that occur when receiving events\n * or when executing any of the user provided functions passed to the `subscribe()` method.\n *\n * The `PartitionContext` passed to this function will indicate the partition that was being processed\n * when the error was thrown. In cases where an error is thrown outside of processing events from a\n * partition(e.g. failure to perform load balancing), the `partitionId` on the context will be an empty string.\n *\n * After the client completes executing this function, the `partitionClose` function is invoked.\n */\n processError: ProcessErrorHandler;\n /**\n * The function invoked by `EventHubConsumerClient` each time the subscription is about to begin\n * reading from a partition. The `PartitionContext` passed to this function can be used to determine\n * which partition is about to be read from.\n *\n * The client will start receiving events for the partition only after completing the execution of\n * this function (if provided). Therefore, use this function to carry out any setup work including\n * async tasks.\n */\n processInitialize?: ProcessInitializeHandler;\n /**\n * The function invoked by `EventHubConsumerClient` each time the subscription stops reading events from\n * a partition. The information on this partition will be available on the `PartitionContext` passed to the\n * function `processClose`.\n *\n * If the `CloseReason` passed to this function is `OwnershipLost`, then another subscription has taken over\n * reading from the same partition using the same consumer group. This is expected if you have multiple\n * instances of your application running and have passed the `CheckpointStore` to the client to load balance.\n *\n * If the `CloseReason` is `Shutdown`, this indicates that either `subscription.close()` was called, or an\n * error occured. Unless the subscription was explicitly closed via `subscription.close()`, the subscription\n * will attempt to resume reading events from the last checkpoint for the partition.\n */\n processClose?: ProcessCloseHandler;\n}\n\n/**\n * Options to configure the `subscribe` method on the `EventHubConsumerClient`.\n * For example, `{ maxBatchSize: 20, maxWaitTimeInSeconds: 120, startPosition: { sequenceNumber: 123 } }`\n */\nexport interface SubscribeOptions {\n /**\n * The number of events to request per batch\n */\n maxBatchSize?: number;\n /**\n * The maximum amount of time to wait to build up the requested message count before\n * passing the data to user code for processing. If not provided, it defaults to 60 seconds.\n */\n maxWaitTimeInSeconds?: number;\n /**\n * The event position in a partition to start receiving events from if no checkpoint is found.\n * Pass a map of partition id to position if you would like to use different starting\n * position for each partition.\n */\n startPosition?: EventPosition | { [partitionId: string]: EventPosition };\n /**\n * Indicates whether or not the consumer should request information on the last enqueued event on its\n * associated partition, and track that information as events are received.\n\n * When information about the partition's last enqueued event is being tracked, each event received\n * from the Event Hubs service will carry metadata about the partition that it otherwise would not. This results in a small amount of\n * additional network bandwidth consumption that is generally a favorable trade-off when considered\n * against periodically making requests for partition properties using the Event Hub client.\n */\n trackLastEnqueuedEventProperties?: boolean;\n /**\n * The owner level to use as this subscription subscribes to partitions.\n */\n ownerLevel?: number;\n /**\n * Options for configuring tracing.\n */\n tracingOptions?: OperationTracingOptions;\n /**\n * Option to disable the client from running JSON.parse() on the message body when receiving the message.\n * Not applicable if the message was sent with AMQP body type value or sequence. Use this option when you\n * prefer to work directly with the bytes present in the message body than have the client attempt to parse it.\n */\n skipParsingBodyAsJson?: boolean;\n /**\n * The count of events requested eagerly and queued without regard to whether a read was requested.\n */\n prefetchCount?: number;\n}\n\n/**\n * Interface that describes the object returned by the `subscribe()` method on the `EventHubConsumerClient`.\n */\nexport interface Subscription {\n /**\n * Stops the subscription from receiving more messages.\n *\n * If a checkpoint store has been configured this will also mark this subscription's\n * partitions as abandoned, freeing them up to be read by other consumers.\n *\n * @returns Promise<void>\n * @throws Error if the underlying connection encounters an error while closing.\n */\n close(): Promise<void>;\n /**\n * Indicates whether the receiver is running.\n * `true` - is running; `false` otherwise.\n * @readonly\n */\n isRunning: boolean;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"eventHubConsumerClientModels.js","sourceRoot":"","sources":["../../src/eventHubConsumerClientModels.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { CloseReason } from \"./models/public.js\";\nimport type { EventPosition } from \"./eventPosition.js\";\nimport type { LastEnqueuedEventProperties } from \"./partitionReceiver.js\";\nimport type { MessagingError } from \"@azure/core-amqp\";\nimport type { OperationTracingOptions } from \"@azure/core-tracing\";\nimport type { ReceivedEventData } from \"./eventData.js\";\n\n/**\n * @internal\n */\nexport interface BasicPartitionProperties {\n /**\n * The fully qualified Event Hubs namespace. This is likely to be similar to\n * <yournamespace>.servicebus.windows.net\n */\n fullyQualifiedNamespace: string;\n /**\n * The event hub name.\n */\n eventHubName: string;\n /**\n * The consumer group name.\n */\n consumerGroup: string;\n /**\n * The identifier of the Event Hub partition.\n */\n partitionId: string;\n}\n\n/**\n * Interface that describes the context passed to each of the functions that are a part\n * of the `SubscriptionEventHandlers`. When implementing any of these functions, use\n * the context object to get information about the partition as well as the\n * ability to checkpoint.\n */\nexport interface PartitionContext {\n /**\n * The fully qualified Event Hubs namespace. This is likely to be similar to\n * <yournamespace>.servicebus.windows.net\n */\n readonly fullyQualifiedNamespace: string;\n /**\n * The event hub name.\n */\n readonly eventHubName: string;\n /**\n * The consumer group name.\n */\n readonly consumerGroup: string;\n /**\n * The identifier of the Event Hub partition.\n */\n readonly partitionId: string;\n /**\n * Information on the last enqueued event in the partition that is being processed.\n * This property is only updated if the `trackLastEnqueuedEventProperties` option is set to true\n * when creating an instance of EventProcessor.\n * @readonly\n */\n readonly lastEnqueuedEventProperties?: LastEnqueuedEventProperties;\n /**\n * Updates the checkpoint using the event data.\n *\n * A checkpoint is meant to represent the last successfully processed event by the user from a particular\n * partition of a consumer group in an Event Hub instance.\n *\n * @param eventData - The event that you want to update the checkpoint with.\n */\n updateCheckpoint(eventData: ReceivedEventData): Promise<void>;\n}\n\n/**\n * Signature of the user provided function invoked by `EventHubConsumerClient` when a set of events is received.\n */\nexport type ProcessEventsHandler = (\n events: ReceivedEventData[],\n context: PartitionContext,\n) => Promise<void>;\n\n/**\n * Signature of the user provided function invoked by `EventHubConsumerClient` for errors that occur when\n * receiving events or when executing any of the user provided functions passed to the `subscribe()` method.\n */\nexport type ProcessErrorHandler = (\n error: Error | MessagingError,\n context: PartitionContext,\n) => Promise<void>;\n\n/**\n * Signature of the user provided function invoked by `EventHubConsumerClient` just before starting to receive\n * events from a partition.\n */\nexport type ProcessInitializeHandler = (context: PartitionContext) => Promise<void>;\n\n/**\n * Signature of the user provided function invoked by `EventHubConsumerClient` just after stopping to receive\n * events from a partition.\n */\nexport type ProcessCloseHandler = (reason: CloseReason, context: PartitionContext) => Promise<void>;\n\n/**\n * Interface that describes the functions to be implemented by the user which are invoked by\n * the `EventHubConsumerClient` when the `subscribe()` method is called to receive events\n * from Event Hub.\n */\nexport interface SubscriptionEventHandlers {\n /**\n * The function invoked by `EventHubConsumerClient` when a set of events is received. The\n * `PartitionContext` passed to this function can be used to determine which partition is being read from.\n *\n * The `updateCheckpoint()` method on the context can be used to update checkpoints in the `CheckpointStore`\n * (if one was provided to the client). Use this in frequent intervals to mark events that have been processed\n * so that the client can restart from such checkpoints in the event of a restart or error recovery.\n *\n * Note: It is possible for received events to be an empty array.\n * This can happen if there are no new events to receive\n * in the `maxWaitTimeInSeconds`, which is defaulted to 60 seconds.\n * The `maxWaitTimeInSeconds` can be changed by setting\n * it in the `options` passed to `subscribe()`.\n */\n processEvents: ProcessEventsHandler;\n /**\n * The function invoked by `EventHubConsumerClient` for errors that occur when receiving events\n * or when executing any of the user provided functions passed to the `subscribe()` method.\n *\n * The `PartitionContext` passed to this function will indicate the partition that was being processed\n * when the error was thrown. In cases where an error is thrown outside of processing events from a\n * partition(e.g. failure to perform load balancing), the `partitionId` on the context will be an empty string.\n *\n * After the client completes executing this function, the `partitionClose` function is invoked.\n */\n processError: ProcessErrorHandler;\n /**\n * The function invoked by `EventHubConsumerClient` each time the subscription is about to begin\n * reading from a partition. The `PartitionContext` passed to this function can be used to determine\n * which partition is about to be read from.\n *\n * The client will start receiving events for the partition only after completing the execution of\n * this function (if provided). Therefore, use this function to carry out any setup work including\n * async tasks.\n */\n processInitialize?: ProcessInitializeHandler;\n /**\n * The function invoked by `EventHubConsumerClient` each time the subscription stops reading events from\n * a partition. The information on this partition will be available on the `PartitionContext` passed to the\n * function `processClose`.\n *\n * If the `CloseReason` passed to this function is `OwnershipLost`, then another subscription has taken over\n * reading from the same partition using the same consumer group. This is expected if you have multiple\n * instances of your application running and have passed the `CheckpointStore` to the client to load balance.\n *\n * If the `CloseReason` is `Shutdown`, this indicates that either `subscription.close()` was called, or an\n * error occured. Unless the subscription was explicitly closed via `subscription.close()`, the subscription\n * will attempt to resume reading events from the last checkpoint for the partition.\n */\n processClose?: ProcessCloseHandler;\n}\n\n/**\n * Options to configure the `subscribe` method on the `EventHubConsumerClient`.\n * For example, `{ maxBatchSize: 20, maxWaitTimeInSeconds: 120, startPosition: { sequenceNumber: 123 } }`\n */\nexport interface SubscribeOptions {\n /**\n * The number of events to request per batch\n */\n maxBatchSize?: number;\n /**\n * The maximum amount of time to wait to build up the requested message count before\n * passing the data to user code for processing. If not provided, it defaults to 60 seconds.\n */\n maxWaitTimeInSeconds?: number;\n /**\n * The event position in a partition to start receiving events from if no checkpoint is found.\n * Pass a map of partition id to position if you would like to use different starting\n * position for each partition.\n */\n startPosition?: EventPosition | { [partitionId: string]: EventPosition };\n /**\n * Indicates whether or not the consumer should request information on the last enqueued event on its\n * associated partition, and track that information as events are received.\n\n * When information about the partition's last enqueued event is being tracked, each event received\n * from the Event Hubs service will carry metadata about the partition that it otherwise would not. This results in a small amount of\n * additional network bandwidth consumption that is generally a favorable trade-off when considered\n * against periodically making requests for partition properties using the Event Hub client.\n */\n trackLastEnqueuedEventProperties?: boolean;\n /**\n * The owner level to use as this subscription subscribes to partitions.\n */\n ownerLevel?: number;\n /**\n * Options for configuring tracing.\n */\n tracingOptions?: OperationTracingOptions;\n /**\n * Option to disable the client from running JSON.parse() on the message body when receiving the message.\n * Not applicable if the message was sent with AMQP body type value or sequence. Use this option when you\n * prefer to work directly with the bytes present in the message body than have the client attempt to parse it.\n */\n skipParsingBodyAsJson?: boolean;\n /**\n * The count of events requested eagerly and queued without regard to whether a read was requested.\n */\n prefetchCount?: number;\n}\n\n/**\n * Interface that describes the object returned by the `subscribe()` method on the `EventHubConsumerClient`.\n */\nexport interface Subscription {\n /**\n * Stops the subscription from receiving more messages.\n *\n * If a checkpoint store has been configured this will also mark this subscription's\n * partitions as abandoned, freeing them up to be read by other consumers.\n *\n * @returns Promise<void>\n * @throws Error if the underlying connection encounters an error while closing.\n */\n close(): Promise<void>;\n /**\n * Indicates whether the receiver is running.\n * `true` - is running; `false` otherwise.\n * @readonly\n */\n isRunning: boolean;\n}\n"]}
|