@azure/event-hubs 6.0.2-alpha.20251014.1 → 6.0.2-alpha.20251021.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/batchingPartitionChannel.d.ts.map +1 -1
- package/dist/browser/batchingPartitionChannel.js +2 -1
- package/dist/browser/batchingPartitionChannel.js.map +1 -1
- package/dist/browser/connectionContext.d.ts.map +1 -1
- package/dist/browser/connectionContext.js +10 -4
- package/dist/browser/connectionContext.js.map +1 -1
- package/dist/browser/eventHubBufferedProducerClient.d.ts.map +1 -1
- package/dist/browser/eventHubBufferedProducerClient.js +2 -1
- package/dist/browser/eventHubBufferedProducerClient.js.map +1 -1
- package/dist/browser/eventHubConsumerClient.d.ts.map +1 -1
- package/dist/browser/eventHubConsumerClient.js +3 -6
- package/dist/browser/eventHubConsumerClient.js.map +1 -1
- package/dist/browser/eventHubProducerClient.d.ts.map +1 -1
- package/dist/browser/eventHubProducerClient.js +3 -6
- package/dist/browser/eventHubProducerClient.js.map +1 -1
- package/dist/browser/eventHubSender.d.ts.map +1 -1
- package/dist/browser/eventHubSender.js +6 -4
- package/dist/browser/eventHubSender.js.map +1 -1
- package/dist/browser/partitionReceiver.js +4 -4
- package/dist/browser/partitionReceiver.js.map +1 -1
- package/dist/browser/util/timerLoop.d.ts.map +1 -1
- package/dist/browser/util/timerLoop.js +12 -5
- package/dist/browser/util/timerLoop.js.map +1 -1
- package/dist/commonjs/batchingPartitionChannel.d.ts.map +1 -1
- package/dist/commonjs/batchingPartitionChannel.js +2 -1
- package/dist/commonjs/batchingPartitionChannel.js.map +1 -1
- package/dist/commonjs/connectionContext.d.ts.map +1 -1
- package/dist/commonjs/connectionContext.js +10 -4
- package/dist/commonjs/connectionContext.js.map +1 -1
- package/dist/commonjs/eventHubBufferedProducerClient.d.ts.map +1 -1
- package/dist/commonjs/eventHubBufferedProducerClient.js +2 -1
- package/dist/commonjs/eventHubBufferedProducerClient.js.map +1 -1
- package/dist/commonjs/eventHubConsumerClient.d.ts.map +1 -1
- package/dist/commonjs/eventHubConsumerClient.js +3 -6
- package/dist/commonjs/eventHubConsumerClient.js.map +1 -1
- package/dist/commonjs/eventHubProducerClient.d.ts.map +1 -1
- package/dist/commonjs/eventHubProducerClient.js +3 -6
- package/dist/commonjs/eventHubProducerClient.js.map +1 -1
- package/dist/commonjs/eventHubSender.d.ts.map +1 -1
- package/dist/commonjs/eventHubSender.js +6 -4
- package/dist/commonjs/eventHubSender.js.map +1 -1
- package/dist/commonjs/partitionReceiver.js +4 -4
- package/dist/commonjs/partitionReceiver.js.map +1 -1
- package/dist/commonjs/util/timerLoop.d.ts.map +1 -1
- package/dist/commonjs/util/timerLoop.js +12 -5
- package/dist/commonjs/util/timerLoop.js.map +1 -1
- package/dist/esm/batchingPartitionChannel.d.ts.map +1 -1
- package/dist/esm/batchingPartitionChannel.js +2 -1
- package/dist/esm/batchingPartitionChannel.js.map +1 -1
- package/dist/esm/connectionContext.d.ts.map +1 -1
- package/dist/esm/connectionContext.js +10 -4
- package/dist/esm/connectionContext.js.map +1 -1
- package/dist/esm/eventHubBufferedProducerClient.d.ts.map +1 -1
- package/dist/esm/eventHubBufferedProducerClient.js +2 -1
- package/dist/esm/eventHubBufferedProducerClient.js.map +1 -1
- package/dist/esm/eventHubConsumerClient.d.ts.map +1 -1
- package/dist/esm/eventHubConsumerClient.js +3 -6
- package/dist/esm/eventHubConsumerClient.js.map +1 -1
- package/dist/esm/eventHubProducerClient.d.ts.map +1 -1
- package/dist/esm/eventHubProducerClient.js +3 -6
- package/dist/esm/eventHubProducerClient.js.map +1 -1
- package/dist/esm/eventHubSender.d.ts.map +1 -1
- package/dist/esm/eventHubSender.js +6 -4
- package/dist/esm/eventHubSender.js.map +1 -1
- package/dist/esm/partitionReceiver.js +4 -4
- package/dist/esm/partitionReceiver.js.map +1 -1
- package/dist/esm/util/timerLoop.d.ts.map +1 -1
- package/dist/esm/util/timerLoop.js +12 -5
- package/dist/esm/util/timerLoop.js.map +1 -1
- package/dist/react-native/batchingPartitionChannel.d.ts +94 -0
- package/dist/react-native/batchingPartitionChannel.d.ts.map +1 -0
- package/dist/react-native/batchingPartitionChannel.js +255 -0
- package/dist/react-native/batchingPartitionChannel.js.map +1 -0
- package/dist/react-native/connectionContext.d.ts +108 -0
- package/dist/react-native/connectionContext.d.ts.map +1 -0
- package/dist/react-native/connectionContext.js +310 -0
- package/dist/react-native/connectionContext.js.map +1 -0
- package/dist/react-native/dataTransformer.d.ts +53 -0
- package/dist/react-native/dataTransformer.d.ts.map +1 -0
- package/dist/react-native/dataTransformer.js +133 -0
- package/dist/react-native/dataTransformer.js.map +1 -0
- package/dist/react-native/diagnostics/instrumentEventData.d.ts +28 -0
- package/dist/react-native/diagnostics/instrumentEventData.d.ts.map +1 -0
- package/dist/react-native/diagnostics/instrumentEventData.js +67 -0
- package/dist/react-native/diagnostics/instrumentEventData.js.map +1 -0
- package/dist/react-native/diagnostics/tracing.d.ts +19 -0
- package/dist/react-native/diagnostics/tracing.d.ts.map +1 -0
- package/dist/react-native/diagnostics/tracing.js +40 -0
- package/dist/react-native/diagnostics/tracing.js.map +1 -0
- package/dist/react-native/eventData.d.ts +295 -0
- package/dist/react-native/eventData.d.ts.map +1 -0
- package/dist/react-native/eventData.js +247 -0
- package/dist/react-native/eventData.js.map +1 -0
- package/dist/react-native/eventDataAdapter.d.ts +69 -0
- package/dist/react-native/eventDataAdapter.d.ts.map +1 -0
- package/dist/react-native/eventDataAdapter.js +38 -0
- package/dist/react-native/eventDataAdapter.js.map +1 -0
- package/dist/react-native/eventDataBatch.d.ts +225 -0
- package/dist/react-native/eventDataBatch.d.ts.map +1 -0
- package/dist/react-native/eventDataBatch.js +301 -0
- package/dist/react-native/eventDataBatch.js.map +1 -0
- package/dist/react-native/eventHubBufferedProducerClient.d.ts +323 -0
- package/dist/react-native/eventHubBufferedProducerClient.d.ts.map +1 -0
- package/dist/react-native/eventHubBufferedProducerClient.js +301 -0
- package/dist/react-native/eventHubBufferedProducerClient.js.map +1 -0
- package/dist/react-native/eventHubConsumerClient.d.ts +293 -0
- package/dist/react-native/eventHubConsumerClient.d.ts.map +1 -0
- package/dist/react-native/eventHubConsumerClient.js +336 -0
- package/dist/react-native/eventHubConsumerClient.js.map +1 -0
- package/dist/react-native/eventHubConsumerClientModels.d.ts +218 -0
- package/dist/react-native/eventHubConsumerClientModels.d.ts.map +1 -0
- package/dist/react-native/eventHubConsumerClientModels.js +4 -0
- package/dist/react-native/eventHubConsumerClientModels.js.map +1 -0
- package/dist/react-native/eventHubProducerClient.d.ts +299 -0
- package/dist/react-native/eventHubProducerClient.d.ts.map +1 -0
- package/dist/react-native/eventHubProducerClient.js +366 -0
- package/dist/react-native/eventHubProducerClient.js.map +1 -0
- package/dist/react-native/eventHubSender.d.ts +227 -0
- package/dist/react-native/eventHubSender.d.ts.map +1 -0
- package/dist/react-native/eventHubSender.js +626 -0
- package/dist/react-native/eventHubSender.js.map +1 -0
- package/dist/react-native/eventPosition.d.ts +73 -0
- package/dist/react-native/eventPosition.d.ts.map +1 -0
- package/dist/react-native/eventPosition.js +121 -0
- package/dist/react-native/eventPosition.js.map +1 -0
- package/dist/react-native/eventProcessor.d.ts +232 -0
- package/dist/react-native/eventProcessor.d.ts.map +1 -0
- package/dist/react-native/eventProcessor.js +389 -0
- package/dist/react-native/eventProcessor.js.map +1 -0
- package/dist/react-native/eventhubConnectionConfig.d.ts +96 -0
- package/dist/react-native/eventhubConnectionConfig.d.ts.map +1 -0
- package/dist/react-native/eventhubConnectionConfig.js +98 -0
- package/dist/react-native/eventhubConnectionConfig.js.map +1 -0
- package/dist/react-native/impl/awaitableQueue.d.ts +25 -0
- package/dist/react-native/impl/awaitableQueue.d.ts.map +1 -0
- package/dist/react-native/impl/awaitableQueue.js +51 -0
- package/dist/react-native/impl/awaitableQueue.js.map +1 -0
- package/dist/react-native/impl/partitionAssigner.d.ts +29 -0
- package/dist/react-native/impl/partitionAssigner.d.ts.map +1 -0
- package/dist/react-native/impl/partitionAssigner.js +52 -0
- package/dist/react-native/impl/partitionAssigner.js.map +1 -0
- package/dist/react-native/impl/partitionGate.d.ts +27 -0
- package/dist/react-native/impl/partitionGate.d.ts.map +1 -0
- package/dist/react-native/impl/partitionGate.js +38 -0
- package/dist/react-native/impl/partitionGate.js.map +1 -0
- package/dist/react-native/impl/partitionKeyToIdMapper.d.ts +6 -0
- package/dist/react-native/impl/partitionKeyToIdMapper.d.ts.map +1 -0
- package/dist/react-native/impl/partitionKeyToIdMapper.js +111 -0
- package/dist/react-native/impl/partitionKeyToIdMapper.js.map +1 -0
- package/dist/react-native/inMemoryCheckpointStore.d.ts +44 -0
- package/dist/react-native/inMemoryCheckpointStore.d.ts.map +1 -0
- package/dist/react-native/inMemoryCheckpointStore.js +94 -0
- package/dist/react-native/inMemoryCheckpointStore.js.map +1 -0
- package/dist/react-native/index.d.ts +21 -0
- package/dist/react-native/index.d.ts.map +1 -0
- package/dist/react-native/index.js +12 -0
- package/dist/react-native/index.js.map +1 -0
- package/dist/react-native/loadBalancerStrategies/balancedStrategy.d.ts +30 -0
- package/dist/react-native/loadBalancerStrategies/balancedStrategy.d.ts.map +1 -0
- package/dist/react-native/loadBalancerStrategies/balancedStrategy.js +40 -0
- package/dist/react-native/loadBalancerStrategies/balancedStrategy.js.map +1 -0
- package/dist/react-native/loadBalancerStrategies/greedyStrategy.d.ts +24 -0
- package/dist/react-native/loadBalancerStrategies/greedyStrategy.d.ts.map +1 -0
- package/dist/react-native/loadBalancerStrategies/greedyStrategy.js +29 -0
- package/dist/react-native/loadBalancerStrategies/greedyStrategy.js.map +1 -0
- package/dist/react-native/loadBalancerStrategies/loadBalancingStrategy.d.ts +28 -0
- package/dist/react-native/loadBalancerStrategies/loadBalancingStrategy.d.ts.map +1 -0
- package/dist/react-native/loadBalancerStrategies/loadBalancingStrategy.js +245 -0
- package/dist/react-native/loadBalancerStrategies/loadBalancingStrategy.js.map +1 -0
- package/dist/react-native/loadBalancerStrategies/unbalancedStrategy.d.ts +20 -0
- package/dist/react-native/loadBalancerStrategies/unbalancedStrategy.d.ts.map +1 -0
- package/dist/react-native/loadBalancerStrategies/unbalancedStrategy.js +22 -0
- package/dist/react-native/loadBalancerStrategies/unbalancedStrategy.js.map +1 -0
- package/dist/react-native/logger.d.ts +37 -0
- package/dist/react-native/logger.d.ts.map +1 -0
- package/dist/react-native/logger.js +56 -0
- package/dist/react-native/logger.js.map +1 -0
- package/dist/react-native/managementClient.d.ts +145 -0
- package/dist/react-native/managementClient.d.ts.map +1 -0
- package/dist/react-native/managementClient.js +305 -0
- package/dist/react-native/managementClient.js.map +1 -0
- package/dist/react-native/models/private.d.ts +185 -0
- package/dist/react-native/models/private.d.ts.map +1 -0
- package/dist/react-native/models/private.js +4 -0
- package/dist/react-native/models/private.js.map +1 -0
- package/dist/react-native/models/public.d.ts +240 -0
- package/dist/react-native/models/public.d.ts.map +1 -0
- package/dist/react-native/models/public.js +18 -0
- package/dist/react-native/models/public.js.map +1 -0
- package/dist/react-native/package.json +3 -0
- package/dist/react-native/partitionProcessor.d.ts +134 -0
- package/dist/react-native/partitionProcessor.d.ts.map +1 -0
- package/dist/react-native/partitionProcessor.js +137 -0
- package/dist/react-native/partitionProcessor.js.map +1 -0
- package/dist/react-native/partitionPump.d.ts +38 -0
- package/dist/react-native/partitionPump.d.ts.map +1 -0
- package/dist/react-native/partitionPump.js +175 -0
- package/dist/react-native/partitionPump.js.map +1 -0
- package/dist/react-native/partitionReceiver.d.ts +82 -0
- package/dist/react-native/partitionReceiver.d.ts.map +1 -0
- package/dist/react-native/partitionReceiver.js +335 -0
- package/dist/react-native/partitionReceiver.js.map +1 -0
- package/dist/react-native/pumpManager.d.ts +72 -0
- package/dist/react-native/pumpManager.d.ts.map +1 -0
- package/dist/react-native/pumpManager.js +120 -0
- package/dist/react-native/pumpManager.js.map +1 -0
- package/dist/react-native/util/connectionStringUtils.d.ts +52 -0
- package/dist/react-native/util/connectionStringUtils.d.ts.map +1 -0
- package/dist/react-native/util/connectionStringUtils.js +48 -0
- package/dist/react-native/util/connectionStringUtils.js.map +1 -0
- package/dist/react-native/util/constants.d.ts +25 -0
- package/dist/react-native/util/constants.d.ts.map +1 -0
- package/dist/react-native/util/constants.js +27 -0
- package/dist/react-native/util/constants.js.map +1 -0
- package/dist/react-native/util/delayWithoutThrow.d.ts +8 -0
- package/dist/react-native/util/delayWithoutThrow.d.ts.map +1 -0
- package/dist/react-native/util/delayWithoutThrow.js +17 -0
- package/dist/react-native/util/delayWithoutThrow.js.map +1 -0
- package/dist/react-native/util/error.d.ts +39 -0
- package/dist/react-native/util/error.d.ts.map +1 -0
- package/dist/react-native/util/error.js +103 -0
- package/dist/react-native/util/error.js.map +1 -0
- package/dist/react-native/util/getPromiseParts.d.ts +10 -0
- package/dist/react-native/util/getPromiseParts.d.ts.map +1 -0
- package/dist/react-native/util/getPromiseParts.js +20 -0
- package/dist/react-native/util/getPromiseParts.js.map +1 -0
- package/dist/react-native/util/operationOptions.d.ts +16 -0
- package/dist/react-native/util/operationOptions.d.ts.map +1 -0
- package/dist/react-native/util/operationOptions.js +4 -0
- package/dist/react-native/util/operationOptions.js.map +1 -0
- package/dist/react-native/util/parseEndpoint.d.ts +11 -0
- package/dist/react-native/util/parseEndpoint.d.ts.map +1 -0
- package/dist/react-native/util/parseEndpoint.js +17 -0
- package/dist/react-native/util/parseEndpoint.js.map +1 -0
- package/dist/react-native/util/retries.d.ts +6 -0
- package/dist/react-native/util/retries.d.ts.map +1 -0
- package/dist/react-native/util/retries.js +13 -0
- package/dist/react-native/util/retries.js.map +1 -0
- package/dist/react-native/util/runtimeInfo-react-native.d.mts.map +1 -0
- package/dist/react-native/util/runtimeInfo-react-native.mjs.map +1 -0
- package/dist/react-native/util/runtimeInfo.d.ts +6 -0
- package/dist/react-native/util/runtimeInfo.js +20 -0
- package/dist/react-native/util/timerLoop.d.ts +26 -0
- package/dist/react-native/util/timerLoop.d.ts.map +1 -0
- package/dist/react-native/util/timerLoop.js +34 -0
- package/dist/react-native/util/timerLoop.js.map +1 -0
- package/dist/react-native/util/typeGuards.d.ts +8 -0
- package/dist/react-native/util/typeGuards.d.ts.map +1 -0
- package/dist/react-native/util/typeGuards.js +12 -0
- package/dist/react-native/util/typeGuards.js.map +1 -0
- package/dist/react-native/util/utils.d.ts +7 -0
- package/dist/react-native/util/utils.d.ts.map +1 -0
- package/dist/react-native/util/utils.js +13 -0
- package/dist/react-native/util/utils.js.map +1 -0
- package/dist/react-native/withAuth.d.ts +25 -0
- package/dist/react-native/withAuth.d.ts.map +1 -0
- package/dist/react-native/withAuth.js +84 -0
- package/dist/react-native/withAuth.js.map +1 -0
- package/package.json +16 -11
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { assertIsEventData, isAmqpAnnotatedMessage, populateIdempotentMessageAnnotations, toRheaMessage, } from "./eventData.js";
|
|
4
|
+
import { message } from "rhea-promise";
|
|
5
|
+
import { isDefined, isObjectWithProperties } from "@azure/core-util";
|
|
6
|
+
import { instrumentEventData } from "./diagnostics/instrumentEventData.js";
|
|
7
|
+
import { throwTypeErrorIfParameterMissing } from "./util/error.js";
|
|
8
|
+
/**
|
|
9
|
+
* The amount of bytes to reserve as overhead for a small message.
|
|
10
|
+
*/
|
|
11
|
+
const smallMessageOverhead = 5;
|
|
12
|
+
/**
|
|
13
|
+
* The amount of bytes to reserve as overhead for a large message.
|
|
14
|
+
*/
|
|
15
|
+
const largeMessageOverhead = 8;
|
|
16
|
+
/**
|
|
17
|
+
* The maximum number of bytes that a message may be to be considered small.
|
|
18
|
+
*/
|
|
19
|
+
const smallMessageMaxBytes = 255;
|
|
20
|
+
/**
|
|
21
|
+
* Checks if the provided eventDataBatch is an instance of `EventDataBatch`.
|
|
22
|
+
* @param eventDataBatch - The instance of `EventDataBatch` to verify.
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export function isEventDataBatch(eventDataBatch) {
|
|
26
|
+
return (isObjectWithProperties(eventDataBatch, ["count", "sizeInBytes", "tryAdd"]) &&
|
|
27
|
+
typeof eventDataBatch.tryAdd === "function" &&
|
|
28
|
+
typeof eventDataBatch.count === "number" &&
|
|
29
|
+
typeof eventDataBatch.sizeInBytes === "number");
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* An internal class representing a batch of events which can be used to send events to Event Hub.
|
|
33
|
+
*
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
export class EventDataBatchImpl {
|
|
37
|
+
/**
|
|
38
|
+
* Describes the amqp connection context for the Client.
|
|
39
|
+
*/
|
|
40
|
+
_context;
|
|
41
|
+
/**
|
|
42
|
+
* The Id of the partition to which the batch is expected to be sent to.
|
|
43
|
+
* Specifying this will throw an error if the batch was created using a `partitionKey`.
|
|
44
|
+
*/
|
|
45
|
+
_partitionId;
|
|
46
|
+
/**
|
|
47
|
+
* A value that is hashed to produce a partition assignment.
|
|
48
|
+
* It guarantees that messages with the same partitionKey end up in the same partition.
|
|
49
|
+
* Specifying this will throw an error if the batch was created using a `partitionId`.
|
|
50
|
+
*/
|
|
51
|
+
_partitionKey;
|
|
52
|
+
/**
|
|
53
|
+
* The maximum size allowed for the batch.
|
|
54
|
+
*/
|
|
55
|
+
_maxSizeInBytes;
|
|
56
|
+
/**
|
|
57
|
+
* Current size of the batch in bytes.
|
|
58
|
+
*/
|
|
59
|
+
_sizeInBytes;
|
|
60
|
+
/**
|
|
61
|
+
* Encoded amqp messages.
|
|
62
|
+
*/
|
|
63
|
+
_encodedMessages = [];
|
|
64
|
+
/**
|
|
65
|
+
* Number of events in the batch.
|
|
66
|
+
*/
|
|
67
|
+
_count;
|
|
68
|
+
/**
|
|
69
|
+
* List of 'message' span contexts.
|
|
70
|
+
*/
|
|
71
|
+
_spanContexts = [];
|
|
72
|
+
/**
|
|
73
|
+
* The message annotations to apply on the batch envelope.
|
|
74
|
+
* This will reflect the message annotations on the first event
|
|
75
|
+
* that was added to the batch.
|
|
76
|
+
* A common annotation is the partition key.
|
|
77
|
+
*/
|
|
78
|
+
_batchAnnotations;
|
|
79
|
+
/**
|
|
80
|
+
* Indicates that the batch should be treated as idempotent.
|
|
81
|
+
*/
|
|
82
|
+
_isIdempotent;
|
|
83
|
+
/**
|
|
84
|
+
* The sequence number assigned to the first event in the batch while
|
|
85
|
+
* the batch is being sent to the service.
|
|
86
|
+
*/
|
|
87
|
+
_pendingStartingSequenceNumber;
|
|
88
|
+
/**
|
|
89
|
+
* The publishing sequence number assigned to the first event in the batch at the time
|
|
90
|
+
* the batch was successfully published.
|
|
91
|
+
* If the producer was not configured to apply sequence numbering or if the batch
|
|
92
|
+
* has not yet been successfully published, the value will be `undefined`.
|
|
93
|
+
*/
|
|
94
|
+
_startingPublishSequenceNumber;
|
|
95
|
+
/**
|
|
96
|
+
* EventDataBatch should not be constructed using `new EventDataBatch()`
|
|
97
|
+
* Use the `createBatch()` method on your `EventHubProducer` instead.
|
|
98
|
+
* @internal
|
|
99
|
+
*/
|
|
100
|
+
constructor(context, maxSizeInBytes, isIdempotent, partitionKey, partitionId) {
|
|
101
|
+
this._context = context;
|
|
102
|
+
this._maxSizeInBytes = maxSizeInBytes;
|
|
103
|
+
this._isIdempotent = isIdempotent;
|
|
104
|
+
this._partitionKey = isDefined(partitionKey) ? String(partitionKey) : partitionKey;
|
|
105
|
+
this._partitionId = isDefined(partitionId) ? String(partitionId) : partitionId;
|
|
106
|
+
this._sizeInBytes = 0;
|
|
107
|
+
this._count = 0;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The maximum size of the batch, in bytes.
|
|
111
|
+
* @readonly
|
|
112
|
+
*/
|
|
113
|
+
get maxSizeInBytes() {
|
|
114
|
+
return this._maxSizeInBytes;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The partitionKey set during `EventDataBatch` creation. This value is hashed to
|
|
118
|
+
* produce a partition assignment when the producer is created without a `partitionId`
|
|
119
|
+
* @readonly
|
|
120
|
+
*/
|
|
121
|
+
get partitionKey() {
|
|
122
|
+
return this._partitionKey;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* The partitionId set during `EventDataBatch` creation.
|
|
126
|
+
* If this value is set then partitionKey can not be set.
|
|
127
|
+
* @readonly
|
|
128
|
+
*/
|
|
129
|
+
get partitionId() {
|
|
130
|
+
return this._partitionId;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Size of the `EventDataBatch` instance after the events added to it have been
|
|
134
|
+
* encoded into a single AMQP message.
|
|
135
|
+
* @readonly
|
|
136
|
+
*/
|
|
137
|
+
get sizeInBytes() {
|
|
138
|
+
return this._sizeInBytes;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Number of events in the `EventDataBatch` instance.
|
|
142
|
+
* @readonly
|
|
143
|
+
*/
|
|
144
|
+
get count() {
|
|
145
|
+
return this._count;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* The publishing sequence number assigned to the first event in the batch at the time
|
|
149
|
+
* the batch was successfully published.
|
|
150
|
+
* If the producer was not configured to apply sequence numbering or if the batch
|
|
151
|
+
* has not yet been successfully published, the value will be `undefined`.
|
|
152
|
+
*/
|
|
153
|
+
get startingPublishedSequenceNumber() {
|
|
154
|
+
return this._startingPublishSequenceNumber;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Gets the "message" span contexts that were created when adding events to the batch.
|
|
158
|
+
* @internal
|
|
159
|
+
*/
|
|
160
|
+
get _messageSpanContexts() {
|
|
161
|
+
return this._spanContexts;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Generates an AMQP message that contains the provided encoded events and annotations.
|
|
165
|
+
* @param encodedEvents - The already encoded events to include in the AMQP batch.
|
|
166
|
+
* @param annotations - The message annotations to set on the batch.
|
|
167
|
+
* @param publishingProps - Idempotent publishing properties used to decorate the events in the batch while sending.
|
|
168
|
+
*/
|
|
169
|
+
_generateBatch(encodedEvents, annotations, publishingProps) {
|
|
170
|
+
if (this._isIdempotent && publishingProps) {
|
|
171
|
+
// We need to decode the encoded events, add the idempotent annotations, and re-encode them.
|
|
172
|
+
// We can't lazily encode the events because we rely on `message.encode` to capture the
|
|
173
|
+
// byte length of anything not in `event.body`.
|
|
174
|
+
// Events can't be decorated ahead of time because the publishing properties aren't known
|
|
175
|
+
// until the events are being sent to the service.
|
|
176
|
+
const decodedEvents = encodedEvents.map(message.decode);
|
|
177
|
+
const decoratedEvents = this._decorateRheaMessagesWithPublishingProps(decodedEvents, publishingProps);
|
|
178
|
+
encodedEvents = decoratedEvents.map(message.encode);
|
|
179
|
+
}
|
|
180
|
+
const batchEnvelope = {
|
|
181
|
+
body: message.data_sections(encodedEvents),
|
|
182
|
+
};
|
|
183
|
+
if (annotations) {
|
|
184
|
+
batchEnvelope.message_annotations = annotations;
|
|
185
|
+
}
|
|
186
|
+
return message.encode(batchEnvelope);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Uses the publishingProps to add idempotent properties as message annotations to rhea messages.
|
|
190
|
+
*/
|
|
191
|
+
_decorateRheaMessagesWithPublishingProps(events, publishingProps) {
|
|
192
|
+
if (!this._isIdempotent) {
|
|
193
|
+
return events;
|
|
194
|
+
}
|
|
195
|
+
const { lastPublishedSequenceNumber = 0, ownerLevel, producerGroupId } = publishingProps;
|
|
196
|
+
const startingSequenceNumber = lastPublishedSequenceNumber + 1;
|
|
197
|
+
for (let i = 0; i < events.length; i++) {
|
|
198
|
+
const event = events[i];
|
|
199
|
+
populateIdempotentMessageAnnotations(event, {
|
|
200
|
+
isIdempotentPublishingEnabled: this._isIdempotent,
|
|
201
|
+
ownerLevel,
|
|
202
|
+
producerGroupId,
|
|
203
|
+
publishSequenceNumber: startingSequenceNumber + i,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
this._pendingStartingSequenceNumber = startingSequenceNumber;
|
|
207
|
+
return events;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Annotates a rhea message with placeholder idempotent properties if the batch is idempotent.
|
|
211
|
+
* This is necessary so that we can accurately calculate the size of the batch while adding events.
|
|
212
|
+
* Placeholder values are used because real values won't be known until we attempt to send the batch.
|
|
213
|
+
*/
|
|
214
|
+
_decorateRheaMessageWithPlaceholderIdempotencyProps(event) {
|
|
215
|
+
if (!this._isIdempotent) {
|
|
216
|
+
return event;
|
|
217
|
+
}
|
|
218
|
+
if (!event.message_annotations) {
|
|
219
|
+
event.message_annotations = {};
|
|
220
|
+
}
|
|
221
|
+
// Set placeholder values for these annotations.
|
|
222
|
+
populateIdempotentMessageAnnotations(event, {
|
|
223
|
+
isIdempotentPublishingEnabled: this._isIdempotent,
|
|
224
|
+
ownerLevel: 0,
|
|
225
|
+
publishSequenceNumber: 0,
|
|
226
|
+
producerGroupId: 0,
|
|
227
|
+
});
|
|
228
|
+
return event;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Generates the single AMQP message which is the result of encoding all the events
|
|
232
|
+
* added into the `EventDataBatch` instance.
|
|
233
|
+
*
|
|
234
|
+
* This is not meant for the user to use directly.
|
|
235
|
+
*
|
|
236
|
+
* When the `EventDataBatch` instance is passed to the `send()` method on the `EventHubProducer`,
|
|
237
|
+
* this single batched AMQP message is what gets sent over the wire to the service.
|
|
238
|
+
* @readonly
|
|
239
|
+
*/
|
|
240
|
+
_generateMessage(publishingProps) {
|
|
241
|
+
return this._generateBatch(this._encodedMessages, this._batchAnnotations, publishingProps);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Sets startingPublishSequenceNumber to the pending publish sequence number.
|
|
245
|
+
*/
|
|
246
|
+
_commitPublish() {
|
|
247
|
+
this._startingPublishSequenceNumber = this._pendingStartingSequenceNumber;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Tries to add an event data to the batch if permitted by the batch's size limit.
|
|
251
|
+
* **NOTE**: Always remember to check the return value of this method, before calling it again
|
|
252
|
+
* for the next event.
|
|
253
|
+
*
|
|
254
|
+
* @param eventData - An individual event data object.
|
|
255
|
+
* @returns A boolean value indicating if the event data has been added to the batch or not.
|
|
256
|
+
*/
|
|
257
|
+
tryAdd(eventData, options = {}) {
|
|
258
|
+
throwTypeErrorIfParameterMissing(this._context.connectionId, "tryAdd", "eventData", eventData);
|
|
259
|
+
if (!isAmqpAnnotatedMessage(eventData)) {
|
|
260
|
+
assertIsEventData(eventData);
|
|
261
|
+
}
|
|
262
|
+
const { entityPath, host } = this._context.config;
|
|
263
|
+
const { event: instrumentedEvent, spanContext } = instrumentEventData(eventData, options, entityPath, host);
|
|
264
|
+
// Convert EventData to RheaMessage.
|
|
265
|
+
const amqpMessage = toRheaMessage(instrumentedEvent, this._partitionKey);
|
|
266
|
+
const originalAnnotations = amqpMessage.message_annotations && {
|
|
267
|
+
...amqpMessage.message_annotations,
|
|
268
|
+
};
|
|
269
|
+
this._decorateRheaMessageWithPlaceholderIdempotencyProps(amqpMessage);
|
|
270
|
+
const encodedMessage = message.encode(amqpMessage);
|
|
271
|
+
let currentSize = this._sizeInBytes;
|
|
272
|
+
// The first time an event is added, we need to calculate
|
|
273
|
+
// the overhead of creating an AMQP batch, including the
|
|
274
|
+
// message_annotations that are taken from the 1st message.
|
|
275
|
+
if (this.count === 0) {
|
|
276
|
+
if (originalAnnotations) {
|
|
277
|
+
this._batchAnnotations = originalAnnotations;
|
|
278
|
+
}
|
|
279
|
+
// Figure out the overhead of creating a batch by generating an empty batch
|
|
280
|
+
// with the expected batch annotations.
|
|
281
|
+
currentSize += this._generateBatch([], this._batchAnnotations).length;
|
|
282
|
+
}
|
|
283
|
+
const messageSize = encodedMessage.length;
|
|
284
|
+
const messageOverhead = messageSize <= smallMessageMaxBytes ? smallMessageOverhead : largeMessageOverhead;
|
|
285
|
+
currentSize += messageSize + messageOverhead;
|
|
286
|
+
// Check if the size of the batch exceeds the maximum allowed size
|
|
287
|
+
// once we add the new event to it.
|
|
288
|
+
if (currentSize > this._maxSizeInBytes) {
|
|
289
|
+
return false;
|
|
290
|
+
}
|
|
291
|
+
// The event will fit in the batch, so it is now safe to store it.
|
|
292
|
+
this._encodedMessages.push(encodedMessage);
|
|
293
|
+
if (spanContext) {
|
|
294
|
+
this._spanContexts.push(spanContext);
|
|
295
|
+
}
|
|
296
|
+
this._sizeInBytes = currentSize;
|
|
297
|
+
this._count++;
|
|
298
|
+
return true;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
//# sourceMappingURL=eventDataBatch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eventDataBatch.js","sourceRoot":"","sources":["../../src/eventDataBatch.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,oCAAoC,EACpC,aAAa,GACd,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAErE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,gCAAgC,EAAE,MAAM,iBAAiB,CAAC;AAGnE;;GAEG;AACH,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAC/B;;GAEG;AACH,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAC/B;;GAEG;AACH,MAAM,oBAAoB,GAAG,GAAG,CAAC;AAEjC;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,cAAuB;IACtD,OAAO,CACL,sBAAsB,CAAC,cAAc,EAAE,CAAC,OAAO,EAAE,aAAa,EAAE,QAAQ,CAAC,CAAC;QAC1E,OAAO,cAAc,CAAC,MAAM,KAAK,UAAU;QAC3C,OAAO,cAAc,CAAC,KAAK,KAAK,QAAQ;QACxC,OAAO,cAAc,CAAC,WAAW,KAAK,QAAQ,CAC/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B,WAAW,IAAI,oBAAoB,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,oBAAoB,CAAC;QACpF,WAAW,IAAI,WAAW,GAAG,eAAe,CAAC;QAE7C,kEAAkE;QAClE,mCAAmC;QACnC,IAAI,WAAW,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;YACvC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,kEAAkE;QAClE,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAC3C,IAAI,WAAW,EAAE,CAAC;YAChB,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACvC,CAAC;QAED,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,MAAM,EAAE,CAAC;QACd,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AmqpAnnotatedMessage } from \"@azure/core-amqp\";\nimport type { EventData } from \"./eventData.js\";\nimport {\n assertIsEventData,\n isAmqpAnnotatedMessage,\n populateIdempotentMessageAnnotations,\n toRheaMessage,\n} from \"./eventData.js\";\nimport type { ConnectionContext } from \"./connectionContext.js\";\nimport type { MessageAnnotations, Message as RheaMessage } from \"rhea-promise\";\nimport { message } from \"rhea-promise\";\nimport { isDefined, isObjectWithProperties } from \"@azure/core-util\";\nimport type { OperationTracingOptions, TracingContext } from \"@azure/core-tracing\";\nimport { instrumentEventData } from \"./diagnostics/instrumentEventData.js\";\nimport { throwTypeErrorIfParameterMissing } from \"./util/error.js\";\nimport type { PartitionPublishingProperties } from \"./models/private.js\";\n\n/**\n * The amount of bytes to reserve as overhead for a small message.\n */\nconst smallMessageOverhead = 5;\n/**\n * The amount of bytes to reserve as overhead for a large message.\n */\nconst largeMessageOverhead = 8;\n/**\n * The maximum number of bytes that a message may be to be considered small.\n */\nconst smallMessageMaxBytes = 255;\n\n/**\n * Checks if the provided eventDataBatch is an instance of `EventDataBatch`.\n * @param eventDataBatch - The instance of `EventDataBatch` to verify.\n * @internal\n */\nexport function isEventDataBatch(eventDataBatch: unknown): eventDataBatch is EventDataBatch {\n return (\n isObjectWithProperties(eventDataBatch, [\"count\", \"sizeInBytes\", \"tryAdd\"]) &&\n typeof eventDataBatch.tryAdd === \"function\" &&\n typeof eventDataBatch.count === \"number\" &&\n typeof eventDataBatch.sizeInBytes === \"number\"\n );\n}\n\n/**\n * Options to configure the behavior of the `tryAdd` method on the `EventDataBatch` class.\n */\nexport interface TryAddOptions {\n /**\n * The options to use when creating Spans for tracing.\n */\n tracingOptions?: OperationTracingOptions;\n}\n\n/**\n * An interface representing a batch of events which can be used to send events to Event Hub.\n *\n * To create the batch, use the `createBatch()` method on the `EventHubProducerClient`.\n * To send the batch, use the `sendBatch()` method on the same client.\n * To fill the batch, use the `tryAdd()` method on the batch itself.\n *\n */\nexport interface EventDataBatch {\n /**\n * A value that is hashed and used by the Azure Event Hubs service to determine the partition to\n * which the events are sent. Use the `createBatch()` method on the `EventHubProducerClient` to\n * set the partitionKey.\n * @readonly\n * @internal\n */\n readonly partitionKey?: string;\n\n /**\n * Id of the partition to which the batch of events are sent. Use the `createBatch()` method on\n * the `EventHubProducerClient` to set the partitionId.\n * @readonly\n * @internal\n */\n readonly partitionId?: string;\n\n /**\n * Size of the batch in bytes after the events added to it have been encoded into a single AMQP\n * message.\n * @readonly\n */\n readonly sizeInBytes: number;\n\n /**\n * Number of events added to the batch.\n * @readonly\n */\n readonly count: number;\n\n /**\n * The maximum size of the batch, in bytes. The `tryAdd` function on the batch will return `false`\n * if the event being added causes the size of the batch to exceed this limit. Use the `createBatch()` method on\n * the `EventHubProducerClient` to set the maxSizeInBytes.\n * @readonly\n */\n readonly maxSizeInBytes: number;\n\n /**\n * Adds an event to the batch if permitted by the batch's size limit.\n * **NOTE**: Always remember to check the return value of this method, before calling it again\n * for the next event.\n *\n * @param eventData - An individual event data object or AmqpAnnotatedMessage.\n * @returns A boolean value indicating if the event data has been added to the batch or not.\n */\n tryAdd(eventData: EventData | AmqpAnnotatedMessage, options?: TryAddOptions): boolean;\n}\n\n/**\n * An internal class representing a batch of events which can be used to send events to Event Hub.\n *\n * @internal\n */\nexport class EventDataBatchImpl implements EventDataBatch {\n /**\n * Describes the amqp connection context for the Client.\n */\n private _context: ConnectionContext;\n /**\n * The Id of the partition to which the batch is expected to be sent to.\n * Specifying this will throw an error if the batch was created using a `partitionKey`.\n */\n private _partitionId?: string;\n /**\n * A value that is hashed to produce a partition assignment.\n * It guarantees that messages with the same partitionKey end up in the same partition.\n * Specifying this will throw an error if the batch was created using a `partitionId`.\n */\n private _partitionKey?: string;\n /**\n * The maximum size allowed for the batch.\n */\n private _maxSizeInBytes: number;\n /**\n * Current size of the batch in bytes.\n */\n private _sizeInBytes: number;\n /**\n * Encoded amqp messages.\n */\n private _encodedMessages: Buffer[] = [];\n /**\n * Number of events in the batch.\n */\n private _count: number;\n /**\n * List of 'message' span contexts.\n */\n private _spanContexts: TracingContext[] = [];\n /**\n * The message annotations to apply on the batch envelope.\n * This will reflect the message annotations on the first event\n * that was added to the batch.\n * A common annotation is the partition key.\n */\n private _batchAnnotations?: MessageAnnotations;\n /**\n * Indicates that the batch should be treated as idempotent.\n */\n private _isIdempotent: boolean;\n /**\n * The sequence number assigned to the first event in the batch while\n * the batch is being sent to the service.\n */\n private _pendingStartingSequenceNumber?: number;\n /**\n * The publishing sequence number assigned to the first event in the batch at the time\n * the batch was successfully published.\n * If the producer was not configured to apply sequence numbering or if the batch\n * has not yet been successfully published, the value will be `undefined`.\n */\n private _startingPublishSequenceNumber?: number;\n\n /**\n * EventDataBatch should not be constructed using `new EventDataBatch()`\n * Use the `createBatch()` method on your `EventHubProducer` instead.\n * @internal\n */\n constructor(\n context: ConnectionContext,\n maxSizeInBytes: number,\n isIdempotent: boolean,\n partitionKey?: string,\n partitionId?: string,\n ) {\n this._context = context;\n this._maxSizeInBytes = maxSizeInBytes;\n this._isIdempotent = isIdempotent;\n this._partitionKey = isDefined(partitionKey) ? String(partitionKey) : partitionKey;\n this._partitionId = isDefined(partitionId) ? String(partitionId) : partitionId;\n this._sizeInBytes = 0;\n this._count = 0;\n }\n\n /**\n * The maximum size of the batch, in bytes.\n * @readonly\n */\n get maxSizeInBytes(): number {\n return this._maxSizeInBytes;\n }\n\n /**\n * The partitionKey set during `EventDataBatch` creation. This value is hashed to\n * produce a partition assignment when the producer is created without a `partitionId`\n * @readonly\n */\n get partitionKey(): string | undefined {\n return this._partitionKey;\n }\n\n /**\n * The partitionId set during `EventDataBatch` creation.\n * If this value is set then partitionKey can not be set.\n * @readonly\n */\n get partitionId(): string | undefined {\n return this._partitionId;\n }\n\n /**\n * Size of the `EventDataBatch` instance after the events added to it have been\n * encoded into a single AMQP message.\n * @readonly\n */\n get sizeInBytes(): number {\n return this._sizeInBytes;\n }\n\n /**\n * Number of events in the `EventDataBatch` instance.\n * @readonly\n */\n get count(): number {\n return this._count;\n }\n\n /**\n * The publishing sequence number assigned to the first event in the batch at the time\n * the batch was successfully published.\n * If the producer was not configured to apply sequence numbering or if the batch\n * has not yet been successfully published, the value will be `undefined`.\n */\n get startingPublishedSequenceNumber(): number | undefined {\n return this._startingPublishSequenceNumber;\n }\n\n /**\n * Gets the \"message\" span contexts that were created when adding events to the batch.\n * @internal\n */\n get _messageSpanContexts(): TracingContext[] {\n return this._spanContexts;\n }\n\n /**\n * Generates an AMQP message that contains the provided encoded events and annotations.\n * @param encodedEvents - The already encoded events to include in the AMQP batch.\n * @param annotations - The message annotations to set on the batch.\n * @param publishingProps - Idempotent publishing properties used to decorate the events in the batch while sending.\n */\n private _generateBatch(\n encodedEvents: Buffer[],\n annotations: MessageAnnotations | undefined,\n publishingProps?: PartitionPublishingProperties,\n ): Buffer {\n if (this._isIdempotent && publishingProps) {\n // We need to decode the encoded events, add the idempotent annotations, and re-encode them.\n // We can't lazily encode the events because we rely on `message.encode` to capture the\n // byte length of anything not in `event.body`.\n // Events can't be decorated ahead of time because the publishing properties aren't known\n // until the events are being sent to the service.\n const decodedEvents = encodedEvents.map(message.decode) as unknown as RheaMessage[];\n const decoratedEvents = this._decorateRheaMessagesWithPublishingProps(\n decodedEvents,\n publishingProps,\n );\n encodedEvents = decoratedEvents.map(message.encode);\n }\n\n const batchEnvelope: RheaMessage = {\n body: message.data_sections(encodedEvents),\n };\n if (annotations) {\n batchEnvelope.message_annotations = annotations;\n }\n return message.encode(batchEnvelope);\n }\n\n /**\n * Uses the publishingProps to add idempotent properties as message annotations to rhea messages.\n */\n private _decorateRheaMessagesWithPublishingProps(\n events: RheaMessage[],\n publishingProps: PartitionPublishingProperties,\n ): RheaMessage[] {\n if (!this._isIdempotent) {\n return events;\n }\n\n const { lastPublishedSequenceNumber = 0, ownerLevel, producerGroupId } = publishingProps;\n const startingSequenceNumber = lastPublishedSequenceNumber + 1;\n for (let i = 0; i < events.length; i++) {\n const event = events[i];\n populateIdempotentMessageAnnotations(event, {\n isIdempotentPublishingEnabled: this._isIdempotent,\n ownerLevel,\n producerGroupId,\n publishSequenceNumber: startingSequenceNumber + i,\n });\n }\n\n this._pendingStartingSequenceNumber = startingSequenceNumber;\n return events;\n }\n\n /**\n * Annotates a rhea message with placeholder idempotent properties if the batch is idempotent.\n * This is necessary so that we can accurately calculate the size of the batch while adding events.\n * Placeholder values are used because real values won't be known until we attempt to send the batch.\n */\n private _decorateRheaMessageWithPlaceholderIdempotencyProps(event: RheaMessage): RheaMessage {\n if (!this._isIdempotent) {\n return event;\n }\n\n if (!event.message_annotations) {\n event.message_annotations = {};\n }\n\n // Set placeholder values for these annotations.\n populateIdempotentMessageAnnotations(event, {\n isIdempotentPublishingEnabled: this._isIdempotent,\n ownerLevel: 0,\n publishSequenceNumber: 0,\n producerGroupId: 0,\n });\n\n return event;\n }\n\n /**\n * Generates the single AMQP message which is the result of encoding all the events\n * added into the `EventDataBatch` instance.\n *\n * This is not meant for the user to use directly.\n *\n * When the `EventDataBatch` instance is passed to the `send()` method on the `EventHubProducer`,\n * this single batched AMQP message is what gets sent over the wire to the service.\n * @readonly\n */\n _generateMessage(publishingProps?: PartitionPublishingProperties): Buffer {\n return this._generateBatch(this._encodedMessages, this._batchAnnotations, publishingProps);\n }\n\n /**\n * Sets startingPublishSequenceNumber to the pending publish sequence number.\n */\n _commitPublish(): void {\n this._startingPublishSequenceNumber = this._pendingStartingSequenceNumber;\n }\n\n /**\n * Tries to add an event data to the batch if permitted by the batch's size limit.\n * **NOTE**: Always remember to check the return value of this method, before calling it again\n * for the next event.\n *\n * @param eventData - An individual event data object.\n * @returns A boolean value indicating if the event data has been added to the batch or not.\n */\n public tryAdd(eventData: EventData | AmqpAnnotatedMessage, options: TryAddOptions = {}): boolean {\n throwTypeErrorIfParameterMissing(this._context.connectionId, \"tryAdd\", \"eventData\", eventData);\n if (!isAmqpAnnotatedMessage(eventData)) {\n assertIsEventData(eventData);\n }\n\n const { entityPath, host } = this._context.config;\n const { event: instrumentedEvent, spanContext } = instrumentEventData(\n eventData,\n options,\n entityPath,\n host,\n );\n\n // Convert EventData to RheaMessage.\n const amqpMessage = toRheaMessage(instrumentedEvent, this._partitionKey);\n const originalAnnotations = amqpMessage.message_annotations && {\n ...amqpMessage.message_annotations,\n };\n this._decorateRheaMessageWithPlaceholderIdempotencyProps(amqpMessage);\n const encodedMessage = message.encode(amqpMessage);\n\n let currentSize = this._sizeInBytes;\n // The first time an event is added, we need to calculate\n // the overhead of creating an AMQP batch, including the\n // message_annotations that are taken from the 1st message.\n if (this.count === 0) {\n if (originalAnnotations) {\n this._batchAnnotations = originalAnnotations;\n }\n\n // Figure out the overhead of creating a batch by generating an empty batch\n // with the expected batch annotations.\n currentSize += this._generateBatch([], this._batchAnnotations).length;\n }\n\n const messageSize = encodedMessage.length;\n const messageOverhead =\n messageSize <= smallMessageMaxBytes ? smallMessageOverhead : largeMessageOverhead;\n currentSize += messageSize + messageOverhead;\n\n // Check if the size of the batch exceeds the maximum allowed size\n // once we add the new event to it.\n if (currentSize > this._maxSizeInBytes) {\n return false;\n }\n\n // The event will fit in the batch, so it is now safe to store it.\n this._encodedMessages.push(encodedMessage);\n if (spanContext) {\n this._spanContexts.push(spanContext);\n }\n\n this._sizeInBytes = currentSize;\n this._count++;\n return true;\n }\n}\n"]}
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import type { EventData } from "./eventData.js";
|
|
2
|
+
import type { OperationOptions } from "./util/operationOptions.js";
|
|
3
|
+
import type { EventHubClientOptions, GetEventHubPropertiesOptions, GetPartitionIdsOptions, GetPartitionPropertiesOptions, SendBatchOptions } from "./models/public.js";
|
|
4
|
+
import type { EventHubProperties, PartitionProperties } from "./managementClient.js";
|
|
5
|
+
import type { NamedKeyCredential, SASCredential, TokenCredential } from "@azure/core-auth";
|
|
6
|
+
import type { AmqpAnnotatedMessage } from "@azure/core-amqp";
|
|
7
|
+
/**
|
|
8
|
+
* Contains the events that were successfully sent to the Event Hub,
|
|
9
|
+
* and the partition they were assigned to.
|
|
10
|
+
*/
|
|
11
|
+
export interface OnSendEventsSuccessContext {
|
|
12
|
+
/**
|
|
13
|
+
* The partition each event was assigned.
|
|
14
|
+
*/
|
|
15
|
+
partitionId: string;
|
|
16
|
+
/**
|
|
17
|
+
* The array of {@link EventData} and/or `AmqpAnnotatedMessage` that were successfully sent to the Event Hub.
|
|
18
|
+
*/
|
|
19
|
+
events: Array<EventData | AmqpAnnotatedMessage>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Contains the events that were not successfully sent to the Event Hub,
|
|
23
|
+
* the partition they were assigned to, and the error that was encountered while sending.
|
|
24
|
+
*/
|
|
25
|
+
export interface OnSendEventsErrorContext {
|
|
26
|
+
/**
|
|
27
|
+
* The partition each event was assigned.
|
|
28
|
+
*/
|
|
29
|
+
partitionId: string;
|
|
30
|
+
/**
|
|
31
|
+
* The array of {@link EventData} and/or `AmqpAnnotatedMessage` that were not successfully sent to the Event Hub.
|
|
32
|
+
*/
|
|
33
|
+
events: Array<EventData | AmqpAnnotatedMessage>;
|
|
34
|
+
/**
|
|
35
|
+
* The error that occurred when sending the associated events to the Event Hub.
|
|
36
|
+
*/
|
|
37
|
+
error: Error;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Describes the options that can be provided while creating the `EventHubBufferedProducerClient`.
|
|
41
|
+
*/
|
|
42
|
+
export interface EventHubBufferedProducerClientOptions extends EventHubClientOptions {
|
|
43
|
+
/**
|
|
44
|
+
* The total number of events that can be buffered for publishing at a given time for a given partition.
|
|
45
|
+
*
|
|
46
|
+
* Default: 1500
|
|
47
|
+
*/
|
|
48
|
+
maxEventBufferLengthPerPartition?: number;
|
|
49
|
+
/**
|
|
50
|
+
* The amount of time to wait for a new event to be enqueued in the buffer before publishing a partially full batch.
|
|
51
|
+
*
|
|
52
|
+
* Default: 1 second.
|
|
53
|
+
*/
|
|
54
|
+
maxWaitTimeInMs?: number;
|
|
55
|
+
/**
|
|
56
|
+
* The handler to call once a batch has successfully published.
|
|
57
|
+
*/
|
|
58
|
+
onSendEventsSuccessHandler?: (ctx: OnSendEventsSuccessContext) => void;
|
|
59
|
+
/**
|
|
60
|
+
* The handler to call when a batch fails to publish.
|
|
61
|
+
*/
|
|
62
|
+
onSendEventsErrorHandler: (ctx: OnSendEventsErrorContext) => void;
|
|
63
|
+
/**
|
|
64
|
+
* Indicates whether or not the EventHubProducerClient should enable idempotent publishing to Event Hub partitions.
|
|
65
|
+
* If enabled, the producer will only be able to publish directly to partitions;
|
|
66
|
+
* it will not be able to publish to the Event Hubs gateway for automatic partition routing
|
|
67
|
+
* nor will it be able to use a partition key.
|
|
68
|
+
* Default: false
|
|
69
|
+
*/
|
|
70
|
+
enableIdempotentRetries?: boolean;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Options to configure the `flush` method on the `EventHubBufferedProducerClient`.
|
|
74
|
+
*/
|
|
75
|
+
export interface BufferedFlushOptions extends OperationOptions {
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Options to configure the `close` method on the `EventHubBufferedProducerClient`.
|
|
79
|
+
*/
|
|
80
|
+
export interface BufferedCloseOptions extends OperationOptions {
|
|
81
|
+
/**
|
|
82
|
+
* When `true`, all buffered events that are pending should be sent before closing.
|
|
83
|
+
* When `false`, abandon all buffered events and close immediately.
|
|
84
|
+
* Defaults to `true`.
|
|
85
|
+
*/
|
|
86
|
+
flush?: boolean;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Options to configure the `enqueueEvents` method on the `EventHubBufferedProducerClient`.
|
|
90
|
+
*/
|
|
91
|
+
export interface EnqueueEventOptions extends SendBatchOptions {
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The `EventHubBufferedProducerClient`is used to publish events to a specific Event Hub.
|
|
95
|
+
*
|
|
96
|
+
* The `EventHubBufferedProducerClient` does not publish events immediately.
|
|
97
|
+
* Instead, events are buffered so they can be efficiently batched and published
|
|
98
|
+
* when the batch is full or the `maxWaitTimeInMs` has elapsed with no new events
|
|
99
|
+
* enqueued.
|
|
100
|
+
*
|
|
101
|
+
* Depending on the options specified when events are enqueued, they may be
|
|
102
|
+
* automatically assigned to a partition, grouped according to the specified partition key,
|
|
103
|
+
* or assigned a specifically requested partition.
|
|
104
|
+
*
|
|
105
|
+
* This model is intended to shift the burden of batch management from callers, at the cost of
|
|
106
|
+
* non-deterministic timing, for when events will be published. There are additional trade-offs
|
|
107
|
+
* to consider, as well:
|
|
108
|
+
* - If the application crashes, events in the buffer will not have been published. To prevent
|
|
109
|
+
* data loss, callers are encouraged to track publishing progress using the
|
|
110
|
+
* `onSendEventsSuccessHandler` and `onSendEventsErrorHandler` handlers.
|
|
111
|
+
* - Events specifying a partition key may be assigned a different partition than those using
|
|
112
|
+
* the same key with other producers.
|
|
113
|
+
* - In the unlikely event that a partition becomes temporarily unavailable, the
|
|
114
|
+
* `EventHubBufferedProducerClient` may take longer to recover than other producers.
|
|
115
|
+
*
|
|
116
|
+
* In scenarios where it is important to have events published immediately with a deterministic
|
|
117
|
+
* outcome, ensure that partition keys are assigned to a partition consistent with other
|
|
118
|
+
* publishers, or where maximizing availability is a requirement, using the
|
|
119
|
+
* `EventHubProducerClient` is recommended.
|
|
120
|
+
*/
|
|
121
|
+
export declare class EventHubBufferedProducerClient {
|
|
122
|
+
/**
|
|
123
|
+
* Controls the `abortSignal` passed to each `BatchingPartitionChannel`.
|
|
124
|
+
* Used to signal when a channel should stop waiting for events.
|
|
125
|
+
*/
|
|
126
|
+
private _abortController;
|
|
127
|
+
/**
|
|
128
|
+
* Indicates whether the client has been explicitly closed.
|
|
129
|
+
*/
|
|
130
|
+
private _isClosed;
|
|
131
|
+
/**
|
|
132
|
+
* Handles assigning partitions.
|
|
133
|
+
*/
|
|
134
|
+
private _partitionAssigner;
|
|
135
|
+
/**
|
|
136
|
+
* The known partitionIds that will be used when assigning events to partitions.
|
|
137
|
+
*/
|
|
138
|
+
private _partitionIds;
|
|
139
|
+
/**
|
|
140
|
+
* The EventHubProducerClient to use when creating and sending batches to the Event Hub.
|
|
141
|
+
*/
|
|
142
|
+
private _producer;
|
|
143
|
+
/**
|
|
144
|
+
* Mapping of partitionIds to `BatchingPartitionChannels`.
|
|
145
|
+
* Each `BatchingPartitionChannel` handles buffering events and backpressure independently.
|
|
146
|
+
*/
|
|
147
|
+
private _partitionChannels;
|
|
148
|
+
/**
|
|
149
|
+
* The options passed by the user when creating the EventHubBufferedProducerClient instance.
|
|
150
|
+
*/
|
|
151
|
+
private _clientOptions;
|
|
152
|
+
/**
|
|
153
|
+
* The interval at which the background management operation should run.
|
|
154
|
+
*/
|
|
155
|
+
private _backgroundManagementInterval;
|
|
156
|
+
/**
|
|
157
|
+
* Indicates whether the background management loop is running.
|
|
158
|
+
*/
|
|
159
|
+
private _isBackgroundManagementRunning;
|
|
160
|
+
/**
|
|
161
|
+
* @readonly
|
|
162
|
+
* The name of the Event Hub instance for which this client is created.
|
|
163
|
+
*/
|
|
164
|
+
get eventHubName(): string;
|
|
165
|
+
/**
|
|
166
|
+
* @readonly
|
|
167
|
+
* The fully qualified namespace of the Event Hub instance for which this client is created.
|
|
168
|
+
* This is likely to be similar to <yournamespace>.servicebus.windows.net.
|
|
169
|
+
*/
|
|
170
|
+
get fullyQualifiedNamespace(): string;
|
|
171
|
+
/**
|
|
172
|
+
* The name used to identify this EventHubBufferedProducerClient.
|
|
173
|
+
* If not specified or empty, a random unique one will be generated.
|
|
174
|
+
*/
|
|
175
|
+
readonly identifier: string;
|
|
176
|
+
/**
|
|
177
|
+
* The `EventHubBufferedProducerClient` class is used to send events to an Event Hub.
|
|
178
|
+
* Use the `options` parmeter to configure retry policy or proxy settings.
|
|
179
|
+
* @param connectionString - The connection string to use for connecting to the Event Hub instance.
|
|
180
|
+
* It is expected that the shared key properties and the Event Hub path are contained in this connection string.
|
|
181
|
+
* e.g. 'Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key;EntityPath=my-event-hub-name'.
|
|
182
|
+
* @param options - A set of options to apply when configuring the client.
|
|
183
|
+
* - `retryOptions` : Configures the retry policy for all the operations on the client.
|
|
184
|
+
* For example, `{ "maxRetries": 4 }` or `{ "maxRetries": 4, "retryDelayInMs": 30000 }`.
|
|
185
|
+
* - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.
|
|
186
|
+
* - `userAgent` : A string to append to the built in user agent string that is passed to the service.
|
|
187
|
+
*/
|
|
188
|
+
constructor(connectionString: string, options: EventHubBufferedProducerClientOptions);
|
|
189
|
+
/**
|
|
190
|
+
* The `EventHubBufferedProducerClient` class is used to send events to an Event Hub.
|
|
191
|
+
* Use the `options` parmeter to configure retry policy or proxy settings.
|
|
192
|
+
* @param connectionString - The connection string to use for connecting to the Event Hubs namespace.
|
|
193
|
+
* It is expected that the shared key properties are contained in this connection string, but not the Event Hub path,
|
|
194
|
+
* e.g. 'Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key;'.
|
|
195
|
+
* @param eventHubName - The name of the specific Event Hub to connect the client to.
|
|
196
|
+
* @param options - A set of options to apply when configuring the client.
|
|
197
|
+
* - `retryOptions` : Configures the retry policy for all the operations on the client.
|
|
198
|
+
* For example, `{ "maxRetries": 4 }` or `{ "maxRetries": 4, "retryDelayInMs": 30000 }`.
|
|
199
|
+
* - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.
|
|
200
|
+
* - `userAgent` : A string to append to the built in user agent string that is passed to the service.
|
|
201
|
+
*/
|
|
202
|
+
constructor(connectionString: string, eventHubName: string, options: EventHubBufferedProducerClientOptions);
|
|
203
|
+
/**
|
|
204
|
+
* The `EventHubBufferedProducerClient` class is used to send events to an Event Hub.
|
|
205
|
+
* Use the `options` parmeter to configure retry policy or proxy settings.
|
|
206
|
+
* @param fullyQualifiedNamespace - The full namespace which is likely to be similar to
|
|
207
|
+
* <yournamespace>.servicebus.windows.net
|
|
208
|
+
* @param eventHubName - The name of the specific Event Hub to connect the client to.
|
|
209
|
+
* @param credential - An credential object used by the client to get the token to authenticate the connection
|
|
210
|
+
* with the Azure Event Hubs service.
|
|
211
|
+
* See @azure/identity for creating credentials that support AAD auth.
|
|
212
|
+
* Use the `AzureNamedKeyCredential` from @azure/core-auth if you want to pass in a `SharedAccessKeyName`
|
|
213
|
+
* and `SharedAccessKey` without using a connection string. These fields map to the `name` and `key` field respectively
|
|
214
|
+
* in `AzureNamedKeyCredential`.
|
|
215
|
+
* Use the `AzureSASCredential` from @azure/core-auth if you want to pass in a `SharedAccessSignature`
|
|
216
|
+
* without using a connection string. This field maps to `signature` in `AzureSASCredential`.
|
|
217
|
+
* @param options - A set of options to apply when configuring the client.
|
|
218
|
+
* - `retryOptions` : Configures the retry policy for all the operations on the client.
|
|
219
|
+
* For example, `{ "maxRetries": 4 }` or `{ "maxRetries": 4, "retryDelayInMs": 30000 }`.
|
|
220
|
+
* - `webSocketOptions`: Configures the channelling of the AMQP connection over Web Sockets.
|
|
221
|
+
* - `userAgent` : A string to append to the built in user agent string that is passed to the service.
|
|
222
|
+
*/
|
|
223
|
+
constructor(fullyQualifiedNamespace: string, eventHubName: string, credential: TokenCredential | NamedKeyCredential | SASCredential, options: EventHubBufferedProducerClientOptions);
|
|
224
|
+
/**
|
|
225
|
+
* Closes the AMQP connection to the Event Hub instance,
|
|
226
|
+
* returning a promise that will be resolved when disconnection is completed.
|
|
227
|
+
*
|
|
228
|
+
* This will wait for enqueued events to be flushed to the service before closing
|
|
229
|
+
* the connection.
|
|
230
|
+
* To close without flushing, set the `flush` option to `false`.
|
|
231
|
+
*
|
|
232
|
+
* @param options - The set of options to apply to the operation call.
|
|
233
|
+
* @returns Promise<void>
|
|
234
|
+
* @throws Error if the underlying connection encounters an error while closing.
|
|
235
|
+
*/
|
|
236
|
+
close(options?: BufferedCloseOptions): Promise<void>;
|
|
237
|
+
/**
|
|
238
|
+
* Enqueues an event into the buffer to be published to the Event Hub.
|
|
239
|
+
* If there is no capacity in the buffer when this method is invoked,
|
|
240
|
+
* it will wait for space to become available and ensure that the event
|
|
241
|
+
* has been enqueued.
|
|
242
|
+
*
|
|
243
|
+
* When this call returns, the event has been accepted into the buffer,
|
|
244
|
+
* but it may not have been published yet.
|
|
245
|
+
* Publishing will take place at a nondeterministic point in the future as the buffer is processed.
|
|
246
|
+
*
|
|
247
|
+
* @param events - An {@link EventData} or `AmqpAnnotatedMessage`.
|
|
248
|
+
* @param options - A set of options that can be specified to influence the way in which
|
|
249
|
+
* the event is sent to the associated Event Hub.
|
|
250
|
+
* - `abortSignal` : A signal used to cancel the enqueueEvent operation.
|
|
251
|
+
* - `partitionId` : The partition this set of events will be sent to. If set, `partitionKey` can not be set.
|
|
252
|
+
* - `partitionKey` : A value that is hashed to produce a partition assignment. If set, `partitionId` can not be set.
|
|
253
|
+
* @returns The total number of events that are currently buffered and waiting to be published, across all partitions.
|
|
254
|
+
*/
|
|
255
|
+
enqueueEvent(event: EventData | AmqpAnnotatedMessage, options?: EnqueueEventOptions): Promise<number>;
|
|
256
|
+
/**
|
|
257
|
+
* Enqueues events into the buffer to be published to the Event Hub.
|
|
258
|
+
* If there is no capacity in the buffer when this method is invoked,
|
|
259
|
+
* it will wait for space to become available and ensure that the events
|
|
260
|
+
* have been enqueued.
|
|
261
|
+
*
|
|
262
|
+
* When this call returns, the events have been accepted into the buffer,
|
|
263
|
+
* but it may not have been published yet.
|
|
264
|
+
* Publishing will take place at a nondeterministic point in the future as the buffer is processed.
|
|
265
|
+
*
|
|
266
|
+
* @param events - An array of {@link EventData} or `AmqpAnnotatedMessage`.
|
|
267
|
+
* @param options - A set of options that can be specified to influence the way in which
|
|
268
|
+
* events are sent to the associated Event Hub.
|
|
269
|
+
* - `abortSignal` : A signal used to cancel the enqueueEvents operation.
|
|
270
|
+
* - `partitionId` : The partition this set of events will be sent to. If set, `partitionKey` can not be set.
|
|
271
|
+
* - `partitionKey` : A value that is hashed to produce a partition assignment. If set, `partitionId` can not be set.
|
|
272
|
+
* @returns The total number of events that are currently buffered and waiting to be published, across all partitions.
|
|
273
|
+
*/
|
|
274
|
+
enqueueEvents(events: EventData[] | AmqpAnnotatedMessage[], options?: EnqueueEventOptions): Promise<number>;
|
|
275
|
+
/**
|
|
276
|
+
* Attempts to publish all events in the buffer immediately.
|
|
277
|
+
* This may result in multiple batches being published,
|
|
278
|
+
* the outcome of each of which will be individually reported by
|
|
279
|
+
* the `onSendEventsSuccessHandler` and `onSendEventsErrorHandler` handlers.
|
|
280
|
+
*
|
|
281
|
+
* @param options - The set of options to apply to the operation call.
|
|
282
|
+
*/
|
|
283
|
+
flush(options?: BufferedFlushOptions): Promise<void>;
|
|
284
|
+
/**
|
|
285
|
+
* Provides the Event Hub runtime information.
|
|
286
|
+
* @param options - The set of options to apply to the operation call.
|
|
287
|
+
* @returns A promise that resolves with information about the Event Hub instance.
|
|
288
|
+
* @throws Error if the underlying connection has been closed, create a new EventHubBufferedProducerClient.
|
|
289
|
+
* @throws AbortError if the operation is cancelled via the abortSignal.
|
|
290
|
+
*/
|
|
291
|
+
getEventHubProperties(options?: GetEventHubPropertiesOptions): Promise<EventHubProperties>;
|
|
292
|
+
/**
|
|
293
|
+
* Provides the id for each partition associated with the Event Hub.
|
|
294
|
+
* @param options - The set of options to apply to the operation call.
|
|
295
|
+
* @returns A promise that resolves with an Array of strings representing the id for
|
|
296
|
+
* each partition associated with the Event Hub.
|
|
297
|
+
* @throws Error if the underlying connection has been closed, create a new EventHubBufferedProducerClient.
|
|
298
|
+
* @throws AbortError if the operation is cancelled via the abortSignal.
|
|
299
|
+
*/
|
|
300
|
+
getPartitionIds(options?: GetPartitionIdsOptions): Promise<Array<string>>;
|
|
301
|
+
/**
|
|
302
|
+
* Provides information about the state of the specified partition.
|
|
303
|
+
* @param partitionId - The id of the partition for which information is required.
|
|
304
|
+
* @param options - The set of options to apply to the operation call.
|
|
305
|
+
* @returns A promise that resolves with information about the state of the partition .
|
|
306
|
+
* @throws Error if the underlying connection has been closed, create a new EventHubBufferedProducerClient.
|
|
307
|
+
* @throws AbortError if the operation is cancelled via the abortSignal.
|
|
308
|
+
*/
|
|
309
|
+
getPartitionProperties(partitionId: string, options?: GetPartitionPropertiesOptions): Promise<PartitionProperties>;
|
|
310
|
+
/**
|
|
311
|
+
* Gets the `BatchingPartitionChannel` associated with the partitionId.
|
|
312
|
+
*
|
|
313
|
+
* If one does not exist, it is created.
|
|
314
|
+
*/
|
|
315
|
+
private _getPartitionChannel;
|
|
316
|
+
/**
|
|
317
|
+
* Returns the total number of buffered events across all partitions.
|
|
318
|
+
*/
|
|
319
|
+
private _getTotalBufferedEventsCount;
|
|
320
|
+
private _updatePartitionIds;
|
|
321
|
+
private _startPartitionIdsUpdateLoop;
|
|
322
|
+
}
|
|
323
|
+
//# sourceMappingURL=eventHubBufferedProducerClient.d.ts.map
|