public final class BatchOptions extends Object
EventDataBatches.
If you're creating EventDataBatches with EventHubClient, then you can set a partitionKey and maxMessageSize
using the .with() method. Alternatively, if you'd like the default settings, simply construct BatchOptions with the void constructor.
Default settings:
- partitionKey is null
- maxMessageSize is the maximum allowed size
If you're creating EventDataBatches with PartitionSender, then you can only set a maxMessageSize
using the .with() method. Alternatively, if you'd like the default settings, simply construct BatchOptions with the void constructor.
Default settings:
- maxMessageSize is the maximum allowed size
- Note: if you set a partition key, an IllegalArgumentException will be thrown.
To construct either type of batch, create a BatchOptions object and pass it into the appropriate
createBatch method. If using PartitionSender, then use (PartitionSender.createBatch(BatchOptions).
If using EventHubClient, then use EventHubClient.createBatch(BatchOptions).
// Note: For all examples, 'client' is an instance of EventHubClient. The usage is the same for PartitionSender,
however, you can NOT set a partition key when using PartitionSender
// Create EventDataBatch with defaults
EventDataBatch edb1 = client.createBatch();
// Create EventDataBatch with custom partitionKey
BatchOptions options = new BatchOptions().with( options -> options.partitionKey = "foo");
EventDataBatch edb2 = client.createBatch(options);
// Create EventDataBatch with custom partitionKey and maxMessageSize
BatchOptions options = new BatchOptions().with ( options -> {
options.partitionKey = "foo";
options.maxMessageSize = 100 * 1024;
};
EventDataBatch edb3 = client.createBatch(options);
| Modifier and Type | Field and Description |
|---|---|
Integer |
maxMessageSize
The maximum size in bytes of
EventDataBatch being constructed. |
String |
partitionKey
The partitionKey to use for all
EventDatas sent in the current EventDataBatch. |
| Constructor and Description |
|---|
BatchOptions() |
| Modifier and Type | Method and Description |
|---|---|
BatchOptions |
with(Consumer<BatchOptions> builderFunction) |
public String partitionKey
EventDatas sent in the current EventDataBatch.
Setting a PartitionKey will deliver the EventData to a specific Event Hubs partition.public Integer maxMessageSize
EventDataBatch being constructed.
This value cannot exceed the maximum size supported by Event Hubs service.
EventDataBatch.tryAdd(EventData) API will use this value as the upper limit.public BatchOptions with(Consumer<BatchOptions> builderFunction)
Copyright © 2019 Microsoft Corporation. All rights reserved.