@azure/event-hubs 6.0.2-alpha.20251014.1 → 6.0.2-alpha.20251021.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/batchingPartitionChannel.d.ts.map +1 -1
- package/dist/browser/batchingPartitionChannel.js +2 -1
- package/dist/browser/batchingPartitionChannel.js.map +1 -1
- package/dist/browser/connectionContext.d.ts.map +1 -1
- package/dist/browser/connectionContext.js +10 -4
- package/dist/browser/connectionContext.js.map +1 -1
- package/dist/browser/eventHubBufferedProducerClient.d.ts.map +1 -1
- package/dist/browser/eventHubBufferedProducerClient.js +2 -1
- package/dist/browser/eventHubBufferedProducerClient.js.map +1 -1
- package/dist/browser/eventHubConsumerClient.d.ts.map +1 -1
- package/dist/browser/eventHubConsumerClient.js +3 -6
- package/dist/browser/eventHubConsumerClient.js.map +1 -1
- package/dist/browser/eventHubProducerClient.d.ts.map +1 -1
- package/dist/browser/eventHubProducerClient.js +3 -6
- package/dist/browser/eventHubProducerClient.js.map +1 -1
- package/dist/browser/eventHubSender.d.ts.map +1 -1
- package/dist/browser/eventHubSender.js +6 -4
- package/dist/browser/eventHubSender.js.map +1 -1
- package/dist/browser/partitionReceiver.js +4 -4
- package/dist/browser/partitionReceiver.js.map +1 -1
- package/dist/browser/util/timerLoop.d.ts.map +1 -1
- package/dist/browser/util/timerLoop.js +12 -5
- package/dist/browser/util/timerLoop.js.map +1 -1
- package/dist/commonjs/batchingPartitionChannel.d.ts.map +1 -1
- package/dist/commonjs/batchingPartitionChannel.js +2 -1
- package/dist/commonjs/batchingPartitionChannel.js.map +1 -1
- package/dist/commonjs/connectionContext.d.ts.map +1 -1
- package/dist/commonjs/connectionContext.js +10 -4
- package/dist/commonjs/connectionContext.js.map +1 -1
- package/dist/commonjs/eventHubBufferedProducerClient.d.ts.map +1 -1
- package/dist/commonjs/eventHubBufferedProducerClient.js +2 -1
- package/dist/commonjs/eventHubBufferedProducerClient.js.map +1 -1
- package/dist/commonjs/eventHubConsumerClient.d.ts.map +1 -1
- package/dist/commonjs/eventHubConsumerClient.js +3 -6
- package/dist/commonjs/eventHubConsumerClient.js.map +1 -1
- package/dist/commonjs/eventHubProducerClient.d.ts.map +1 -1
- package/dist/commonjs/eventHubProducerClient.js +3 -6
- package/dist/commonjs/eventHubProducerClient.js.map +1 -1
- package/dist/commonjs/eventHubSender.d.ts.map +1 -1
- package/dist/commonjs/eventHubSender.js +6 -4
- package/dist/commonjs/eventHubSender.js.map +1 -1
- package/dist/commonjs/partitionReceiver.js +4 -4
- package/dist/commonjs/partitionReceiver.js.map +1 -1
- package/dist/commonjs/util/timerLoop.d.ts.map +1 -1
- package/dist/commonjs/util/timerLoop.js +12 -5
- package/dist/commonjs/util/timerLoop.js.map +1 -1
- package/dist/esm/batchingPartitionChannel.d.ts.map +1 -1
- package/dist/esm/batchingPartitionChannel.js +2 -1
- package/dist/esm/batchingPartitionChannel.js.map +1 -1
- package/dist/esm/connectionContext.d.ts.map +1 -1
- package/dist/esm/connectionContext.js +10 -4
- package/dist/esm/connectionContext.js.map +1 -1
- package/dist/esm/eventHubBufferedProducerClient.d.ts.map +1 -1
- package/dist/esm/eventHubBufferedProducerClient.js +2 -1
- package/dist/esm/eventHubBufferedProducerClient.js.map +1 -1
- package/dist/esm/eventHubConsumerClient.d.ts.map +1 -1
- package/dist/esm/eventHubConsumerClient.js +3 -6
- package/dist/esm/eventHubConsumerClient.js.map +1 -1
- package/dist/esm/eventHubProducerClient.d.ts.map +1 -1
- package/dist/esm/eventHubProducerClient.js +3 -6
- package/dist/esm/eventHubProducerClient.js.map +1 -1
- package/dist/esm/eventHubSender.d.ts.map +1 -1
- package/dist/esm/eventHubSender.js +6 -4
- package/dist/esm/eventHubSender.js.map +1 -1
- package/dist/esm/partitionReceiver.js +4 -4
- package/dist/esm/partitionReceiver.js.map +1 -1
- package/dist/esm/util/timerLoop.d.ts.map +1 -1
- package/dist/esm/util/timerLoop.js +12 -5
- package/dist/esm/util/timerLoop.js.map +1 -1
- package/dist/react-native/batchingPartitionChannel.d.ts +94 -0
- package/dist/react-native/batchingPartitionChannel.d.ts.map +1 -0
- package/dist/react-native/batchingPartitionChannel.js +255 -0
- package/dist/react-native/batchingPartitionChannel.js.map +1 -0
- package/dist/react-native/connectionContext.d.ts +108 -0
- package/dist/react-native/connectionContext.d.ts.map +1 -0
- package/dist/react-native/connectionContext.js +310 -0
- package/dist/react-native/connectionContext.js.map +1 -0
- package/dist/react-native/dataTransformer.d.ts +53 -0
- package/dist/react-native/dataTransformer.d.ts.map +1 -0
- package/dist/react-native/dataTransformer.js +133 -0
- package/dist/react-native/dataTransformer.js.map +1 -0
- package/dist/react-native/diagnostics/instrumentEventData.d.ts +28 -0
- package/dist/react-native/diagnostics/instrumentEventData.d.ts.map +1 -0
- package/dist/react-native/diagnostics/instrumentEventData.js +67 -0
- package/dist/react-native/diagnostics/instrumentEventData.js.map +1 -0
- package/dist/react-native/diagnostics/tracing.d.ts +19 -0
- package/dist/react-native/diagnostics/tracing.d.ts.map +1 -0
- package/dist/react-native/diagnostics/tracing.js +40 -0
- package/dist/react-native/diagnostics/tracing.js.map +1 -0
- package/dist/react-native/eventData.d.ts +295 -0
- package/dist/react-native/eventData.d.ts.map +1 -0
- package/dist/react-native/eventData.js +247 -0
- package/dist/react-native/eventData.js.map +1 -0
- package/dist/react-native/eventDataAdapter.d.ts +69 -0
- package/dist/react-native/eventDataAdapter.d.ts.map +1 -0
- package/dist/react-native/eventDataAdapter.js +38 -0
- package/dist/react-native/eventDataAdapter.js.map +1 -0
- package/dist/react-native/eventDataBatch.d.ts +225 -0
- package/dist/react-native/eventDataBatch.d.ts.map +1 -0
- package/dist/react-native/eventDataBatch.js +301 -0
- package/dist/react-native/eventDataBatch.js.map +1 -0
- package/dist/react-native/eventHubBufferedProducerClient.d.ts +323 -0
- package/dist/react-native/eventHubBufferedProducerClient.d.ts.map +1 -0
- package/dist/react-native/eventHubBufferedProducerClient.js +301 -0
- package/dist/react-native/eventHubBufferedProducerClient.js.map +1 -0
- package/dist/react-native/eventHubConsumerClient.d.ts +293 -0
- package/dist/react-native/eventHubConsumerClient.d.ts.map +1 -0
- package/dist/react-native/eventHubConsumerClient.js +336 -0
- package/dist/react-native/eventHubConsumerClient.js.map +1 -0
- package/dist/react-native/eventHubConsumerClientModels.d.ts +218 -0
- package/dist/react-native/eventHubConsumerClientModels.d.ts.map +1 -0
- package/dist/react-native/eventHubConsumerClientModels.js +4 -0
- package/dist/react-native/eventHubConsumerClientModels.js.map +1 -0
- package/dist/react-native/eventHubProducerClient.d.ts +299 -0
- package/dist/react-native/eventHubProducerClient.d.ts.map +1 -0
- package/dist/react-native/eventHubProducerClient.js +366 -0
- package/dist/react-native/eventHubProducerClient.js.map +1 -0
- package/dist/react-native/eventHubSender.d.ts +227 -0
- package/dist/react-native/eventHubSender.d.ts.map +1 -0
- package/dist/react-native/eventHubSender.js +626 -0
- package/dist/react-native/eventHubSender.js.map +1 -0
- package/dist/react-native/eventPosition.d.ts +73 -0
- package/dist/react-native/eventPosition.d.ts.map +1 -0
- package/dist/react-native/eventPosition.js +121 -0
- package/dist/react-native/eventPosition.js.map +1 -0
- package/dist/react-native/eventProcessor.d.ts +232 -0
- package/dist/react-native/eventProcessor.d.ts.map +1 -0
- package/dist/react-native/eventProcessor.js +389 -0
- package/dist/react-native/eventProcessor.js.map +1 -0
- package/dist/react-native/eventhubConnectionConfig.d.ts +96 -0
- package/dist/react-native/eventhubConnectionConfig.d.ts.map +1 -0
- package/dist/react-native/eventhubConnectionConfig.js +98 -0
- package/dist/react-native/eventhubConnectionConfig.js.map +1 -0
- package/dist/react-native/impl/awaitableQueue.d.ts +25 -0
- package/dist/react-native/impl/awaitableQueue.d.ts.map +1 -0
- package/dist/react-native/impl/awaitableQueue.js +51 -0
- package/dist/react-native/impl/awaitableQueue.js.map +1 -0
- package/dist/react-native/impl/partitionAssigner.d.ts +29 -0
- package/dist/react-native/impl/partitionAssigner.d.ts.map +1 -0
- package/dist/react-native/impl/partitionAssigner.js +52 -0
- package/dist/react-native/impl/partitionAssigner.js.map +1 -0
- package/dist/react-native/impl/partitionGate.d.ts +27 -0
- package/dist/react-native/impl/partitionGate.d.ts.map +1 -0
- package/dist/react-native/impl/partitionGate.js +38 -0
- package/dist/react-native/impl/partitionGate.js.map +1 -0
- package/dist/react-native/impl/partitionKeyToIdMapper.d.ts +6 -0
- package/dist/react-native/impl/partitionKeyToIdMapper.d.ts.map +1 -0
- package/dist/react-native/impl/partitionKeyToIdMapper.js +111 -0
- package/dist/react-native/impl/partitionKeyToIdMapper.js.map +1 -0
- package/dist/react-native/inMemoryCheckpointStore.d.ts +44 -0
- package/dist/react-native/inMemoryCheckpointStore.d.ts.map +1 -0
- package/dist/react-native/inMemoryCheckpointStore.js +94 -0
- package/dist/react-native/inMemoryCheckpointStore.js.map +1 -0
- package/dist/react-native/index.d.ts +21 -0
- package/dist/react-native/index.d.ts.map +1 -0
- package/dist/react-native/index.js +12 -0
- package/dist/react-native/index.js.map +1 -0
- package/dist/react-native/loadBalancerStrategies/balancedStrategy.d.ts +30 -0
- package/dist/react-native/loadBalancerStrategies/balancedStrategy.d.ts.map +1 -0
- package/dist/react-native/loadBalancerStrategies/balancedStrategy.js +40 -0
- package/dist/react-native/loadBalancerStrategies/balancedStrategy.js.map +1 -0
- package/dist/react-native/loadBalancerStrategies/greedyStrategy.d.ts +24 -0
- package/dist/react-native/loadBalancerStrategies/greedyStrategy.d.ts.map +1 -0
- package/dist/react-native/loadBalancerStrategies/greedyStrategy.js +29 -0
- package/dist/react-native/loadBalancerStrategies/greedyStrategy.js.map +1 -0
- package/dist/react-native/loadBalancerStrategies/loadBalancingStrategy.d.ts +28 -0
- package/dist/react-native/loadBalancerStrategies/loadBalancingStrategy.d.ts.map +1 -0
- package/dist/react-native/loadBalancerStrategies/loadBalancingStrategy.js +245 -0
- package/dist/react-native/loadBalancerStrategies/loadBalancingStrategy.js.map +1 -0
- package/dist/react-native/loadBalancerStrategies/unbalancedStrategy.d.ts +20 -0
- package/dist/react-native/loadBalancerStrategies/unbalancedStrategy.d.ts.map +1 -0
- package/dist/react-native/loadBalancerStrategies/unbalancedStrategy.js +22 -0
- package/dist/react-native/loadBalancerStrategies/unbalancedStrategy.js.map +1 -0
- package/dist/react-native/logger.d.ts +37 -0
- package/dist/react-native/logger.d.ts.map +1 -0
- package/dist/react-native/logger.js +56 -0
- package/dist/react-native/logger.js.map +1 -0
- package/dist/react-native/managementClient.d.ts +145 -0
- package/dist/react-native/managementClient.d.ts.map +1 -0
- package/dist/react-native/managementClient.js +305 -0
- package/dist/react-native/managementClient.js.map +1 -0
- package/dist/react-native/models/private.d.ts +185 -0
- package/dist/react-native/models/private.d.ts.map +1 -0
- package/dist/react-native/models/private.js +4 -0
- package/dist/react-native/models/private.js.map +1 -0
- package/dist/react-native/models/public.d.ts +240 -0
- package/dist/react-native/models/public.d.ts.map +1 -0
- package/dist/react-native/models/public.js +18 -0
- package/dist/react-native/models/public.js.map +1 -0
- package/dist/react-native/package.json +3 -0
- package/dist/react-native/partitionProcessor.d.ts +134 -0
- package/dist/react-native/partitionProcessor.d.ts.map +1 -0
- package/dist/react-native/partitionProcessor.js +137 -0
- package/dist/react-native/partitionProcessor.js.map +1 -0
- package/dist/react-native/partitionPump.d.ts +38 -0
- package/dist/react-native/partitionPump.d.ts.map +1 -0
- package/dist/react-native/partitionPump.js +175 -0
- package/dist/react-native/partitionPump.js.map +1 -0
- package/dist/react-native/partitionReceiver.d.ts +82 -0
- package/dist/react-native/partitionReceiver.d.ts.map +1 -0
- package/dist/react-native/partitionReceiver.js +335 -0
- package/dist/react-native/partitionReceiver.js.map +1 -0
- package/dist/react-native/pumpManager.d.ts +72 -0
- package/dist/react-native/pumpManager.d.ts.map +1 -0
- package/dist/react-native/pumpManager.js +120 -0
- package/dist/react-native/pumpManager.js.map +1 -0
- package/dist/react-native/util/connectionStringUtils.d.ts +52 -0
- package/dist/react-native/util/connectionStringUtils.d.ts.map +1 -0
- package/dist/react-native/util/connectionStringUtils.js +48 -0
- package/dist/react-native/util/connectionStringUtils.js.map +1 -0
- package/dist/react-native/util/constants.d.ts +25 -0
- package/dist/react-native/util/constants.d.ts.map +1 -0
- package/dist/react-native/util/constants.js +27 -0
- package/dist/react-native/util/constants.js.map +1 -0
- package/dist/react-native/util/delayWithoutThrow.d.ts +8 -0
- package/dist/react-native/util/delayWithoutThrow.d.ts.map +1 -0
- package/dist/react-native/util/delayWithoutThrow.js +17 -0
- package/dist/react-native/util/delayWithoutThrow.js.map +1 -0
- package/dist/react-native/util/error.d.ts +39 -0
- package/dist/react-native/util/error.d.ts.map +1 -0
- package/dist/react-native/util/error.js +103 -0
- package/dist/react-native/util/error.js.map +1 -0
- package/dist/react-native/util/getPromiseParts.d.ts +10 -0
- package/dist/react-native/util/getPromiseParts.d.ts.map +1 -0
- package/dist/react-native/util/getPromiseParts.js +20 -0
- package/dist/react-native/util/getPromiseParts.js.map +1 -0
- package/dist/react-native/util/operationOptions.d.ts +16 -0
- package/dist/react-native/util/operationOptions.d.ts.map +1 -0
- package/dist/react-native/util/operationOptions.js +4 -0
- package/dist/react-native/util/operationOptions.js.map +1 -0
- package/dist/react-native/util/parseEndpoint.d.ts +11 -0
- package/dist/react-native/util/parseEndpoint.d.ts.map +1 -0
- package/dist/react-native/util/parseEndpoint.js +17 -0
- package/dist/react-native/util/parseEndpoint.js.map +1 -0
- package/dist/react-native/util/retries.d.ts +6 -0
- package/dist/react-native/util/retries.d.ts.map +1 -0
- package/dist/react-native/util/retries.js +13 -0
- package/dist/react-native/util/retries.js.map +1 -0
- package/dist/react-native/util/runtimeInfo-react-native.d.mts.map +1 -0
- package/dist/react-native/util/runtimeInfo-react-native.mjs.map +1 -0
- package/dist/react-native/util/runtimeInfo.d.ts +6 -0
- package/dist/react-native/util/runtimeInfo.js +20 -0
- package/dist/react-native/util/timerLoop.d.ts +26 -0
- package/dist/react-native/util/timerLoop.d.ts.map +1 -0
- package/dist/react-native/util/timerLoop.js +34 -0
- package/dist/react-native/util/timerLoop.js.map +1 -0
- package/dist/react-native/util/typeGuards.d.ts +8 -0
- package/dist/react-native/util/typeGuards.d.ts.map +1 -0
- package/dist/react-native/util/typeGuards.js +12 -0
- package/dist/react-native/util/typeGuards.js.map +1 -0
- package/dist/react-native/util/utils.d.ts +7 -0
- package/dist/react-native/util/utils.d.ts.map +1 -0
- package/dist/react-native/util/utils.js +13 -0
- package/dist/react-native/util/utils.js.map +1 -0
- package/dist/react-native/withAuth.d.ts +25 -0
- package/dist/react-native/withAuth.d.ts.map +1 -0
- package/dist/react-native/withAuth.js +84 -0
- package/dist/react-native/withAuth.js.map +1 -0
- package/package.json +16 -11
|
@@ -0,0 +1,293 @@
|
|
|
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
|
+
/**
|
|
7
|
+
* The `EventHubConsumerClient` class is used to consume events from an Event Hub.
|
|
8
|
+
*
|
|
9
|
+
* There are multiple ways to create an `EventHubConsumerClient`
|
|
10
|
+
* - Use the connection string from the SAS policy created for your Event Hub instance.
|
|
11
|
+
* - Use the connection string from the SAS policy created for your Event Hub namespace,
|
|
12
|
+
* and the name of the Event Hub instance
|
|
13
|
+
* - Use the full namespace like `<yournamespace>.servicebus.windows.net`, and a credentials object.
|
|
14
|
+
*
|
|
15
|
+
* Optionally, you can also pass:
|
|
16
|
+
* - An options bag to configure the retry policy or proxy settings.
|
|
17
|
+
* - A checkpoint store that is used by the client to read checkpoints to determine the position from where it should
|
|
18
|
+
* resume receiving events when your application gets restarted. The checkpoint store is also used by the client
|
|
19
|
+
* to load balance multiple instances of your application.
|
|
20
|
+
*/
|
|
21
|
+
export declare class EventHubConsumerClient {
|
|
22
|
+
private _consumerGroup;
|
|
23
|
+
/**
|
|
24
|
+
* Describes the amqp connection context for the client.
|
|
25
|
+
*/
|
|
26
|
+
private _context;
|
|
27
|
+
/**
|
|
28
|
+
* The options passed by the user when creating the EventHubClient instance.
|
|
29
|
+
*/
|
|
30
|
+
private _clientOptions;
|
|
31
|
+
private _partitionGate;
|
|
32
|
+
/**
|
|
33
|
+
* The Subscriptions that were spawned by calling `subscribe()`.
|
|
34
|
+
* Subscriptions that have been stopped by the user will not
|
|
35
|
+
* be present in this set.
|
|
36
|
+
*/
|
|
37
|
+
private _subscriptions;
|
|
38
|
+
/**
|
|
39
|
+
* The name of the default consumer group in the Event Hubs service.
|
|
40
|
+
*/
|
|
41
|
+
static defaultConsumerGroupName: string;
|
|
42
|
+
private _checkpointStore;
|
|
43
|
+
private _userChoseCheckpointStore;
|
|
44
|
+
/**
|
|
45
|
+
* Options for configuring load balancing.
|
|
46
|
+
*/
|
|
47
|
+
private readonly _loadBalancingOptions;
|
|
48
|
+
/**
|
|
49
|
+
* @readonly
|
|
50
|
+
* The name of the Event Hub instance for which this client is created.
|
|
51
|
+
*/
|
|
52
|
+
get eventHubName(): string;
|
|
53
|
+
/**
|
|
54
|
+
* @readonly
|
|
55
|
+
* The fully qualified namespace of the Event Hub instance for which this client is created.
|
|
56
|
+
* This is likely to be similar to <yournamespace>.servicebus.windows.net.
|
|
57
|
+
*/
|
|
58
|
+
get fullyQualifiedNamespace(): string;
|
|
59
|
+
/**
|
|
60
|
+
* The name used to identify this EventHubConsumerClient.
|
|
61
|
+
* If not specified or empty, a random unique one will be generated.
|
|
62
|
+
*/
|
|
63
|
+
readonly identifier: string;
|
|
64
|
+
/**
|
|
65
|
+
* The `EventHubConsumerClient` class is used to consume events from an Event Hub.
|
|
66
|
+
* Use the `options` parmeter to configure retry policy or proxy settings.
|
|
67
|
+
* @param consumerGroup - The name of the consumer group from which you want to process events.
|
|
68
|
+
* @param connectionString - The connection string to use for connecting to the Event Hub instance.
|
|
69
|
+
* It is expected that the shared key properties and the Event Hub path are contained in this connection string.
|
|
70
|
+
* e.g. 'Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key;EntityPath=my-event-hub-name'.
|
|
71
|
+
* @param options - A set of options to apply when configuring the client.
|
|
72
|
+
* - `retryOptions` : Configures the retry policy for all the operations on the client.
|
|
73
|
+
* For example, `{ "maxRetries": 4 }` or `{ "maxRetries": 4, "retryDelayInMs": 30000 }`.
|
|
74
|
+
* - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.
|
|
75
|
+
* - `userAgent` : A string to append to the built in user agent string that is passed to the service.
|
|
76
|
+
*/
|
|
77
|
+
constructor(consumerGroup: string, connectionString: string, options?: EventHubConsumerClientOptions);
|
|
78
|
+
/**
|
|
79
|
+
* The `EventHubConsumerClient` class is used to consume events from an Event Hub.
|
|
80
|
+
* Use the `options` parmeter to configure retry policy or proxy settings.
|
|
81
|
+
* @param consumerGroup - The name of the consumer group from which you want to process events.
|
|
82
|
+
* @param connectionString - The connection string to use for connecting to the Event Hub instance.
|
|
83
|
+
* It is expected that the shared key properties and the Event Hub path are contained in this connection string.
|
|
84
|
+
* e.g. 'Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key;EntityPath=my-event-hub-name'.
|
|
85
|
+
* @param checkpointStore - A checkpoint store that is used by the client to read checkpoints to determine
|
|
86
|
+
* the position from where it should resume receiving events when your application gets restarted.
|
|
87
|
+
* It is also used by the client to load balance multiple instances of your application.
|
|
88
|
+
* @param options - A set of options to apply when configuring the client.
|
|
89
|
+
* - `retryOptions` : Configures the retry policy for all the operations on the client.
|
|
90
|
+
* For example, `{ "maxRetries": 4 }` or `{ "maxRetries": 4, "retryDelayInMs": 30000 }`.
|
|
91
|
+
* - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.
|
|
92
|
+
* - `userAgent` : A string to append to the built in user agent string that is passed to the service.
|
|
93
|
+
*/
|
|
94
|
+
constructor(consumerGroup: string, connectionString: string, checkpointStore: CheckpointStore, options?: EventHubConsumerClientOptions);
|
|
95
|
+
/**
|
|
96
|
+
* The `EventHubConsumerClient` class is used to consume events from an Event Hub.
|
|
97
|
+
* Use the `options` parmeter to configure retry policy or proxy settings.
|
|
98
|
+
* @param consumerGroup - The name of the consumer group from which you want to process events.
|
|
99
|
+
* @param connectionString - The connection string to use for connecting to the Event Hubs namespace.
|
|
100
|
+
* It is expected that the shared key properties are contained in this connection string, but not the Event Hub path,
|
|
101
|
+
* e.g. 'Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key;'.
|
|
102
|
+
* @param eventHubName - The name of the specific Event Hub to connect the client to.
|
|
103
|
+
* @param options - A set of options to apply when configuring the client.
|
|
104
|
+
* - `retryOptions` : Configures the retry policy for all the operations on the client.
|
|
105
|
+
* For example, `{ "maxRetries": 4 }` or `{ "maxRetries": 4, "retryDelayInMs": 30000 }`.
|
|
106
|
+
* - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.
|
|
107
|
+
* - `userAgent` : A string to append to the built in user agent string that is passed to the service.
|
|
108
|
+
*/
|
|
109
|
+
constructor(consumerGroup: string, connectionString: string, eventHubName: string, options?: EventHubConsumerClientOptions);
|
|
110
|
+
/**
|
|
111
|
+
* The `EventHubConsumerClient` class is used to consume events from an Event Hub.
|
|
112
|
+
* Use the `options` parmeter to configure retry policy or proxy settings.
|
|
113
|
+
* @param consumerGroup - The name of the consumer group from which you want to process events.
|
|
114
|
+
* @param connectionString - The connection string to use for connecting to the Event Hubs namespace.
|
|
115
|
+
* It is expected that the shared key properties are contained in this connection string, but not the Event Hub path,
|
|
116
|
+
* e.g. 'Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key;'.
|
|
117
|
+
* @param eventHubName - The name of the specific Event Hub to connect the client to.
|
|
118
|
+
* @param checkpointStore - A checkpoint store that is used by the client to read checkpoints to determine
|
|
119
|
+
* the position from where it should resume receiving events when your application gets restarted.
|
|
120
|
+
* It is also used by the client to load balance multiple instances of your application.
|
|
121
|
+
* @param options - A set of options to apply when configuring the client.
|
|
122
|
+
* - `retryOptions` : Configures the retry policy for all the operations on the client.
|
|
123
|
+
* For example, `{ "maxRetries": 4 }` or `{ "maxRetries": 4, "retryDelayInMs": 30000 }`.
|
|
124
|
+
* - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.
|
|
125
|
+
* - `userAgent` : A string to append to the built in user agent string that is passed to the service.
|
|
126
|
+
*/
|
|
127
|
+
constructor(consumerGroup: string, connectionString: string, eventHubName: string, checkpointStore: CheckpointStore, options?: EventHubConsumerClientOptions);
|
|
128
|
+
/**
|
|
129
|
+
* The `EventHubConsumerClient` class is used to consume events from an Event Hub.
|
|
130
|
+
* Use the `options` parmeter to configure retry policy or proxy settings.
|
|
131
|
+
* @param consumerGroup - The name of the consumer group from which you want to process events.
|
|
132
|
+
* @param fullyQualifiedNamespace - The full namespace which is likely to be similar to
|
|
133
|
+
* <yournamespace>.servicebus.windows.net
|
|
134
|
+
* @param eventHubName - The name of the specific Event Hub to connect the client to.
|
|
135
|
+
* @param credential - An credential object used by the client to get the token to authenticate the connection
|
|
136
|
+
* with the Azure Event Hubs service.
|
|
137
|
+
* See @azure/identity for creating credentials that support AAD auth.
|
|
138
|
+
* Use the `AzureNamedKeyCredential` from @azure/core-auth if you want to pass in a `SharedAccessKeyName`
|
|
139
|
+
* and `SharedAccessKey` without using a connection string. These fields map to the `name` and `key` field respectively
|
|
140
|
+
* in `AzureNamedKeyCredential`.
|
|
141
|
+
* Use the `AzureSASCredential` from @azure/core-auth if you want to pass in a `SharedAccessSignature`
|
|
142
|
+
* without using a connection string. This field maps to `signature` in `AzureSASCredential`.
|
|
143
|
+
* @param options - A set of options to apply when configuring the client.
|
|
144
|
+
* - `retryOptions` : Configures the retry policy for all the operations on the client.
|
|
145
|
+
* For example, `{ "maxRetries": 4 }` or `{ "maxRetries": 4, "retryDelayInMs": 30000 }`.
|
|
146
|
+
* - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.
|
|
147
|
+
* - `userAgent` : A string to append to the built in user agent string that is passed to the service.
|
|
148
|
+
*/
|
|
149
|
+
constructor(consumerGroup: string, fullyQualifiedNamespace: string, eventHubName: string, credential: TokenCredential | NamedKeyCredential | SASCredential, options?: EventHubConsumerClientOptions);
|
|
150
|
+
/**
|
|
151
|
+
* The `EventHubConsumerClient` class is used to consume events from an Event Hub.
|
|
152
|
+
* Use the `options` parmeter to configure retry policy or proxy settings.
|
|
153
|
+
* @param consumerGroup - The name of the consumer group from which you want to process events.
|
|
154
|
+
* @param fullyQualifiedNamespace - The full namespace which is likely to be similar to
|
|
155
|
+
* <yournamespace>.servicebus.windows.net
|
|
156
|
+
* @param eventHubName - The name of the specific Event Hub to connect the client to.
|
|
157
|
+
* @param credential - An credential object used by the client to get the token to authenticate the connection
|
|
158
|
+
* with the Azure Event Hubs service.
|
|
159
|
+
* See @azure/identity for creating credentials that support AAD auth.
|
|
160
|
+
* Use the `AzureNamedKeyCredential` from @azure/core-auth if you want to pass in a `SharedAccessKeyName`
|
|
161
|
+
* and `SharedAccessKey` without using a connection string. These fields map to the `name` and `key` field respectively
|
|
162
|
+
* in `AzureNamedKeyCredential`.
|
|
163
|
+
* Use the `AzureSASCredential` from @azure/core-auth if you want to pass in a `SharedAccessSignature`
|
|
164
|
+
* without using a connection string. This field maps to `signature` in `AzureSASCredential`.
|
|
165
|
+
* @param checkpointStore - A checkpoint store that is used by the client to read checkpoints to determine
|
|
166
|
+
* the position from where it should resume receiving events when your application gets restarted.
|
|
167
|
+
* It is also used by the client to load balance multiple instances of your application.
|
|
168
|
+
* @param options - A set of options to apply when configuring the client.
|
|
169
|
+
* - `retryOptions` : Configures the retry policy for all the operations on the client.
|
|
170
|
+
* For example, `{ "maxRetries": 4 }` or `{ "maxRetries": 4, "retryDelayInMs": 30000 }`.
|
|
171
|
+
* - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.
|
|
172
|
+
* - `userAgent` : A string to append to the built in user agent string that is passed to the service.
|
|
173
|
+
*/
|
|
174
|
+
constructor(consumerGroup: string, fullyQualifiedNamespace: string, eventHubName: string, credential: TokenCredential | NamedKeyCredential | SASCredential, checkpointStore: CheckpointStore, options?: EventHubConsumerClientOptions);
|
|
175
|
+
/**
|
|
176
|
+
* Closes the AMQP connection to the Event Hub instance,
|
|
177
|
+
* returning a promise that will be resolved when disconnection is completed.
|
|
178
|
+
* @returns Promise<void>
|
|
179
|
+
* @throws Error if the underlying connection encounters an error while closing.
|
|
180
|
+
*/
|
|
181
|
+
close(): Promise<void>;
|
|
182
|
+
/**
|
|
183
|
+
* Provides the id for each partition associated with the Event Hub.
|
|
184
|
+
* @param options - The set of options to apply to the operation call.
|
|
185
|
+
* @returns A promise that resolves with an Array of strings representing the id for
|
|
186
|
+
* each partition associated with the Event Hub.
|
|
187
|
+
* @throws Error if the underlying connection has been closed, create a new EventHubConsumerClient.
|
|
188
|
+
* @throws AbortError if the operation is cancelled via the abortSignal.
|
|
189
|
+
*/
|
|
190
|
+
getPartitionIds(options?: GetPartitionIdsOptions): Promise<Array<string>>;
|
|
191
|
+
/**
|
|
192
|
+
* Provides information about the state of the specified partition.
|
|
193
|
+
* @param partitionId - The id of the partition for which information is required.
|
|
194
|
+
* @param options - The set of options to apply to the operation call.
|
|
195
|
+
* @returns A promise that resolves with information about the state of the partition .
|
|
196
|
+
* @throws Error if the underlying connection has been closed, create a new EventHubConsumerClient.
|
|
197
|
+
* @throws AbortError if the operation is cancelled via the abortSignal.
|
|
198
|
+
*/
|
|
199
|
+
getPartitionProperties(partitionId: string, options?: GetPartitionPropertiesOptions): Promise<PartitionProperties>;
|
|
200
|
+
/**
|
|
201
|
+
* Provides the Event Hub runtime information.
|
|
202
|
+
* @param options - The set of options to apply to the operation call.
|
|
203
|
+
* @returns A promise that resolves with information about the Event Hub instance.
|
|
204
|
+
* @throws Error if the underlying connection has been closed, create a new EventHubConsumerClient.
|
|
205
|
+
* @throws AbortError if the operation is cancelled via the abortSignal.
|
|
206
|
+
*/
|
|
207
|
+
getEventHubProperties(options?: GetEventHubPropertiesOptions): Promise<EventHubProperties>;
|
|
208
|
+
/**
|
|
209
|
+
* Subscribe to events from all partitions.
|
|
210
|
+
*
|
|
211
|
+
* If checkpoint store is provided to the `EventHubConsumerClient` and there are multiple
|
|
212
|
+
* instances of your application, then each instance will subscribe to a subset of the
|
|
213
|
+
* partitions such that the load is balanced amongst them.
|
|
214
|
+
*
|
|
215
|
+
* Call close() on the returned object to stop receiving events.
|
|
216
|
+
*
|
|
217
|
+
* Example usage:
|
|
218
|
+
* ```ts snippet:EventHubConsumerClient_Subscribe
|
|
219
|
+
* import { EventHubConsumerClient, earliestEventPosition } from "@azure/event-hubs";
|
|
220
|
+
*
|
|
221
|
+
* const client = new EventHubConsumerClient("my-consumer-group", "connectionString", "eventHubName");
|
|
222
|
+
*
|
|
223
|
+
* const subscription = client.subscribe(
|
|
224
|
+
* {
|
|
225
|
+
* processEvents: async (events, context) => {
|
|
226
|
+
* console.log("Received event count: ", events.length);
|
|
227
|
+
* },
|
|
228
|
+
* processError: async (err, context) => {
|
|
229
|
+
* console.log("Error: ", err);
|
|
230
|
+
* },
|
|
231
|
+
* },
|
|
232
|
+
* { startPosition: earliestEventPosition },
|
|
233
|
+
* );
|
|
234
|
+
* ```
|
|
235
|
+
*
|
|
236
|
+
* @param handlers - Handlers for the lifecycle of the subscription - subscription initialization
|
|
237
|
+
* per partition, receiving events, handling errors and the closing
|
|
238
|
+
* of a subscription per partition.
|
|
239
|
+
* @param options - Configures the way events are received.
|
|
240
|
+
* Most common are `maxBatchSize` and `maxWaitTimeInSeconds` that control the flow of
|
|
241
|
+
* events to the handler provided to receive events as well as the start position. For example,
|
|
242
|
+
* `{ maxBatchSize: 20, maxWaitTimeInSeconds: 120, startPosition: { sequenceNumber: 123 } }`
|
|
243
|
+
*/
|
|
244
|
+
subscribe(handlers: SubscriptionEventHandlers, options?: SubscribeOptions): Subscription;
|
|
245
|
+
/**
|
|
246
|
+
* Subscribe to events from a single partition.
|
|
247
|
+
* Call close() on the returned object to stop receiving events.
|
|
248
|
+
*
|
|
249
|
+
* Example usage:
|
|
250
|
+
* ```ts snippet:EventHubConsumerClient_SubscribeSinglePartition
|
|
251
|
+
* import { EventHubConsumerClient, earliestEventPosition } from "@azure/event-hubs";
|
|
252
|
+
*
|
|
253
|
+
* const client = new EventHubConsumerClient("my-consumer-group", "connectionString", "eventHubName");
|
|
254
|
+
*
|
|
255
|
+
* const partitionIds = await client.getPartitionIds();
|
|
256
|
+
*
|
|
257
|
+
* const subscription = client.subscribe(
|
|
258
|
+
* partitionIds[0],
|
|
259
|
+
* {
|
|
260
|
+
* processEvents: async (events, context) => {
|
|
261
|
+
* console.log("Received event count: ", events.length);
|
|
262
|
+
* },
|
|
263
|
+
* processError: async (err, context) => {
|
|
264
|
+
* console.log("Error: ", err);
|
|
265
|
+
* },
|
|
266
|
+
* },
|
|
267
|
+
* { startPosition: earliestEventPosition },
|
|
268
|
+
* );
|
|
269
|
+
* ```
|
|
270
|
+
*
|
|
271
|
+
* @param partitionId - The id of the partition to subscribe to.
|
|
272
|
+
* @param handlers - Handlers for the lifecycle of the subscription - subscription initialization
|
|
273
|
+
* of the partition, receiving events, handling errors and the closing
|
|
274
|
+
* of a subscription to the partition.
|
|
275
|
+
* @param options - Configures the way events are received.
|
|
276
|
+
* Most common are `maxBatchSize` and `maxWaitTimeInSeconds` that control the flow of
|
|
277
|
+
* events to the handler provided to receive events as well as the start position. For example,
|
|
278
|
+
* `{ maxBatchSize: 20, maxWaitTimeInSeconds: 120, startPosition: { sequenceNumber: 123 } }`
|
|
279
|
+
*/
|
|
280
|
+
subscribe(partitionId: string, handlers: SubscriptionEventHandlers, options?: SubscribeOptions): Subscription;
|
|
281
|
+
/**
|
|
282
|
+
* Gets the LoadBalancing strategy that should be used based on what the user provided.
|
|
283
|
+
*/
|
|
284
|
+
private _getLoadBalancingStrategy;
|
|
285
|
+
private createEventProcessorForAllPartitions;
|
|
286
|
+
private createEventProcessorForSinglePartition;
|
|
287
|
+
private _createEventProcessor;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* @internal
|
|
291
|
+
*/
|
|
292
|
+
export declare function isCheckpointStore(possible: CheckpointStore | any): possible is CheckpointStore;
|
|
293
|
+
//# sourceMappingURL=eventHubConsumerClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eventHubConsumerClient.d.ts","sourceRoot":"","sources":["../../src/eventHubConsumerClient.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { EventProcessor } from "./eventProcessor.js";
|
|
4
|
+
import { createConnectionContext } from "./connectionContext.js";
|
|
5
|
+
import { BalancedLoadBalancingStrategy } from "./loadBalancerStrategies/balancedStrategy.js";
|
|
6
|
+
import { Constants } from "@azure/core-amqp";
|
|
7
|
+
import { GreedyLoadBalancingStrategy } from "./loadBalancerStrategies/greedyStrategy.js";
|
|
8
|
+
import { InMemoryCheckpointStore } from "./inMemoryCheckpointStore.js";
|
|
9
|
+
import { PartitionGate } from "./impl/partitionGate.js";
|
|
10
|
+
import { UnbalancedLoadBalancingStrategy } from "./loadBalancerStrategies/unbalancedStrategy.js";
|
|
11
|
+
import { isCredential } from "./util/typeGuards.js";
|
|
12
|
+
import { logger } from "./logger.js";
|
|
13
|
+
import { validateEventPositions } from "./eventPosition.js";
|
|
14
|
+
import { getRandomName } from "./util/utils.js";
|
|
15
|
+
const defaultConsumerClientOptions = {
|
|
16
|
+
// to support our current "process single event only" workflow we'll also purposefully
|
|
17
|
+
// only request a single event at a time.
|
|
18
|
+
maxBatchSize: 1,
|
|
19
|
+
maxWaitTimeInSeconds: 60,
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* The `EventHubConsumerClient` class is used to consume events from an Event Hub.
|
|
23
|
+
*
|
|
24
|
+
* There are multiple ways to create an `EventHubConsumerClient`
|
|
25
|
+
* - Use the connection string from the SAS policy created for your Event Hub instance.
|
|
26
|
+
* - Use the connection string from the SAS policy created for your Event Hub namespace,
|
|
27
|
+
* and the name of the Event Hub instance
|
|
28
|
+
* - Use the full namespace like `<yournamespace>.servicebus.windows.net`, and a credentials object.
|
|
29
|
+
*
|
|
30
|
+
* Optionally, you can also pass:
|
|
31
|
+
* - An options bag to configure the retry policy or proxy settings.
|
|
32
|
+
* - A checkpoint store that is used by the client to read checkpoints to determine the position from where it should
|
|
33
|
+
* resume receiving events when your application gets restarted. The checkpoint store is also used by the client
|
|
34
|
+
* to load balance multiple instances of your application.
|
|
35
|
+
*/
|
|
36
|
+
export class EventHubConsumerClient {
|
|
37
|
+
_consumerGroup;
|
|
38
|
+
/**
|
|
39
|
+
* Describes the amqp connection context for the client.
|
|
40
|
+
*/
|
|
41
|
+
_context;
|
|
42
|
+
/**
|
|
43
|
+
* The options passed by the user when creating the EventHubClient instance.
|
|
44
|
+
*/
|
|
45
|
+
_clientOptions;
|
|
46
|
+
_partitionGate = new PartitionGate();
|
|
47
|
+
/**
|
|
48
|
+
* The Subscriptions that were spawned by calling `subscribe()`.
|
|
49
|
+
* Subscriptions that have been stopped by the user will not
|
|
50
|
+
* be present in this set.
|
|
51
|
+
*/
|
|
52
|
+
_subscriptions = new Set();
|
|
53
|
+
/**
|
|
54
|
+
* The name of the default consumer group in the Event Hubs service.
|
|
55
|
+
*/
|
|
56
|
+
static defaultConsumerGroupName = Constants.defaultConsumerGroup;
|
|
57
|
+
_checkpointStore;
|
|
58
|
+
_userChoseCheckpointStore;
|
|
59
|
+
/**
|
|
60
|
+
* Options for configuring load balancing.
|
|
61
|
+
*/
|
|
62
|
+
_loadBalancingOptions;
|
|
63
|
+
/**
|
|
64
|
+
* @readonly
|
|
65
|
+
* The name of the Event Hub instance for which this client is created.
|
|
66
|
+
*/
|
|
67
|
+
get eventHubName() {
|
|
68
|
+
return this._context.config.entityPath;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* @readonly
|
|
72
|
+
* The fully qualified namespace of the Event Hub instance for which this client is created.
|
|
73
|
+
* This is likely to be similar to <yournamespace>.servicebus.windows.net.
|
|
74
|
+
*/
|
|
75
|
+
get fullyQualifiedNamespace() {
|
|
76
|
+
return this._context.config.host;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The name used to identify this EventHubConsumerClient.
|
|
80
|
+
* If not specified or empty, a random unique one will be generated.
|
|
81
|
+
*/
|
|
82
|
+
identifier;
|
|
83
|
+
constructor(_consumerGroup, connectionStringOrFullyQualifiedNamespace2, checkpointStoreOrEventHubNameOrOptions3, checkpointStoreOrCredentialOrOptions4, checkpointStoreOrOptions5, options6) {
|
|
84
|
+
this._consumerGroup = _consumerGroup;
|
|
85
|
+
if (isCredential(checkpointStoreOrCredentialOrOptions4)) {
|
|
86
|
+
// #3 or 3.1
|
|
87
|
+
logger.info("Creating EventHubConsumerClient with TokenCredential.");
|
|
88
|
+
if (isCheckpointStore(checkpointStoreOrOptions5)) {
|
|
89
|
+
// 3.1
|
|
90
|
+
this._checkpointStore = checkpointStoreOrOptions5;
|
|
91
|
+
this._userChoseCheckpointStore = true;
|
|
92
|
+
this._clientOptions = options6 || {};
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
this._checkpointStore = new InMemoryCheckpointStore();
|
|
96
|
+
this._userChoseCheckpointStore = false;
|
|
97
|
+
this._clientOptions = checkpointStoreOrOptions5 || {};
|
|
98
|
+
}
|
|
99
|
+
this._context = createConnectionContext(connectionStringOrFullyQualifiedNamespace2, checkpointStoreOrEventHubNameOrOptions3, checkpointStoreOrCredentialOrOptions4, this._clientOptions);
|
|
100
|
+
}
|
|
101
|
+
else if (typeof checkpointStoreOrEventHubNameOrOptions3 === "string") {
|
|
102
|
+
// #2 or 2.1
|
|
103
|
+
logger.info("Creating EventHubConsumerClient with connection string and event hub name.");
|
|
104
|
+
if (isCheckpointStore(checkpointStoreOrCredentialOrOptions4)) {
|
|
105
|
+
// 2.1
|
|
106
|
+
this._checkpointStore = checkpointStoreOrCredentialOrOptions4;
|
|
107
|
+
this._userChoseCheckpointStore = true;
|
|
108
|
+
this._clientOptions = checkpointStoreOrOptions5 || {};
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
// 2
|
|
112
|
+
this._checkpointStore = new InMemoryCheckpointStore();
|
|
113
|
+
this._userChoseCheckpointStore = false;
|
|
114
|
+
this._clientOptions = checkpointStoreOrCredentialOrOptions4 || {};
|
|
115
|
+
}
|
|
116
|
+
this._context = createConnectionContext(connectionStringOrFullyQualifiedNamespace2, checkpointStoreOrEventHubNameOrOptions3, this._clientOptions);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
// #1 or 1.1
|
|
120
|
+
logger.info("Creating EventHubConsumerClient with connection string.");
|
|
121
|
+
if (isCheckpointStore(checkpointStoreOrEventHubNameOrOptions3)) {
|
|
122
|
+
// 1.1
|
|
123
|
+
this._checkpointStore = checkpointStoreOrEventHubNameOrOptions3;
|
|
124
|
+
this._userChoseCheckpointStore = true;
|
|
125
|
+
this._clientOptions =
|
|
126
|
+
checkpointStoreOrCredentialOrOptions4 || {};
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
// 1
|
|
130
|
+
this._checkpointStore = new InMemoryCheckpointStore();
|
|
131
|
+
this._userChoseCheckpointStore = false;
|
|
132
|
+
this._clientOptions =
|
|
133
|
+
checkpointStoreOrEventHubNameOrOptions3 || {};
|
|
134
|
+
}
|
|
135
|
+
this._context = createConnectionContext(connectionStringOrFullyQualifiedNamespace2, this._clientOptions);
|
|
136
|
+
}
|
|
137
|
+
this.identifier = this._clientOptions.identifier ?? getRandomName();
|
|
138
|
+
this._loadBalancingOptions = {
|
|
139
|
+
// default options
|
|
140
|
+
strategy: "balanced",
|
|
141
|
+
updateIntervalInMs: 10000,
|
|
142
|
+
partitionOwnershipExpirationIntervalInMs: 60000,
|
|
143
|
+
// options supplied by user
|
|
144
|
+
...this._clientOptions?.loadBalancingOptions,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Closes the AMQP connection to the Event Hub instance,
|
|
149
|
+
* returning a promise that will be resolved when disconnection is completed.
|
|
150
|
+
* @returns Promise<void>
|
|
151
|
+
* @throws Error if the underlying connection encounters an error while closing.
|
|
152
|
+
*/
|
|
153
|
+
async close() {
|
|
154
|
+
// Stop all the actively running subscriptions.
|
|
155
|
+
const activeSubscriptions = Array.from(this._subscriptions);
|
|
156
|
+
await Promise.all(activeSubscriptions.map((subscription) => {
|
|
157
|
+
return subscription.close();
|
|
158
|
+
}));
|
|
159
|
+
// Close the connection via the connection context.
|
|
160
|
+
return this._context.close();
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Provides the id for each partition associated with the Event Hub.
|
|
164
|
+
* @param options - The set of options to apply to the operation call.
|
|
165
|
+
* @returns A promise that resolves with an Array of strings representing the id for
|
|
166
|
+
* each partition associated with the Event Hub.
|
|
167
|
+
* @throws Error if the underlying connection has been closed, create a new EventHubConsumerClient.
|
|
168
|
+
* @throws AbortError if the operation is cancelled via the abortSignal.
|
|
169
|
+
*/
|
|
170
|
+
async getPartitionIds(options = {}) {
|
|
171
|
+
const eventHubProperties = await this._context.managementSession.getEventHubProperties({
|
|
172
|
+
...options,
|
|
173
|
+
retryOptions: this._clientOptions.retryOptions,
|
|
174
|
+
});
|
|
175
|
+
return eventHubProperties.partitionIds;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Provides information about the state of the specified partition.
|
|
179
|
+
* @param partitionId - The id of the partition for which information is required.
|
|
180
|
+
* @param options - The set of options to apply to the operation call.
|
|
181
|
+
* @returns A promise that resolves with information about the state of the partition .
|
|
182
|
+
* @throws Error if the underlying connection has been closed, create a new EventHubConsumerClient.
|
|
183
|
+
* @throws AbortError if the operation is cancelled via the abortSignal.
|
|
184
|
+
*/
|
|
185
|
+
getPartitionProperties(partitionId, options = {}) {
|
|
186
|
+
return this._context.managementSession.getPartitionProperties(partitionId, {
|
|
187
|
+
...options,
|
|
188
|
+
retryOptions: this._clientOptions.retryOptions,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Provides the Event Hub runtime information.
|
|
193
|
+
* @param options - The set of options to apply to the operation call.
|
|
194
|
+
* @returns A promise that resolves with information about the Event Hub instance.
|
|
195
|
+
* @throws Error if the underlying connection has been closed, create a new EventHubConsumerClient.
|
|
196
|
+
* @throws AbortError if the operation is cancelled via the abortSignal.
|
|
197
|
+
*/
|
|
198
|
+
getEventHubProperties(options = {}) {
|
|
199
|
+
return this._context.managementSession.getEventHubProperties({
|
|
200
|
+
...options,
|
|
201
|
+
retryOptions: this._clientOptions.retryOptions,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
subscribe(handlersOrPartitionId1, optionsOrHandlers2, possibleOptions3) {
|
|
205
|
+
let eventProcessor;
|
|
206
|
+
let targetedPartitionId;
|
|
207
|
+
if (isSubscriptionEventHandlers(handlersOrPartitionId1)) {
|
|
208
|
+
// #1: subscribe overload - read from all partitions
|
|
209
|
+
const options = optionsOrHandlers2;
|
|
210
|
+
if (options && options.startPosition) {
|
|
211
|
+
validateEventPositions(options.startPosition);
|
|
212
|
+
}
|
|
213
|
+
({ targetedPartitionId, eventProcessor } = this.createEventProcessorForAllPartitions(handlersOrPartitionId1, options));
|
|
214
|
+
}
|
|
215
|
+
else if (isSubscriptionEventHandlers(optionsOrHandlers2)) {
|
|
216
|
+
// #2: subscribe overload (read from specific partition IDs), don't coordinate
|
|
217
|
+
const options = possibleOptions3;
|
|
218
|
+
if (options && options.startPosition) {
|
|
219
|
+
validateEventPositions(options.startPosition);
|
|
220
|
+
}
|
|
221
|
+
({ targetedPartitionId, eventProcessor } = this.createEventProcessorForSinglePartition(
|
|
222
|
+
// cast to string as downstream code expects partitionId to be string, but JS users could have given us anything.
|
|
223
|
+
// we don't validate the user input and instead rely on service throwing errors if any
|
|
224
|
+
String(handlersOrPartitionId1), optionsOrHandlers2, possibleOptions3));
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
throw new TypeError("Unhandled subscribe() overload");
|
|
228
|
+
}
|
|
229
|
+
eventProcessor.start();
|
|
230
|
+
const subscription = {
|
|
231
|
+
get isRunning() {
|
|
232
|
+
return eventProcessor.isRunning();
|
|
233
|
+
},
|
|
234
|
+
close: () => {
|
|
235
|
+
this._partitionGate.remove(targetedPartitionId);
|
|
236
|
+
this._subscriptions.delete(subscription);
|
|
237
|
+
return eventProcessor.stop();
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
this._subscriptions.add(subscription);
|
|
241
|
+
return subscription;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Gets the LoadBalancing strategy that should be used based on what the user provided.
|
|
245
|
+
*/
|
|
246
|
+
_getLoadBalancingStrategy() {
|
|
247
|
+
if (!this._userChoseCheckpointStore) {
|
|
248
|
+
// The default behavior when a checkpointstore isn't provided
|
|
249
|
+
// is to always grab all the partitions.
|
|
250
|
+
return new UnbalancedLoadBalancingStrategy();
|
|
251
|
+
}
|
|
252
|
+
const partitionOwnershipExpirationIntervalInMs = this._loadBalancingOptions.partitionOwnershipExpirationIntervalInMs;
|
|
253
|
+
if (this._loadBalancingOptions?.strategy === "greedy") {
|
|
254
|
+
return new GreedyLoadBalancingStrategy(partitionOwnershipExpirationIntervalInMs);
|
|
255
|
+
}
|
|
256
|
+
// The default behavior when a checkpointstore is provided is
|
|
257
|
+
// to grab one partition at a time.
|
|
258
|
+
return new BalancedLoadBalancingStrategy(partitionOwnershipExpirationIntervalInMs);
|
|
259
|
+
}
|
|
260
|
+
createEventProcessorForAllPartitions(subscriptionEventHandlers, options) {
|
|
261
|
+
this._partitionGate.add("all");
|
|
262
|
+
if (this._userChoseCheckpointStore) {
|
|
263
|
+
logger.verbose("EventHubConsumerClient subscribing to all partitions, using a checkpoint store.");
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
logger.verbose("EventHubConsumerClient subscribing to all partitions, no checkpoint store.");
|
|
267
|
+
}
|
|
268
|
+
const loadBalancingStrategy = this._getLoadBalancingStrategy();
|
|
269
|
+
const eventProcessor = this._createEventProcessor(this._context, subscriptionEventHandlers, this._checkpointStore, {
|
|
270
|
+
...defaultConsumerClientOptions,
|
|
271
|
+
...options,
|
|
272
|
+
ownerLevel: getOwnerLevel(options, this._userChoseCheckpointStore),
|
|
273
|
+
// make it so all the event processors process work with the same overarching owner ID
|
|
274
|
+
// this allows the EventHubConsumer to unify all the work for any processors that it spawns
|
|
275
|
+
ownerId: this.identifier,
|
|
276
|
+
retryOptions: this._clientOptions.retryOptions,
|
|
277
|
+
loadBalancingStrategy,
|
|
278
|
+
loopIntervalInMs: this._loadBalancingOptions.updateIntervalInMs,
|
|
279
|
+
});
|
|
280
|
+
return { targetedPartitionId: "all", eventProcessor };
|
|
281
|
+
}
|
|
282
|
+
createEventProcessorForSinglePartition(partitionId, eventHandlers, options) {
|
|
283
|
+
this._partitionGate.add(partitionId);
|
|
284
|
+
const subscribeOptions = options;
|
|
285
|
+
if (this._userChoseCheckpointStore) {
|
|
286
|
+
logger.verbose(`EventHubConsumerClient subscribing to specific partition (${partitionId}), using a checkpoint store.`);
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
logger.verbose(`EventHubConsumerClient subscribing to specific partition (${partitionId}), no checkpoint store.`);
|
|
290
|
+
}
|
|
291
|
+
const eventProcessor = this._createEventProcessor(this._context, eventHandlers, this._checkpointStore, {
|
|
292
|
+
...defaultConsumerClientOptions,
|
|
293
|
+
...options,
|
|
294
|
+
processingTarget: partitionId,
|
|
295
|
+
ownerLevel: getOwnerLevel(subscribeOptions, this._userChoseCheckpointStore),
|
|
296
|
+
retryOptions: this._clientOptions.retryOptions,
|
|
297
|
+
loadBalancingStrategy: new UnbalancedLoadBalancingStrategy(),
|
|
298
|
+
loopIntervalInMs: this._loadBalancingOptions.updateIntervalInMs ?? 10000,
|
|
299
|
+
});
|
|
300
|
+
return { targetedPartitionId: partitionId, eventProcessor };
|
|
301
|
+
}
|
|
302
|
+
_createEventProcessor(connectionContext, subscriptionEventHandlers, checkpointStore, options) {
|
|
303
|
+
return new EventProcessor(this._consumerGroup, connectionContext, subscriptionEventHandlers, checkpointStore, options);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* @internal
|
|
308
|
+
*/
|
|
309
|
+
export function isCheckpointStore(possible) {
|
|
310
|
+
if (!possible) {
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
const checkpointStore = possible;
|
|
314
|
+
return (typeof checkpointStore.claimOwnership === "function" &&
|
|
315
|
+
typeof checkpointStore.listCheckpoints === "function" &&
|
|
316
|
+
typeof checkpointStore.listOwnership === "function" &&
|
|
317
|
+
typeof checkpointStore.updateCheckpoint === "function");
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* @internal
|
|
321
|
+
*/
|
|
322
|
+
function isSubscriptionEventHandlers(possible) {
|
|
323
|
+
return typeof possible.processEvents === "function";
|
|
324
|
+
}
|
|
325
|
+
function getOwnerLevel(options, userChoseCheckpointStore) {
|
|
326
|
+
if (options && options.ownerLevel) {
|
|
327
|
+
return options.ownerLevel;
|
|
328
|
+
}
|
|
329
|
+
if (userChoseCheckpointStore) {
|
|
330
|
+
return 0;
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
return undefined;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
//# sourceMappingURL=eventHubConsumerClient.js.map
|