@azure/event-hubs 6.0.0-alpha.20250131.1 → 6.0.0-alpha.20250205.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +143 -165
  2. package/dist/browser/eventHubConsumerClient.d.ts +31 -15
  3. package/dist/browser/eventHubConsumerClient.d.ts.map +1 -1
  4. package/dist/browser/eventHubConsumerClient.js.map +1 -1
  5. package/dist/browser/eventHubProducerClient.d.ts +57 -24
  6. package/dist/browser/eventHubProducerClient.d.ts.map +1 -1
  7. package/dist/browser/eventHubProducerClient.js +22 -11
  8. package/dist/browser/eventHubProducerClient.js.map +1 -1
  9. package/dist/browser/eventProcessor.d.ts +1 -1
  10. package/dist/browser/eventProcessor.js.map +1 -1
  11. package/dist/browser/models/private.d.ts +1 -1
  12. package/dist/browser/models/private.js.map +1 -1
  13. package/dist/browser/models/public.d.ts +4 -4
  14. package/dist/browser/models/public.js.map +1 -1
  15. package/dist/commonjs/eventHubConsumerClient.d.ts +31 -15
  16. package/dist/commonjs/eventHubConsumerClient.d.ts.map +1 -1
  17. package/dist/commonjs/eventHubConsumerClient.js.map +1 -1
  18. package/dist/commonjs/eventHubProducerClient.d.ts +57 -24
  19. package/dist/commonjs/eventHubProducerClient.d.ts.map +1 -1
  20. package/dist/commonjs/eventHubProducerClient.js +22 -11
  21. package/dist/commonjs/eventHubProducerClient.js.map +1 -1
  22. package/dist/commonjs/eventProcessor.d.ts +1 -1
  23. package/dist/commonjs/eventProcessor.js.map +1 -1
  24. package/dist/commonjs/models/private.d.ts +1 -1
  25. package/dist/commonjs/models/private.js.map +1 -1
  26. package/dist/commonjs/models/public.d.ts +4 -4
  27. package/dist/commonjs/models/public.js.map +1 -1
  28. package/dist/commonjs/tsdoc-metadata.json +1 -1
  29. package/dist/esm/eventHubConsumerClient.d.ts +31 -15
  30. package/dist/esm/eventHubConsumerClient.d.ts.map +1 -1
  31. package/dist/esm/eventHubConsumerClient.js.map +1 -1
  32. package/dist/esm/eventHubProducerClient.d.ts +57 -24
  33. package/dist/esm/eventHubProducerClient.d.ts.map +1 -1
  34. package/dist/esm/eventHubProducerClient.js +22 -11
  35. package/dist/esm/eventHubProducerClient.js.map +1 -1
  36. package/dist/esm/eventProcessor.d.ts +1 -1
  37. package/dist/esm/eventProcessor.js.map +1 -1
  38. package/dist/esm/models/private.d.ts +1 -1
  39. package/dist/esm/models/private.js.map +1 -1
  40. package/dist/esm/models/public.d.ts +4 -4
  41. package/dist/esm/models/public.js.map +1 -1
  42. package/package.json +12 -13
@@ -1 +1 @@
1
- {"version":3,"file":"public.js","sourceRoot":"","sources":["../../../src/models/public.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAwElC;;;GAGG;AACH,IAAY,WASX;AATD,WAAY,WAAW;IACrB;;OAEG;IACH,8CAA+B,CAAA;IAC/B;;OAEG;IACH,oCAAqB,CAAA;AACvB,CAAC,EATW,WAAW,2BAAX,WAAW,QAStB","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { RetryOptions, WebSocketOptions } from \"@azure/core-amqp\";\nimport type { OperationOptions } from \"../util/operationOptions.js\";\n\n/**\n * The set of options to configure the behavior of `getEventHubProperties`.\n * - `abortSignal` : An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.\n * - `parentSpan` : The `Span` or `SpanContext` to use as the `parent` of the span created while calling this operation.\n */\nexport interface GetEventHubPropertiesOptions extends OperationOptions {}\n\n/**\n * The set of options to configure the behavior of `getPartitionProperties`.\n * - `abortSignal` : An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.\n * - `parentSpan` : The `Span` or `SpanContext` to use as the `parent` of the span created while calling this operation.\n */\nexport interface GetPartitionPropertiesOptions extends OperationOptions {}\n\n/**\n * The set of options to configure the behavior of `getPartitionIds`.\n * - `abortSignal` : An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.\n * - `parentSpan` : The `Span` or `SpanContext` to use as the `parent` of the span created while calling this operation.\n */\nexport interface GetPartitionIdsOptions extends OperationOptions {}\n\n/**\n * Options to configure the `sendBatch` method on the `EventHubProducerClient`\n * when sending an array of events.\n * If `partitionId` is set, `partitionKey` must not be set and vice versa.\n *\n * - `partitionId` : The partition this batch will be sent to.\n * - `partitionKey` : A value that is hashed to produce a partition assignment.\n * - `abortSignal` : A signal used to cancel the send operation.\n */\nexport interface SendBatchOptions extends OperationOptions {\n /**\n * The partition this batch will be sent to.\n * If this value is set then partitionKey can not be set.\n */\n 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 producer was created using a `partitionId`.\n */\n partitionKey?: string;\n}\n\n/**\n * The set of options to configure the `send` operation on the `EventHubProducer`.\n * - `partitionKey` : A value that is hashed to produce a partition assignment.\n * - `abortSignal` : A signal used to cancel the send operation.\n *\n * Example usage:\n * ```js\n * {\n * partitionKey: 'foo'\n * }\n * ```\n *\n * @internal\n */\nexport interface SendOptions extends OperationOptions {\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 producer was created using a `partitionId`.\n */\n partitionKey?: string;\n}\n\n/**\n * An enum representing the different reasons for an `EventHubConsumerClient` to stop processing\n * events from a partition in a consumer group of an Event Hub.\n */\nexport enum CloseReason {\n /**\n * Ownership of the partition was lost or transitioned to a new processor instance.\n */\n OwnershipLost = \"OwnershipLost\",\n /**\n * The EventProcessor was shutdown.\n */\n Shutdown = \"Shutdown\",\n}\n\n/**\n * Describes the options that can be provided while creating the EventHubClient.\n * - `userAgent` : A string to append to the built in user agent string that is passed as a connection property\n * to the service.\n * - `webSocketOptions` : Options to configure the channelling of the AMQP connection over Web Sockets.\n * - `websocket` : The WebSocket constructor used to create an AMQP connection if you choose to make the connection\n * over a WebSocket.\n * - `webSocketConstructorOptions` : Options to pass to the Websocket constructor when you choose to make the connection\n * over a WebSocket.\n * - `retryOptions` : The retry options for all the operations on the client/producer/consumer.\n * - `maxRetries` : The number of times the operation can be retried in case of a retryable error.\n * - `maxRetryDelayInMs`: The maximum delay between retries. Applicable only when performing exponential retries.\n * - `mode`: Which retry mode to apply, specified by the `RetryMode` enum. Options are `Exponential` and `Fixed`. Defaults to `Fixed`.\n * - `retryDelayInMs`: Amount of time to wait in milliseconds before making the next attempt. When `mode` is set to `Exponential`,\n * this is used to compute the exponentially increasing delays between retries. Default: 30000 milliseconds.\n * - `timeoutInMs`: Amount of time in milliseconds to wait before the operation times out. This will trigger a retry if there are any\n * retry attempts remaining. Default value: 60000 milliseconds.\n *\n * A simple usage can be `{ \"maxRetries\": 4 }`.\n *\n * Example usage:\n * ```js\n * {\n * retryOptions: {\n * maxRetries: 4\n * }\n * }\n * ```\n */\nexport interface EventHubClientOptions {\n /**\n * A custom endpoint to use when connecting to the Event Hubs service.\n * This can be useful when your network does not allow connecting to the\n * standard Azure Event Hubs endpoint address, but does allow connecting\n * through an intermediary.\n *\n * Example: \"https://my.custom.endpoint:100/\"\n */\n customEndpointAddress?: string;\n /**\n * Options to configure the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n *\n */\n retryOptions?: RetryOptions;\n /**\n * Options to configure the channelling of the AMQP connection over Web Sockets.\n */\n webSocketOptions?: WebSocketOptions;\n /**\n * Value that is appended to the built in user agent string that is passed to the Event Hubs service.\n */\n userAgent?: string;\n /**\n * A unique name used to identify the client. If not provided, a GUID will be used as the identifier\n */\n identifier?: string;\n}\n\n/**\n * Describes the options that can be provided while creating the EventHubConsumerClient.\n * - `loadBalancingOptions`: Options to tune how the EventHubConsumerClient claims partitions.\n * - `userAgent` : A string to append to the built in user agent string that is passed as a connection property\n * to the service.\n * - `webSocketOptions` : Options to configure the channelling of the AMQP connection over Web Sockets.\n * - `websocket` : The WebSocket constructor used to create an AMQP connection if you choose to make the connection\n * over a WebSocket.\n * - `webSocketConstructorOptions` : Options to pass to the Websocket constructor when you choose to make the connection\n * over a WebSocket.\n * - `retryOptions` : The retry options for all the operations on the client/producer/consumer.\n * - `maxRetries` : The number of times the operation can be retried in case of a retryable error.\n * - `maxRetryDelayInMs`: The maximum delay between retries. Applicable only when performing exponential retries.\n * - `mode`: Which retry mode to apply, specified by the `RetryMode` enum. Options are `Exponential` and `Fixed`. Defaults to `Fixed`.\n * - `retryDelayInMs`: Amount of time to wait in milliseconds before making the next attempt. When `mode` is set to `Exponential`,\n * this is used to compute the exponentially increasing delays between retries. Default: 30000 milliseconds.\n * - `timeoutInMs`: Amount of time in milliseconds to wait before the operation times out. This will trigger a retry if there are any\n * retry attempts remaining. Default value: 60000 milliseconds.\n *\n * A simple usage can be `{ \"maxRetries\": 4 }`.\n *\n * Example usage:\n * ```js\n * {\n * retryOptions: {\n * maxRetries: 4\n * }\n * }\n * ```\n */\nexport interface EventHubConsumerClientOptions extends EventHubClientOptions {\n /**\n * Options to tune how the EventHubConsumerClient claims partitions.\n */\n loadBalancingOptions?: LoadBalancingOptions;\n}\n\n/**\n * An options bag to configure load balancing settings.\n */\nexport interface LoadBalancingOptions {\n /**\n * Whether to apply a greedy or a more balanced approach when\n * claiming partitions.\n *\n * - balanced: The `EventHubConsumerClient` will take a measured approach to\n * requesting partition ownership when balancing work with other clients,\n * slowly claiming partitions until a stabilized distribution is achieved.\n *\n * - greedy: The `EventHubConsumerClient` will attempt to claim ownership\n * of its fair share of partitions aggressively when balancing work with\n * other clients.\n *\n * This option is ignored when either:\n * - `CheckpointStore` is __not__ provided to the `EventHubConsumerClient`.\n * - `subscribe()` is called for a single partition.\n * Default: balanced\n */\n strategy?: \"balanced\" | \"greedy\";\n /**\n * The length of time between attempts to claim partitions.\n * Default: 10000\n */\n updateIntervalInMs?: number;\n /**\n * The length of time a partition claim is valid.\n * Default: 60000\n */\n partitionOwnershipExpirationIntervalInMs?: number;\n}\n\n/**\n * Options to configure the `createBatch` method on the `EventHubProducerClient`.\n * - `partitionKey` : A value that is hashed to produce a partition assignment.\n * - `maxSizeInBytes`: The upper limit for the size of batch.\n * - `abortSignal` : A signal the request to cancel the send operation.\n *\n * Example usage:\n * ```js\n * {\n * partitionKey: 'foo',\n * maxSizeInBytes: 1024 * 1024 // 1 MB\n * }\n * ```\n */\nexport interface CreateBatchOptions extends OperationOptions {\n /**\n * A value that is hashed to produce a partition assignment. It guarantees that messages\n * with the same partitionKey end up in the same partition.\n * If this value is set then partitionId can not be set.\n */\n partitionKey?: string;\n /**\n * The partition this batch will be sent to.\n * If this value is set then partitionKey can not be set.\n */\n partitionId?: string;\n /**\n * The upper limit for the size of batch. The `tryAdd` function will return `false` after this limit is reached.\n */\n maxSizeInBytes?: number;\n}\n"]}
1
+ {"version":3,"file":"public.js","sourceRoot":"","sources":["../../../src/models/public.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAwElC;;;GAGG;AACH,IAAY,WASX;AATD,WAAY,WAAW;IACrB;;OAEG;IACH,8CAA+B,CAAA;IAC/B;;OAEG;IACH,oCAAqB,CAAA;AACvB,CAAC,EATW,WAAW,2BAAX,WAAW,QAStB","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { RetryOptions, WebSocketOptions } from \"@azure/core-amqp\";\nimport type { OperationOptions } from \"../util/operationOptions.js\";\n\n/**\n * The set of options to configure the behavior of `getEventHubProperties`.\n * - `abortSignal` : An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.\n * - `parentSpan` : The `Span` or `SpanContext` to use as the `parent` of the span created while calling this operation.\n */\nexport interface GetEventHubPropertiesOptions extends OperationOptions {}\n\n/**\n * The set of options to configure the behavior of `getPartitionProperties`.\n * - `abortSignal` : An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.\n * - `parentSpan` : The `Span` or `SpanContext` to use as the `parent` of the span created while calling this operation.\n */\nexport interface GetPartitionPropertiesOptions extends OperationOptions {}\n\n/**\n * The set of options to configure the behavior of `getPartitionIds`.\n * - `abortSignal` : An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.\n * - `parentSpan` : The `Span` or `SpanContext` to use as the `parent` of the span created while calling this operation.\n */\nexport interface GetPartitionIdsOptions extends OperationOptions {}\n\n/**\n * Options to configure the `sendBatch` method on the `EventHubProducerClient`\n * when sending an array of events.\n * If `partitionId` is set, `partitionKey` must not be set and vice versa.\n *\n * - `partitionId` : The partition this batch will be sent to.\n * - `partitionKey` : A value that is hashed to produce a partition assignment.\n * - `abortSignal` : A signal used to cancel the send operation.\n */\nexport interface SendBatchOptions extends OperationOptions {\n /**\n * The partition this batch will be sent to.\n * If this value is set then partitionKey can not be set.\n */\n 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 producer was created using a `partitionId`.\n */\n partitionKey?: string;\n}\n\n/**\n * The set of options to configure the `send` operation on the `EventHubProducer`.\n * - `partitionKey` : A value that is hashed to produce a partition assignment.\n * - `abortSignal` : A signal used to cancel the send operation.\n *\n * Example usage:\n * ```ts snippet:ignore\n * {\n * partitionKey: 'foo'\n * }\n * ```\n *\n * @internal\n */\nexport interface SendOptions extends OperationOptions {\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 producer was created using a `partitionId`.\n */\n partitionKey?: string;\n}\n\n/**\n * An enum representing the different reasons for an `EventHubConsumerClient` to stop processing\n * events from a partition in a consumer group of an Event Hub.\n */\nexport enum CloseReason {\n /**\n * Ownership of the partition was lost or transitioned to a new processor instance.\n */\n OwnershipLost = \"OwnershipLost\",\n /**\n * The EventProcessor was shutdown.\n */\n Shutdown = \"Shutdown\",\n}\n\n/**\n * Describes the options that can be provided while creating the EventHubClient.\n * - `userAgent` : A string to append to the built in user agent string that is passed as a connection property\n * to the service.\n * - `webSocketOptions` : Options to configure the channelling of the AMQP connection over Web Sockets.\n * - `websocket` : The WebSocket constructor used to create an AMQP connection if you choose to make the connection\n * over a WebSocket.\n * - `webSocketConstructorOptions` : Options to pass to the Websocket constructor when you choose to make the connection\n * over a WebSocket.\n * - `retryOptions` : The retry options for all the operations on the client/producer/consumer.\n * - `maxRetries` : The number of times the operation can be retried in case of a retryable error.\n * - `maxRetryDelayInMs`: The maximum delay between retries. Applicable only when performing exponential retries.\n * - `mode`: Which retry mode to apply, specified by the `RetryMode` enum. Options are `Exponential` and `Fixed`. Defaults to `Fixed`.\n * - `retryDelayInMs`: Amount of time to wait in milliseconds before making the next attempt. When `mode` is set to `Exponential`,\n * this is used to compute the exponentially increasing delays between retries. Default: 30000 milliseconds.\n * - `timeoutInMs`: Amount of time in milliseconds to wait before the operation times out. This will trigger a retry if there are any\n * retry attempts remaining. Default value: 60000 milliseconds.\n *\n * A simple usage can be `{ \"maxRetries\": 4 }`.\n *\n * Example usage:\n * ```ts snippet:ignore\n * {\n * retryOptions: {\n * maxRetries: 4\n * }\n * }\n * ```\n */\nexport interface EventHubClientOptions {\n /**\n * A custom endpoint to use when connecting to the Event Hubs service.\n * This can be useful when your network does not allow connecting to the\n * standard Azure Event Hubs endpoint address, but does allow connecting\n * through an intermediary.\n *\n * Example: \"https://my.custom.endpoint:100/\"\n */\n customEndpointAddress?: string;\n /**\n * Options to configure the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n *\n */\n retryOptions?: RetryOptions;\n /**\n * Options to configure the channelling of the AMQP connection over Web Sockets.\n */\n webSocketOptions?: WebSocketOptions;\n /**\n * Value that is appended to the built in user agent string that is passed to the Event Hubs service.\n */\n userAgent?: string;\n /**\n * A unique name used to identify the client. If not provided, a GUID will be used as the identifier\n */\n identifier?: string;\n}\n\n/**\n * Describes the options that can be provided while creating the EventHubConsumerClient.\n * - `loadBalancingOptions`: Options to tune how the EventHubConsumerClient claims partitions.\n * - `userAgent` : A string to append to the built in user agent string that is passed as a connection property\n * to the service.\n * - `webSocketOptions` : Options to configure the channelling of the AMQP connection over Web Sockets.\n * - `websocket` : The WebSocket constructor used to create an AMQP connection if you choose to make the connection\n * over a WebSocket.\n * - `webSocketConstructorOptions` : Options to pass to the Websocket constructor when you choose to make the connection\n * over a WebSocket.\n * - `retryOptions` : The retry options for all the operations on the client/producer/consumer.\n * - `maxRetries` : The number of times the operation can be retried in case of a retryable error.\n * - `maxRetryDelayInMs`: The maximum delay between retries. Applicable only when performing exponential retries.\n * - `mode`: Which retry mode to apply, specified by the `RetryMode` enum. Options are `Exponential` and `Fixed`. Defaults to `Fixed`.\n * - `retryDelayInMs`: Amount of time to wait in milliseconds before making the next attempt. When `mode` is set to `Exponential`,\n * this is used to compute the exponentially increasing delays between retries. Default: 30000 milliseconds.\n * - `timeoutInMs`: Amount of time in milliseconds to wait before the operation times out. This will trigger a retry if there are any\n * retry attempts remaining. Default value: 60000 milliseconds.\n *\n * A simple usage can be `{ \"maxRetries\": 4 }`.\n *\n * Example usage:\n * ```ts snippet:ignore\n * {\n * retryOptions: {\n * maxRetries: 4\n * }\n * }\n * ```\n */\nexport interface EventHubConsumerClientOptions extends EventHubClientOptions {\n /**\n * Options to tune how the EventHubConsumerClient claims partitions.\n */\n loadBalancingOptions?: LoadBalancingOptions;\n}\n\n/**\n * An options bag to configure load balancing settings.\n */\nexport interface LoadBalancingOptions {\n /**\n * Whether to apply a greedy or a more balanced approach when\n * claiming partitions.\n *\n * - balanced: The `EventHubConsumerClient` will take a measured approach to\n * requesting partition ownership when balancing work with other clients,\n * slowly claiming partitions until a stabilized distribution is achieved.\n *\n * - greedy: The `EventHubConsumerClient` will attempt to claim ownership\n * of its fair share of partitions aggressively when balancing work with\n * other clients.\n *\n * This option is ignored when either:\n * - `CheckpointStore` is __not__ provided to the `EventHubConsumerClient`.\n * - `subscribe()` is called for a single partition.\n * Default: balanced\n */\n strategy?: \"balanced\" | \"greedy\";\n /**\n * The length of time between attempts to claim partitions.\n * Default: 10000\n */\n updateIntervalInMs?: number;\n /**\n * The length of time a partition claim is valid.\n * Default: 60000\n */\n partitionOwnershipExpirationIntervalInMs?: number;\n}\n\n/**\n * Options to configure the `createBatch` method on the `EventHubProducerClient`.\n * - `partitionKey` : A value that is hashed to produce a partition assignment.\n * - `maxSizeInBytes`: The upper limit for the size of batch.\n * - `abortSignal` : A signal the request to cancel the send operation.\n *\n * Example usage:\n * ```ts snippet:ignore\n * {\n * partitionKey: 'foo',\n * maxSizeInBytes: 1024 * 1024 // 1 MB\n * }\n * ```\n */\nexport interface CreateBatchOptions extends OperationOptions {\n /**\n * A value that is hashed to produce a partition assignment. It guarantees that messages\n * with the same partitionKey end up in the same partition.\n * If this value is set then partitionId can not be set.\n */\n partitionKey?: string;\n /**\n * The partition this batch will be sent to.\n * If this value is set then partitionKey can not be set.\n */\n partitionId?: string;\n /**\n * The upper limit for the size of batch. The `tryAdd` function will return `false` after this limit is reached.\n */\n maxSizeInBytes?: number;\n}\n"]}
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.49.1"
8
+ "packageVersion": "7.49.2"
9
9
  }
10
10
  ]
11
11
  }
@@ -215,14 +215,21 @@ export declare class EventHubConsumerClient {
215
215
  * Call close() on the returned object to stop receiving events.
216
216
  *
217
217
  * Example usage:
218
- * ```ts
219
- * const client = new EventHubConsumerClient(consumerGroup, connectionString, eventHubName);
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
+ *
220
223
  * const subscription = client.subscribe(
221
- * {
222
- * processEvents: (events, context) => { console.log("Received event count: ", events.length) },
223
- * processError: (err, context) => { console.log("Error: ", err) }
224
- * },
225
- * { startPosition: earliestEventPosition }
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 },
226
233
  * );
227
234
  * ```
228
235
  *
@@ -240,15 +247,24 @@ export declare class EventHubConsumerClient {
240
247
  * Call close() on the returned object to stop receiving events.
241
248
  *
242
249
  * Example usage:
243
- * ```ts
244
- * const client = new EventHubConsumerClient(consumerGroup, connectionString, eventHubName);
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
+ *
245
257
  * const subscription = client.subscribe(
246
- * partitionId,
247
- * {
248
- * processEvents: (events, context) => { console.log("Received event count: ", events.length) },
249
- * processError: (err, context) => { console.log("Error: ", err) }
250
- * },
251
- * { startPosition: earliestEventPosition }
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 },
252
268
  * );
253
269
  * ```
254
270
  *
@@ -1 +1 @@
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,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACrF,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC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.\n\nimport type { CheckpointStore, FullEventProcessorOptions } from \"./eventProcessor.js\";\nimport { EventProcessor } from \"./eventProcessor.js\";\nimport type { ConnectionContext } from \"./connectionContext.js\";\nimport { createConnectionContext } from \"./connectionContext.js\";\nimport type {\n EventHubConsumerClientOptions,\n GetEventHubPropertiesOptions,\n GetPartitionIdsOptions,\n GetPartitionPropertiesOptions,\n LoadBalancingOptions,\n} from \"./models/public.js\";\nimport type { EventHubProperties, PartitionProperties } from \"./managementClient.js\";\nimport type { NamedKeyCredential, SASCredential, TokenCredential } from \"@azure/core-auth\";\nimport type {\n SubscribeOptions,\n Subscription,\n SubscriptionEventHandlers,\n} from \"./eventHubConsumerClientModels.js\";\nimport { BalancedLoadBalancingStrategy } from \"./loadBalancerStrategies/balancedStrategy.js\";\nimport { Constants } from \"@azure/core-amqp\";\nimport { GreedyLoadBalancingStrategy } from \"./loadBalancerStrategies/greedyStrategy.js\";\nimport { InMemoryCheckpointStore } from \"./inMemoryCheckpointStore.js\";\nimport type { LoadBalancingStrategy } from \"./loadBalancerStrategies/loadBalancingStrategy.js\";\nimport { PartitionGate } from \"./impl/partitionGate.js\";\nimport { UnbalancedLoadBalancingStrategy } from \"./loadBalancerStrategies/unbalancedStrategy.js\";\nimport { isCredential } from \"./util/typeGuards.js\";\nimport { logger } from \"./logger.js\";\nimport { validateEventPositions } from \"./eventPosition.js\";\nimport { getRandomName } from \"./util/utils.js\";\n\nconst defaultConsumerClientOptions: Required<\n Pick<FullEventProcessorOptions, \"maxWaitTimeInSeconds\" | \"maxBatchSize\">\n> = {\n // to support our current \"process single event only\" workflow we'll also purposefully\n // only request a single event at a time.\n maxBatchSize: 1,\n maxWaitTimeInSeconds: 60,\n};\n\n/**\n * The `EventHubConsumerClient` class is used to consume events from an Event Hub.\n *\n * There are multiple ways to create an `EventHubConsumerClient`\n * - Use the connection string from the SAS policy created for your Event Hub instance.\n * - Use the connection string from the SAS policy created for your Event Hub namespace,\n * and the name of the Event Hub instance\n * - Use the full namespace like `<yournamespace>.servicebus.windows.net`, and a credentials object.\n *\n * Optionally, you can also pass:\n * - An options bag to configure the retry policy or proxy settings.\n * - A checkpoint store that is used by the client to read checkpoints to determine the position from where it should\n * resume receiving events when your application gets restarted. The checkpoint store is also used by the client\n * to load balance multiple instances of your application.\n */\nexport class EventHubConsumerClient {\n /**\n * Describes the amqp connection context for the client.\n */\n private _context: ConnectionContext;\n /**\n * The options passed by the user when creating the EventHubClient instance.\n */\n private _clientOptions: EventHubConsumerClientOptions;\n private _partitionGate = new PartitionGate();\n\n /**\n * The Subscriptions that were spawned by calling `subscribe()`.\n * Subscriptions that have been stopped by the user will not\n * be present in this set.\n */\n private _subscriptions = new Set<Subscription>();\n\n /**\n * The name of the default consumer group in the Event Hubs service.\n */\n static defaultConsumerGroupName: string = Constants.defaultConsumerGroup;\n\n private _checkpointStore: CheckpointStore;\n private _userChoseCheckpointStore: boolean;\n\n /**\n * Options for configuring load balancing.\n */\n private readonly _loadBalancingOptions: Required<LoadBalancingOptions>;\n\n /**\n * @readonly\n * The name of the Event Hub instance for which this client is created.\n */\n get eventHubName(): string {\n return this._context.config.entityPath;\n }\n\n /**\n * @readonly\n * The fully qualified namespace of the Event Hub instance for which this client is created.\n * This is likely to be similar to <yournamespace>.servicebus.windows.net.\n */\n get fullyQualifiedNamespace(): string {\n return this._context.config.host;\n }\n\n /**\n * The name used to identify this EventHubConsumerClient.\n * If not specified or empty, a random unique one will be generated.\n */\n public readonly identifier: string;\n\n /**\n * The `EventHubConsumerClient` class is used to consume events from an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param consumerGroup - The name of the consumer group from which you want to process events.\n * @param connectionString - The connection string to use for connecting to the Event Hub instance.\n * It is expected that the shared key properties and the Event Hub path are contained in this connection string.\n * e.g. 'Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key;EntityPath=my-event-hub-name'.\n * @param options - A set of options to apply when configuring the client.\n * - `retryOptions` : Configures the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n * - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.\n * - `userAgent` : A string to append to the built in user agent string that is passed to the service.\n */\n constructor(\n consumerGroup: string,\n connectionString: string,\n options?: EventHubConsumerClientOptions,\n ); // #1\n /**\n * The `EventHubConsumerClient` class is used to consume events from an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param consumerGroup - The name of the consumer group from which you want to process events.\n * @param connectionString - The connection string to use for connecting to the Event Hub instance.\n * It is expected that the shared key properties and the Event Hub path are contained in this connection string.\n * e.g. 'Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key;EntityPath=my-event-hub-name'.\n * @param checkpointStore - A checkpoint store that is used by the client to read checkpoints to determine\n * the position from where it should resume receiving events when your application gets restarted.\n * It is also used by the client to load balance multiple instances of your application.\n * @param options - A set of options to apply when configuring the client.\n * - `retryOptions` : Configures the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n * - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.\n * - `userAgent` : A string to append to the built in user agent string that is passed to the service.\n */\n constructor(\n consumerGroup: string,\n connectionString: string,\n checkpointStore: CheckpointStore,\n options?: EventHubConsumerClientOptions,\n ); // #1.1\n /**\n * The `EventHubConsumerClient` class is used to consume events from an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param consumerGroup - The name of the consumer group from which you want to process events.\n * @param connectionString - The connection string to use for connecting to the Event Hubs namespace.\n * It is expected that the shared key properties are contained in this connection string, but not the Event Hub path,\n * e.g. 'Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key;'.\n * @param eventHubName - The name of the specific Event Hub to connect the client to.\n * @param options - A set of options to apply when configuring the client.\n * - `retryOptions` : Configures the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n * - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.\n * - `userAgent` : A string to append to the built in user agent string that is passed to the service.\n */\n constructor(\n consumerGroup: string,\n connectionString: string,\n eventHubName: string,\n options?: EventHubConsumerClientOptions,\n ); // #2\n /**\n * The `EventHubConsumerClient` class is used to consume events from an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param consumerGroup - The name of the consumer group from which you want to process events.\n * @param connectionString - The connection string to use for connecting to the Event Hubs namespace.\n * It is expected that the shared key properties are contained in this connection string, but not the Event Hub path,\n * e.g. 'Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key;'.\n * @param eventHubName - The name of the specific Event Hub to connect the client to.\n * @param checkpointStore - A checkpoint store that is used by the client to read checkpoints to determine\n * the position from where it should resume receiving events when your application gets restarted.\n * It is also used by the client to load balance multiple instances of your application.\n * @param options - A set of options to apply when configuring the client.\n * - `retryOptions` : Configures the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n * - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.\n * - `userAgent` : A string to append to the built in user agent string that is passed to the service.\n */\n constructor(\n consumerGroup: string,\n connectionString: string,\n eventHubName: string,\n checkpointStore: CheckpointStore,\n options?: EventHubConsumerClientOptions,\n ); // #2.1\n /**\n * The `EventHubConsumerClient` class is used to consume events from an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param consumerGroup - The name of the consumer group from which you want to process events.\n * @param fullyQualifiedNamespace - The full namespace which is likely to be similar to\n * <yournamespace>.servicebus.windows.net\n * @param eventHubName - The name of the specific Event Hub to connect the client to.\n * @param credential - An credential object used by the client to get the token to authenticate the connection\n * with the Azure Event Hubs service.\n * See &commat;azure/identity for creating credentials that support AAD auth.\n * Use the `AzureNamedKeyCredential` from &commat;azure/core-auth if you want to pass in a `SharedAccessKeyName`\n * and `SharedAccessKey` without using a connection string. These fields map to the `name` and `key` field respectively\n * in `AzureNamedKeyCredential`.\n * Use the `AzureSASCredential` from &commat;azure/core-auth if you want to pass in a `SharedAccessSignature`\n * without using a connection string. This field maps to `signature` in `AzureSASCredential`.\n * @param options - A set of options to apply when configuring the client.\n * - `retryOptions` : Configures the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n * - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.\n * - `userAgent` : A string to append to the built in user agent string that is passed to the service.\n */\n constructor(\n consumerGroup: string,\n fullyQualifiedNamespace: string,\n eventHubName: string,\n credential: TokenCredential | NamedKeyCredential | SASCredential,\n options?: EventHubConsumerClientOptions,\n ); // #3\n /**\n * The `EventHubConsumerClient` class is used to consume events from an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param consumerGroup - The name of the consumer group from which you want to process events.\n * @param fullyQualifiedNamespace - The full namespace which is likely to be similar to\n * <yournamespace>.servicebus.windows.net\n * @param eventHubName - The name of the specific Event Hub to connect the client to.\n * @param credential - An credential object used by the client to get the token to authenticate the connection\n * with the Azure Event Hubs service.\n * See &commat;azure/identity for creating credentials that support AAD auth.\n * Use the `AzureNamedKeyCredential` from &commat;azure/core-auth if you want to pass in a `SharedAccessKeyName`\n * and `SharedAccessKey` without using a connection string. These fields map to the `name` and `key` field respectively\n * in `AzureNamedKeyCredential`.\n * Use the `AzureSASCredential` from &commat;azure/core-auth if you want to pass in a `SharedAccessSignature`\n * without using a connection string. This field maps to `signature` in `AzureSASCredential`.\n * @param checkpointStore - A checkpoint store that is used by the client to read checkpoints to determine\n * the position from where it should resume receiving events when your application gets restarted.\n * It is also used by the client to load balance multiple instances of your application.\n * @param options - A set of options to apply when configuring the client.\n * - `retryOptions` : Configures the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n * - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.\n * - `userAgent` : A string to append to the built in user agent string that is passed to the service.\n */\n constructor(\n consumerGroup: string,\n fullyQualifiedNamespace: string,\n eventHubName: string,\n credential: TokenCredential | NamedKeyCredential | SASCredential,\n checkpointStore: CheckpointStore,\n options?: EventHubConsumerClientOptions,\n ); // #3.1\n constructor(\n private _consumerGroup: string,\n connectionStringOrFullyQualifiedNamespace2: string,\n checkpointStoreOrEventHubNameOrOptions3?:\n | CheckpointStore\n | EventHubConsumerClientOptions\n | string,\n checkpointStoreOrCredentialOrOptions4?:\n | CheckpointStore\n | EventHubConsumerClientOptions\n | TokenCredential\n | NamedKeyCredential\n | SASCredential,\n checkpointStoreOrOptions5?: CheckpointStore | EventHubConsumerClientOptions,\n options6?: EventHubConsumerClientOptions,\n ) {\n if (isCredential(checkpointStoreOrCredentialOrOptions4)) {\n // #3 or 3.1\n logger.info(\"Creating EventHubConsumerClient with TokenCredential.\");\n\n if (isCheckpointStore(checkpointStoreOrOptions5)) {\n // 3.1\n this._checkpointStore = checkpointStoreOrOptions5;\n this._userChoseCheckpointStore = true;\n this._clientOptions = options6 || {};\n } else {\n this._checkpointStore = new InMemoryCheckpointStore();\n this._userChoseCheckpointStore = false;\n this._clientOptions = checkpointStoreOrOptions5 || {};\n }\n\n this._context = createConnectionContext(\n connectionStringOrFullyQualifiedNamespace2,\n checkpointStoreOrEventHubNameOrOptions3 as string,\n checkpointStoreOrCredentialOrOptions4,\n this._clientOptions,\n );\n } else if (typeof checkpointStoreOrEventHubNameOrOptions3 === \"string\") {\n // #2 or 2.1\n logger.info(\"Creating EventHubConsumerClient with connection string and event hub name.\");\n\n if (isCheckpointStore(checkpointStoreOrCredentialOrOptions4)) {\n // 2.1\n this._checkpointStore = checkpointStoreOrCredentialOrOptions4;\n this._userChoseCheckpointStore = true;\n this._clientOptions = (checkpointStoreOrOptions5 as EventHubConsumerClientOptions) || {};\n } else {\n // 2\n this._checkpointStore = new InMemoryCheckpointStore();\n this._userChoseCheckpointStore = false;\n this._clientOptions = checkpointStoreOrCredentialOrOptions4 || {};\n }\n\n this._context = createConnectionContext(\n connectionStringOrFullyQualifiedNamespace2,\n checkpointStoreOrEventHubNameOrOptions3,\n this._clientOptions,\n );\n } else {\n // #1 or 1.1\n logger.info(\"Creating EventHubConsumerClient with connection string.\");\n\n if (isCheckpointStore(checkpointStoreOrEventHubNameOrOptions3)) {\n // 1.1\n this._checkpointStore = checkpointStoreOrEventHubNameOrOptions3;\n this._userChoseCheckpointStore = true;\n this._clientOptions =\n (checkpointStoreOrCredentialOrOptions4 as EventHubConsumerClientOptions) || {};\n } else {\n // 1\n this._checkpointStore = new InMemoryCheckpointStore();\n this._userChoseCheckpointStore = false;\n this._clientOptions =\n (checkpointStoreOrEventHubNameOrOptions3 as EventHubConsumerClientOptions) || {};\n }\n\n this._context = createConnectionContext(\n connectionStringOrFullyQualifiedNamespace2,\n this._clientOptions,\n );\n }\n this.identifier = this._clientOptions.identifier ?? getRandomName();\n this._loadBalancingOptions = {\n // default options\n strategy: \"balanced\",\n updateIntervalInMs: 10000,\n partitionOwnershipExpirationIntervalInMs: 60000,\n // options supplied by user\n ...this._clientOptions?.loadBalancingOptions,\n };\n }\n\n /**\n * Closes the AMQP connection to the Event Hub instance,\n * returning a promise that will be resolved when disconnection is completed.\n * @returns Promise<void>\n * @throws Error if the underlying connection encounters an error while closing.\n */\n async close(): Promise<void> {\n // Stop all the actively running subscriptions.\n const activeSubscriptions = Array.from(this._subscriptions);\n await Promise.all(\n activeSubscriptions.map((subscription) => {\n return subscription.close();\n }),\n );\n // Close the connection via the connection context.\n return this._context.close();\n }\n\n /**\n * Provides the id for each partition associated with the Event Hub.\n * @param options - The set of options to apply to the operation call.\n * @returns A promise that resolves with an Array of strings representing the id for\n * each partition associated with the Event Hub.\n * @throws Error if the underlying connection has been closed, create a new EventHubConsumerClient.\n * @throws AbortError if the operation is cancelled via the abortSignal.\n */\n getPartitionIds(options: GetPartitionIdsOptions = {}): Promise<Array<string>> {\n return this._context\n .managementSession!.getEventHubProperties({\n ...options,\n retryOptions: this._clientOptions.retryOptions,\n })\n .then((eventHubProperties) => {\n return eventHubProperties.partitionIds;\n });\n }\n\n /**\n * Provides information about the state of the specified partition.\n * @param partitionId - The id of the partition for which information is required.\n * @param options - The set of options to apply to the operation call.\n * @returns A promise that resolves with information about the state of the partition .\n * @throws Error if the underlying connection has been closed, create a new EventHubConsumerClient.\n * @throws AbortError if the operation is cancelled via the abortSignal.\n */\n getPartitionProperties(\n partitionId: string,\n options: GetPartitionPropertiesOptions = {},\n ): Promise<PartitionProperties> {\n return this._context.managementSession!.getPartitionProperties(partitionId, {\n ...options,\n retryOptions: this._clientOptions.retryOptions,\n });\n }\n\n /**\n * Provides the Event Hub runtime information.\n * @param options - The set of options to apply to the operation call.\n * @returns A promise that resolves with information about the Event Hub instance.\n * @throws Error if the underlying connection has been closed, create a new EventHubConsumerClient.\n * @throws AbortError if the operation is cancelled via the abortSignal.\n */\n getEventHubProperties(options: GetEventHubPropertiesOptions = {}): Promise<EventHubProperties> {\n return this._context.managementSession!.getEventHubProperties({\n ...options,\n retryOptions: this._clientOptions.retryOptions,\n });\n }\n\n /**\n * Subscribe to events from all partitions.\n *\n * If checkpoint store is provided to the `EventHubConsumerClient` and there are multiple\n * instances of your application, then each instance will subscribe to a subset of the\n * partitions such that the load is balanced amongst them.\n *\n * Call close() on the returned object to stop receiving events.\n *\n * Example usage:\n * ```ts\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,MAA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Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { CheckpointStore, FullEventProcessorOptions } from \"./eventProcessor.js\";\nimport { EventProcessor } from \"./eventProcessor.js\";\nimport type { ConnectionContext } from \"./connectionContext.js\";\nimport { createConnectionContext } from \"./connectionContext.js\";\nimport type {\n EventHubConsumerClientOptions,\n GetEventHubPropertiesOptions,\n GetPartitionIdsOptions,\n GetPartitionPropertiesOptions,\n LoadBalancingOptions,\n} from \"./models/public.js\";\nimport type { EventHubProperties, PartitionProperties } from \"./managementClient.js\";\nimport type { NamedKeyCredential, SASCredential, TokenCredential } from \"@azure/core-auth\";\nimport type {\n SubscribeOptions,\n Subscription,\n SubscriptionEventHandlers,\n} from \"./eventHubConsumerClientModels.js\";\nimport { BalancedLoadBalancingStrategy } from \"./loadBalancerStrategies/balancedStrategy.js\";\nimport { Constants } from \"@azure/core-amqp\";\nimport { GreedyLoadBalancingStrategy } from \"./loadBalancerStrategies/greedyStrategy.js\";\nimport { InMemoryCheckpointStore } from \"./inMemoryCheckpointStore.js\";\nimport type { LoadBalancingStrategy } from \"./loadBalancerStrategies/loadBalancingStrategy.js\";\nimport { PartitionGate } from \"./impl/partitionGate.js\";\nimport { UnbalancedLoadBalancingStrategy } from \"./loadBalancerStrategies/unbalancedStrategy.js\";\nimport { isCredential } from \"./util/typeGuards.js\";\nimport { logger } from \"./logger.js\";\nimport { validateEventPositions } from \"./eventPosition.js\";\nimport { getRandomName } from \"./util/utils.js\";\n\nconst defaultConsumerClientOptions: Required<\n Pick<FullEventProcessorOptions, \"maxWaitTimeInSeconds\" | \"maxBatchSize\">\n> = {\n // to support our current \"process single event only\" workflow we'll also purposefully\n // only request a single event at a time.\n maxBatchSize: 1,\n maxWaitTimeInSeconds: 60,\n};\n\n/**\n * The `EventHubConsumerClient` class is used to consume events from an Event Hub.\n *\n * There are multiple ways to create an `EventHubConsumerClient`\n * - Use the connection string from the SAS policy created for your Event Hub instance.\n * - Use the connection string from the SAS policy created for your Event Hub namespace,\n * and the name of the Event Hub instance\n * - Use the full namespace like `<yournamespace>.servicebus.windows.net`, and a credentials object.\n *\n * Optionally, you can also pass:\n * - An options bag to configure the retry policy or proxy settings.\n * - A checkpoint store that is used by the client to read checkpoints to determine the position from where it should\n * resume receiving events when your application gets restarted. The checkpoint store is also used by the client\n * to load balance multiple instances of your application.\n */\nexport class EventHubConsumerClient {\n /**\n * Describes the amqp connection context for the client.\n */\n private _context: ConnectionContext;\n /**\n * The options passed by the user when creating the EventHubClient instance.\n */\n private _clientOptions: EventHubConsumerClientOptions;\n private _partitionGate = new PartitionGate();\n\n /**\n * The Subscriptions that were spawned by calling `subscribe()`.\n * Subscriptions that have been stopped by the user will not\n * be present in this set.\n */\n private _subscriptions = new Set<Subscription>();\n\n /**\n * The name of the default consumer group in the Event Hubs service.\n */\n static defaultConsumerGroupName: string = Constants.defaultConsumerGroup;\n\n private _checkpointStore: CheckpointStore;\n private _userChoseCheckpointStore: boolean;\n\n /**\n * Options for configuring load balancing.\n */\n private readonly _loadBalancingOptions: Required<LoadBalancingOptions>;\n\n /**\n * @readonly\n * The name of the Event Hub instance for which this client is created.\n */\n get eventHubName(): string {\n return this._context.config.entityPath;\n }\n\n /**\n * @readonly\n * The fully qualified namespace of the Event Hub instance for which this client is created.\n * This is likely to be similar to <yournamespace>.servicebus.windows.net.\n */\n get fullyQualifiedNamespace(): string {\n return this._context.config.host;\n }\n\n /**\n * The name used to identify this EventHubConsumerClient.\n * If not specified or empty, a random unique one will be generated.\n */\n public readonly identifier: string;\n\n /**\n * The `EventHubConsumerClient` class is used to consume events from an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param consumerGroup - The name of the consumer group from which you want to process events.\n * @param connectionString - The connection string to use for connecting to the Event Hub instance.\n * It is expected that the shared key properties and the Event Hub path are contained in this connection string.\n * e.g. 'Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key;EntityPath=my-event-hub-name'.\n * @param options - A set of options to apply when configuring the client.\n * - `retryOptions` : Configures the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n * - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.\n * - `userAgent` : A string to append to the built in user agent string that is passed to the service.\n */\n constructor(\n consumerGroup: string,\n connectionString: string,\n options?: EventHubConsumerClientOptions,\n ); // #1\n /**\n * The `EventHubConsumerClient` class is used to consume events from an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param consumerGroup - The name of the consumer group from which you want to process events.\n * @param connectionString - The connection string to use for connecting to the Event Hub instance.\n * It is expected that the shared key properties and the Event Hub path are contained in this connection string.\n * e.g. 'Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key;EntityPath=my-event-hub-name'.\n * @param checkpointStore - A checkpoint store that is used by the client to read checkpoints to determine\n * the position from where it should resume receiving events when your application gets restarted.\n * It is also used by the client to load balance multiple instances of your application.\n * @param options - A set of options to apply when configuring the client.\n * - `retryOptions` : Configures the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n * - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.\n * - `userAgent` : A string to append to the built in user agent string that is passed to the service.\n */\n constructor(\n consumerGroup: string,\n connectionString: string,\n checkpointStore: CheckpointStore,\n options?: EventHubConsumerClientOptions,\n ); // #1.1\n /**\n * The `EventHubConsumerClient` class is used to consume events from an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param consumerGroup - The name of the consumer group from which you want to process events.\n * @param connectionString - The connection string to use for connecting to the Event Hubs namespace.\n * It is expected that the shared key properties are contained in this connection string, but not the Event Hub path,\n * e.g. 'Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key;'.\n * @param eventHubName - The name of the specific Event Hub to connect the client to.\n * @param options - A set of options to apply when configuring the client.\n * - `retryOptions` : Configures the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n * - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.\n * - `userAgent` : A string to append to the built in user agent string that is passed to the service.\n */\n constructor(\n consumerGroup: string,\n connectionString: string,\n eventHubName: string,\n options?: EventHubConsumerClientOptions,\n ); // #2\n /**\n * The `EventHubConsumerClient` class is used to consume events from an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param consumerGroup - The name of the consumer group from which you want to process events.\n * @param connectionString - The connection string to use for connecting to the Event Hubs namespace.\n * It is expected that the shared key properties are contained in this connection string, but not the Event Hub path,\n * e.g. 'Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key;'.\n * @param eventHubName - The name of the specific Event Hub to connect the client to.\n * @param checkpointStore - A checkpoint store that is used by the client to read checkpoints to determine\n * the position from where it should resume receiving events when your application gets restarted.\n * It is also used by the client to load balance multiple instances of your application.\n * @param options - A set of options to apply when configuring the client.\n * - `retryOptions` : Configures the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n * - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.\n * - `userAgent` : A string to append to the built in user agent string that is passed to the service.\n */\n constructor(\n consumerGroup: string,\n connectionString: string,\n eventHubName: string,\n checkpointStore: CheckpointStore,\n options?: EventHubConsumerClientOptions,\n ); // #2.1\n /**\n * The `EventHubConsumerClient` class is used to consume events from an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param consumerGroup - The name of the consumer group from which you want to process events.\n * @param fullyQualifiedNamespace - The full namespace which is likely to be similar to\n * <yournamespace>.servicebus.windows.net\n * @param eventHubName - The name of the specific Event Hub to connect the client to.\n * @param credential - An credential object used by the client to get the token to authenticate the connection\n * with the Azure Event Hubs service.\n * See &commat;azure/identity for creating credentials that support AAD auth.\n * Use the `AzureNamedKeyCredential` from &commat;azure/core-auth if you want to pass in a `SharedAccessKeyName`\n * and `SharedAccessKey` without using a connection string. These fields map to the `name` and `key` field respectively\n * in `AzureNamedKeyCredential`.\n * Use the `AzureSASCredential` from &commat;azure/core-auth if you want to pass in a `SharedAccessSignature`\n * without using a connection string. This field maps to `signature` in `AzureSASCredential`.\n * @param options - A set of options to apply when configuring the client.\n * - `retryOptions` : Configures the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n * - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.\n * - `userAgent` : A string to append to the built in user agent string that is passed to the service.\n */\n constructor(\n consumerGroup: string,\n fullyQualifiedNamespace: string,\n eventHubName: string,\n credential: TokenCredential | NamedKeyCredential | SASCredential,\n options?: EventHubConsumerClientOptions,\n ); // #3\n /**\n * The `EventHubConsumerClient` class is used to consume events from an Event Hub.\n * Use the `options` parmeter to configure retry policy or proxy settings.\n * @param consumerGroup - The name of the consumer group from which you want to process events.\n * @param fullyQualifiedNamespace - The full namespace which is likely to be similar to\n * <yournamespace>.servicebus.windows.net\n * @param eventHubName - The name of the specific Event Hub to connect the client to.\n * @param credential - An credential object used by the client to get the token to authenticate the connection\n * with the Azure Event Hubs service.\n * See &commat;azure/identity for creating credentials that support AAD auth.\n * Use the `AzureNamedKeyCredential` from &commat;azure/core-auth if you want to pass in a `SharedAccessKeyName`\n * and `SharedAccessKey` without using a connection string. These fields map to the `name` and `key` field respectively\n * in `AzureNamedKeyCredential`.\n * Use the `AzureSASCredential` from &commat;azure/core-auth if you want to pass in a `SharedAccessSignature`\n * without using a connection string. This field maps to `signature` in `AzureSASCredential`.\n * @param checkpointStore - A checkpoint store that is used by the client to read checkpoints to determine\n * the position from where it should resume receiving events when your application gets restarted.\n * It is also used by the client to load balance multiple instances of your application.\n * @param options - A set of options to apply when configuring the client.\n * - `retryOptions` : Configures the retry policy for all the operations on the client.\n * For example, `{ \"maxRetries\": 4 }` or `{ \"maxRetries\": 4, \"retryDelayInMs\": 30000 }`.\n * - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.\n * - `userAgent` : A string to append to the built in user agent string that is passed to the service.\n */\n constructor(\n consumerGroup: string,\n fullyQualifiedNamespace: string,\n eventHubName: string,\n credential: TokenCredential | NamedKeyCredential | SASCredential,\n checkpointStore: CheckpointStore,\n options?: EventHubConsumerClientOptions,\n ); // #3.1\n constructor(\n private _consumerGroup: string,\n connectionStringOrFullyQualifiedNamespace2: string,\n checkpointStoreOrEventHubNameOrOptions3?:\n | CheckpointStore\n | EventHubConsumerClientOptions\n | string,\n checkpointStoreOrCredentialOrOptions4?:\n | CheckpointStore\n | EventHubConsumerClientOptions\n | TokenCredential\n | NamedKeyCredential\n | SASCredential,\n checkpointStoreOrOptions5?: CheckpointStore | EventHubConsumerClientOptions,\n options6?: EventHubConsumerClientOptions,\n ) {\n if (isCredential(checkpointStoreOrCredentialOrOptions4)) {\n // #3 or 3.1\n logger.info(\"Creating EventHubConsumerClient with TokenCredential.\");\n\n if (isCheckpointStore(checkpointStoreOrOptions5)) {\n // 3.1\n this._checkpointStore = checkpointStoreOrOptions5;\n this._userChoseCheckpointStore = true;\n this._clientOptions = options6 || {};\n } else {\n this._checkpointStore = new InMemoryCheckpointStore();\n this._userChoseCheckpointStore = false;\n this._clientOptions = checkpointStoreOrOptions5 || {};\n }\n\n this._context = createConnectionContext(\n connectionStringOrFullyQualifiedNamespace2,\n checkpointStoreOrEventHubNameOrOptions3 as string,\n checkpointStoreOrCredentialOrOptions4,\n this._clientOptions,\n );\n } else if (typeof checkpointStoreOrEventHubNameOrOptions3 === \"string\") {\n // #2 or 2.1\n logger.info(\"Creating EventHubConsumerClient with connection string and event hub name.\");\n\n if (isCheckpointStore(checkpointStoreOrCredentialOrOptions4)) {\n // 2.1\n this._checkpointStore = checkpointStoreOrCredentialOrOptions4;\n this._userChoseCheckpointStore = true;\n this._clientOptions = (checkpointStoreOrOptions5 as EventHubConsumerClientOptions) || {};\n } else {\n // 2\n this._checkpointStore = new InMemoryCheckpointStore();\n this._userChoseCheckpointStore = false;\n this._clientOptions = checkpointStoreOrCredentialOrOptions4 || {};\n }\n\n this._context = createConnectionContext(\n connectionStringOrFullyQualifiedNamespace2,\n checkpointStoreOrEventHubNameOrOptions3,\n this._clientOptions,\n );\n } else {\n // #1 or 1.1\n logger.info(\"Creating EventHubConsumerClient with connection string.\");\n\n if (isCheckpointStore(checkpointStoreOrEventHubNameOrOptions3)) {\n // 1.1\n this._checkpointStore = checkpointStoreOrEventHubNameOrOptions3;\n this._userChoseCheckpointStore = true;\n this._clientOptions =\n (checkpointStoreOrCredentialOrOptions4 as EventHubConsumerClientOptions) || {};\n } else {\n // 1\n this._checkpointStore = new InMemoryCheckpointStore();\n this._userChoseCheckpointStore = false;\n this._clientOptions =\n (checkpointStoreOrEventHubNameOrOptions3 as EventHubConsumerClientOptions) || {};\n }\n\n this._context = createConnectionContext(\n connectionStringOrFullyQualifiedNamespace2,\n this._clientOptions,\n );\n }\n this.identifier = this._clientOptions.identifier ?? getRandomName();\n this._loadBalancingOptions = {\n // default options\n strategy: \"balanced\",\n updateIntervalInMs: 10000,\n partitionOwnershipExpirationIntervalInMs: 60000,\n // options supplied by user\n ...this._clientOptions?.loadBalancingOptions,\n };\n }\n\n /**\n * Closes the AMQP connection to the Event Hub instance,\n * returning a promise that will be resolved when disconnection is completed.\n * @returns Promise<void>\n * @throws Error if the underlying connection encounters an error while closing.\n */\n async close(): Promise<void> {\n // Stop all the actively running subscriptions.\n const activeSubscriptions = Array.from(this._subscriptions);\n await Promise.all(\n activeSubscriptions.map((subscription) => {\n return subscription.close();\n }),\n );\n // Close the connection via the connection context.\n return this._context.close();\n }\n\n /**\n * Provides the id for each partition associated with the Event Hub.\n * @param options - The set of options to apply to the operation call.\n * @returns A promise that resolves with an Array of strings representing the id for\n * each partition associated with the Event Hub.\n * @throws Error if the underlying connection has been closed, create a new EventHubConsumerClient.\n * @throws AbortError if the operation is cancelled via the abortSignal.\n */\n getPartitionIds(options: GetPartitionIdsOptions = {}): Promise<Array<string>> {\n return this._context\n .managementSession!.getEventHubProperties({\n ...options,\n retryOptions: this._clientOptions.retryOptions,\n })\n .then((eventHubProperties) => {\n return eventHubProperties.partitionIds;\n });\n }\n\n /**\n * Provides information about the state of the specified partition.\n * @param partitionId - The id of the partition for which information is required.\n * @param options - The set of options to apply to the operation call.\n * @returns A promise that resolves with information about the state of the partition .\n * @throws Error if the underlying connection has been closed, create a new EventHubConsumerClient.\n * @throws AbortError if the operation is cancelled via the abortSignal.\n */\n getPartitionProperties(\n partitionId: string,\n options: GetPartitionPropertiesOptions = {},\n ): Promise<PartitionProperties> {\n return this._context.managementSession!.getPartitionProperties(partitionId, {\n ...options,\n retryOptions: this._clientOptions.retryOptions,\n });\n }\n\n /**\n * Provides the Event Hub runtime information.\n * @param options - The set of options to apply to the operation call.\n * @returns A promise that resolves with information about the Event Hub instance.\n * @throws Error if the underlying connection has been closed, create a new EventHubConsumerClient.\n * @throws AbortError if the operation is cancelled via the abortSignal.\n */\n getEventHubProperties(options: GetEventHubPropertiesOptions = {}): Promise<EventHubProperties> {\n return this._context.managementSession!.getEventHubProperties({\n ...options,\n retryOptions: this._clientOptions.retryOptions,\n });\n }\n\n /**\n * Subscribe to events from all partitions.\n *\n * If checkpoint store is provided to the `EventHubConsumerClient` and there are multiple\n * instances of your application, then each instance will subscribe to a subset of the\n * partitions such that the load is balanced amongst them.\n *\n * Call close() on the returned object to stop receiving events.\n *\n * Example usage:\n * ```ts snippet:EventHubConsumerClient_Subscribe\n * import { EventHubConsumerClient, earliestEventPosition } from \"@azure/event-hubs\";\n *\n * const client = new EventHubConsumerClient(\"my-consumer-group\", \"connectionString\", \"eventHubName\");\n *\n * const subscription = client.subscribe(\n * {\n * processEvents: async (events, context) => {\n * console.log(\"Received event count: \", events.length);\n * },\n * processError: async (err, context) => {\n * console.log(\"Error: \", err);\n * },\n * },\n * { startPosition: earliestEventPosition },\n * );\n * ```\n *\n * @param handlers - Handlers for the lifecycle of the subscription - subscription initialization\n * per partition, receiving events, handling errors and the closing\n * of a subscription per partition.\n * @param options - Configures the way events are received.\n * Most common are `maxBatchSize` and `maxWaitTimeInSeconds` that control the flow of\n * events to the handler provided to receive events as well as the start position. For example,\n * `{ maxBatchSize: 20, maxWaitTimeInSeconds: 120, startPosition: { sequenceNumber: 123 } }`\n */\n subscribe(handlers: SubscriptionEventHandlers, options?: SubscribeOptions): Subscription; // #1\n /**\n * Subscribe to events from a single partition.\n * Call close() on the returned object to stop receiving events.\n *\n * Example usage:\n * ```ts snippet:EventHubConsumerClient_SubscribeSinglePartition\n * import { EventHubConsumerClient, earliestEventPosition } from \"@azure/event-hubs\";\n *\n * const client = new EventHubConsumerClient(\"my-consumer-group\", \"connectionString\", \"eventHubName\");\n *\n * const partitionIds = await client.getPartitionIds();\n *\n * const subscription = client.subscribe(\n * partitionIds[0],\n * {\n * processEvents: async (events, context) => {\n * console.log(\"Received event count: \", events.length);\n * },\n * processError: async (err, context) => {\n * console.log(\"Error: \", err);\n * },\n * },\n * { startPosition: earliestEventPosition },\n * );\n * ```\n *\n * @param partitionId - The id of the partition to subscribe to.\n * @param handlers - Handlers for the lifecycle of the subscription - subscription initialization\n * of the partition, receiving events, handling errors and the closing\n * of a subscription to the partition.\n * @param options - Configures the way events are received.\n * Most common are `maxBatchSize` and `maxWaitTimeInSeconds` that control the flow of\n * events to the handler provided to receive events as well as the start position. For example,\n * `{ maxBatchSize: 20, maxWaitTimeInSeconds: 120, startPosition: { sequenceNumber: 123 } }`\n */\n\n subscribe(\n partitionId: string,\n handlers: SubscriptionEventHandlers,\n options?: SubscribeOptions,\n ): Subscription; // #2\n subscribe(\n handlersOrPartitionId1?: SubscriptionEventHandlers | string,\n optionsOrHandlers2?: SubscribeOptions | SubscriptionEventHandlers,\n possibleOptions3?: SubscribeOptions,\n ): Subscription {\n let eventProcessor: EventProcessor;\n let targetedPartitionId: string;\n\n if (isSubscriptionEventHandlers(handlersOrPartitionId1)) {\n // #1: subscribe overload - read from all partitions\n const options = optionsOrHandlers2 as SubscribeOptions | undefined;\n if (options && options.startPosition) {\n validateEventPositions(options.startPosition);\n }\n ({ targetedPartitionId, eventProcessor } = this.createEventProcessorForAllPartitions(\n handlersOrPartitionId1,\n options,\n ));\n } else if (isSubscriptionEventHandlers(optionsOrHandlers2)) {\n // #2: subscribe overload (read from specific partition IDs), don't coordinate\n const options = possibleOptions3 as SubscribeOptions | undefined;\n if (options && options.startPosition) {\n validateEventPositions(options.startPosition);\n }\n ({ targetedPartitionId, eventProcessor } = this.createEventProcessorForSinglePartition(\n // cast to string as downstream code expects partitionId to be string, but JS users could have given us anything.\n // we don't validate the user input and instead rely on service throwing errors if any\n String(handlersOrPartitionId1),\n optionsOrHandlers2,\n possibleOptions3,\n ));\n } else {\n throw new TypeError(\"Unhandled subscribe() overload\");\n }\n\n eventProcessor.start();\n\n const subscription = {\n get isRunning() {\n return eventProcessor.isRunning();\n },\n close: () => {\n this._partitionGate.remove(targetedPartitionId);\n this._subscriptions.delete(subscription);\n return eventProcessor.stop();\n },\n };\n this._subscriptions.add(subscription);\n return subscription;\n }\n\n /**\n * Gets the LoadBalancing strategy that should be used based on what the user provided.\n */\n private _getLoadBalancingStrategy(): LoadBalancingStrategy {\n if (!this._userChoseCheckpointStore) {\n // The default behavior when a checkpointstore isn't provided\n // is to always grab all the partitions.\n return new UnbalancedLoadBalancingStrategy();\n }\n\n const partitionOwnershipExpirationIntervalInMs =\n this._loadBalancingOptions.partitionOwnershipExpirationIntervalInMs;\n if (this._loadBalancingOptions?.strategy === \"greedy\") {\n return new GreedyLoadBalancingStrategy(partitionOwnershipExpirationIntervalInMs);\n }\n\n // The default behavior when a checkpointstore is provided is\n // to grab one partition at a time.\n return new BalancedLoadBalancingStrategy(partitionOwnershipExpirationIntervalInMs);\n }\n\n private createEventProcessorForAllPartitions(\n subscriptionEventHandlers: SubscriptionEventHandlers,\n options?: SubscribeOptions,\n ): { targetedPartitionId: string; eventProcessor: EventProcessor } {\n this._partitionGate.add(\"all\");\n\n if (this._userChoseCheckpointStore) {\n logger.verbose(\n \"EventHubConsumerClient subscribing to all partitions, using a checkpoint store.\",\n );\n } else {\n logger.verbose(\"EventHubConsumerClient subscribing to all partitions, no checkpoint store.\");\n }\n\n const loadBalancingStrategy = this._getLoadBalancingStrategy();\n const eventProcessor = this._createEventProcessor(\n this._context,\n subscriptionEventHandlers,\n this._checkpointStore,\n {\n ...defaultConsumerClientOptions,\n ...(options as SubscribeOptions),\n ownerLevel: getOwnerLevel(options, this._userChoseCheckpointStore),\n // make it so all the event processors process work with the same overarching owner ID\n // this allows the EventHubConsumer to unify all the work for any processors that it spawns\n ownerId: this.identifier,\n retryOptions: this._clientOptions.retryOptions,\n loadBalancingStrategy,\n loopIntervalInMs: this._loadBalancingOptions.updateIntervalInMs,\n },\n );\n\n return { targetedPartitionId: \"all\", eventProcessor };\n }\n\n private createEventProcessorForSinglePartition(\n partitionId: string,\n eventHandlers: SubscriptionEventHandlers,\n options?: SubscribeOptions,\n ): { targetedPartitionId: string; eventProcessor: EventProcessor } {\n this._partitionGate.add(partitionId);\n\n const subscribeOptions = options as SubscribeOptions | undefined;\n\n if (this._userChoseCheckpointStore) {\n logger.verbose(\n `EventHubConsumerClient subscribing to specific partition (${partitionId}), using a checkpoint store.`,\n );\n } else {\n logger.verbose(\n `EventHubConsumerClient subscribing to specific partition (${partitionId}), no checkpoint store.`,\n );\n }\n\n const eventProcessor = this._createEventProcessor(\n this._context,\n eventHandlers,\n this._checkpointStore,\n {\n ...defaultConsumerClientOptions,\n ...options,\n processingTarget: partitionId,\n ownerLevel: getOwnerLevel(subscribeOptions, this._userChoseCheckpointStore),\n retryOptions: this._clientOptions.retryOptions,\n loadBalancingStrategy: new UnbalancedLoadBalancingStrategy(),\n loopIntervalInMs: this._loadBalancingOptions.updateIntervalInMs ?? 10000,\n },\n );\n\n return { targetedPartitionId: partitionId, eventProcessor };\n }\n\n private _createEventProcessor(\n connectionContext: ConnectionContext,\n subscriptionEventHandlers: SubscriptionEventHandlers,\n checkpointStore: CheckpointStore,\n options: FullEventProcessorOptions,\n ): EventProcessor {\n return new EventProcessor(\n this._consumerGroup,\n connectionContext,\n subscriptionEventHandlers,\n checkpointStore,\n options,\n );\n }\n}\n\n/**\n * @internal\n */\nexport function isCheckpointStore(possible: CheckpointStore | any): possible is CheckpointStore {\n if (!possible) {\n return false;\n }\n\n const checkpointStore = possible as CheckpointStore;\n\n return (\n typeof checkpointStore.claimOwnership === \"function\" &&\n typeof checkpointStore.listCheckpoints === \"function\" &&\n typeof checkpointStore.listOwnership === \"function\" &&\n typeof checkpointStore.updateCheckpoint === \"function\"\n );\n}\n\n/**\n * @internal\n */\nfunction isSubscriptionEventHandlers(\n possible: any | SubscriptionEventHandlers,\n): possible is SubscriptionEventHandlers {\n return typeof (possible as SubscriptionEventHandlers).processEvents === \"function\";\n}\n\nfunction getOwnerLevel(\n options: SubscribeOptions | undefined,\n userChoseCheckpointStore: boolean,\n): number | undefined {\n if (options && options.ownerLevel) {\n return options.ownerLevel;\n }\n\n if (userChoseCheckpointStore) {\n return 0;\n } else {\n return undefined;\n }\n}\n"]}
@@ -121,19 +121,30 @@ export declare class EventHubProducerClient {
121
121
  * for effecient management of batches.
122
122
  *
123
123
  * Example usage:
124
- * ```ts
125
- * const client = new EventHubProducerClient(connectionString);
124
+ * ```ts snippet:EventHubProducerClient_CreateBatch
125
+ * import { EventHubProducerClient } from "@azure/event-hubs";
126
+ *
127
+ * const client = new EventHubProducerClient("my-connection-string", "my-event-hub");
128
+ *
129
+ * const messages = [
130
+ * { body: "my-event-body1" },
131
+ * { body: "my-event-body2" },
132
+ * { body: "my-event-body3" },
133
+ * { body: "my-event-body4" },
134
+ * { body: "my-event-body5" },
135
+ * ];
136
+ *
126
137
  * let batch = await client.createBatch();
127
138
  * for (let i = 0; i < messages.length; i++) {
128
- * if (!batch.tryAdd(messages[i])) {
129
- * await client.sendBatch(batch);
130
- * batch = await client.createBatch();
131
- * if (!batch.tryAdd(messages[i])) {
132
- * throw new Error("Message too big to fit")
133
- * }
134
- * if (i === messages.length - 1) {
135
- * await client.sendBatch(batch);
136
- * }
139
+ * if (!batch.tryAdd(messages[i])) {
140
+ * await client.sendBatch(batch);
141
+ * batch = await client.createBatch();
142
+ * if (!batch.tryAdd(messages[i])) {
143
+ * throw new Error("Message too big to fit");
144
+ * }
145
+ * if (i === messages.length - 1) {
146
+ * await client.sendBatch(batch);
147
+ * }
137
148
  * }
138
149
  * }
139
150
  * ```
@@ -171,8 +182,19 @@ export declare class EventHubProducerClient {
171
182
  * `EventHubBufferedProducerClient` instead.
172
183
  *
173
184
  * Example usage:
174
- * ```ts
175
- * const client = new EventHubProducerClient(connectionString);
185
+ * ```ts snippet:EventHubProducerClient_SendBatch
186
+ * import { EventHubProducerClient } from "@azure/event-hubs";
187
+ *
188
+ * const client = new EventHubProducerClient("my-connection-string", "my-event-hub");
189
+ *
190
+ * const messages = [
191
+ * { body: "my-event-body1" },
192
+ * { body: "my-event-body2" },
193
+ * { body: "my-event-body3" },
194
+ * { body: "my-event-body4" },
195
+ * { body: "my-event-body5" },
196
+ * ];
197
+ *
176
198
  * await client.sendBatch(messages);
177
199
  * ```
178
200
  *
@@ -202,19 +224,30 @@ export declare class EventHubProducerClient {
202
224
  * for effecient management of batches.
203
225
  *
204
226
  * Example usage:
205
- * ```ts
206
- * const client = new EventHubProducerClient(connectionString);
227
+ * ```ts snippet:EventHubProducerClient_SendBatchPartitioned
228
+ * import { EventHubProducerClient } from "@azure/event-hubs";
229
+ *
230
+ * const client = new EventHubProducerClient("my-connection-string", "my-event-hub");
231
+ *
232
+ * const messages = [
233
+ * { body: "my-event-body1" },
234
+ * { body: "my-event-body2" },
235
+ * { body: "my-event-body3" },
236
+ * { body: "my-event-body4" },
237
+ * { body: "my-event-body5" },
238
+ * ];
239
+ *
207
240
  * let batch = await client.createBatch();
208
241
  * for (let i = 0; i < messages.length; i++) {
209
- * if (!batch.tryAdd(messages[i])) {
210
- * await client.sendBatch(batch);
211
- * batch = await client.createBatch();
212
- * if (!batch.tryAdd(messages[i])) {
213
- * throw new Error("Message too big to fit")
214
- * }
215
- * if (i === messages.length - 1) {
216
- * await client.sendBatch(batch);
217
- * }
242
+ * if (!batch.tryAdd(messages[i])) {
243
+ * await client.sendBatch(batch);
244
+ * batch = await client.createBatch();
245
+ * if (!batch.tryAdd(messages[i])) {
246
+ * throw new Error("Message too big to fit");
247
+ * }
248
+ * if (i === messages.length - 1) {
249
+ * await client.sendBatch(batch);
250
+ * }
218
251
  * }
219
252
  * }
220
253
  * ```
@@ -1 +1 @@
1
- {"version":3,"file":"eventHubProducerClient.d.ts","sourceRoot":"","sources":["../../src/eventHubProducerClient.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACrB,4BAA4B,EAC5B,sBAAsB,EACtB,6BAA6B,EAC7B,gBAAgB,EACjB,MAAM,oBAAoB,CAAC;AAK5B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAErF,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAW3F,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAqB,MAAM,gBAAgB,CAAC;AAGnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAKnE;;;;;;;;;;;GAWG;AACH,qBAAa,sBAAsB;IACjC;;O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AiC,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAO9F;;;;;;;OAOG;IACH,eAAe,CAAC,OAAO,GAAE,sBAA2B,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAW7E;;;;;;;OAOG;IACH,sBAAsB,CACpB,WAAW,EAAE,MAAM,EACnB,OAAO,GAAE,6BAAkC,GAC1C,OAAO,CAAC,mBAAmB,CAAC;CAMhC"}
@@ -67,19 +67,30 @@ export class EventHubProducerClient {
67
67
  * for effecient management of batches.
68
68
  *
69
69
  * Example usage:
70
- * ```ts
71
- * const client = new EventHubProducerClient(connectionString);
70
+ * ```ts snippet:EventHubProducerClient_CreateBatch
71
+ * import { EventHubProducerClient } from "@azure/event-hubs";
72
+ *
73
+ * const client = new EventHubProducerClient("my-connection-string", "my-event-hub");
74
+ *
75
+ * const messages = [
76
+ * { body: "my-event-body1" },
77
+ * { body: "my-event-body2" },
78
+ * { body: "my-event-body3" },
79
+ * { body: "my-event-body4" },
80
+ * { body: "my-event-body5" },
81
+ * ];
82
+ *
72
83
  * let batch = await client.createBatch();
73
84
  * for (let i = 0; i < messages.length; i++) {
74
- * if (!batch.tryAdd(messages[i])) {
75
- * await client.sendBatch(batch);
76
- * batch = await client.createBatch();
77
- * if (!batch.tryAdd(messages[i])) {
78
- * throw new Error("Message too big to fit")
79
- * }
80
- * if (i === messages.length - 1) {
81
- * await client.sendBatch(batch);
82
- * }
85
+ * if (!batch.tryAdd(messages[i])) {
86
+ * await client.sendBatch(batch);
87
+ * batch = await client.createBatch();
88
+ * if (!batch.tryAdd(messages[i])) {
89
+ * throw new Error("Message too big to fit");
90
+ * }
91
+ * if (i === messages.length - 1) {
92
+ * await client.sendBatch(batch);
93
+ * }
83
94
  * }
84
95
  * }
85
96
  * ```