PartitionSender Interface
public interface PartitionSender
This sender class is a logical representation of sending events to a specific EventHub partition. Do not use this class if you do not care about sending events to specific partitions. Instead, use EventHubClient#send method.
Method Summary
Method Details
close
public abstract CompletableFuture
closeSync
createBatch
public default EventDataBatch createBatch()
Creates an Empty Collection of EventData. The same partitionKey must be used while sending these events using send(EventDataBatch eventDatas).
Returns:
createBatch
public abstract EventDataBatch createBatch(BatchOptions options)
Creates an Empty Collection of EventData. The same partitionKey must be used while sending these events using send(EventDataBatch eventDatas).
Parameters:
Returns:
getPartitionId
public abstract String getPartitionId()
The partition id that will receive events from this sender.
Returns:
send
public abstract CompletableFuture
Send EventData to a specific EventHub partition. The target partition is pre-determined when this PartitionSender was created. This send pattern emphasize data correlation over general availability and latency.
There are 3 ways to send to EventHubs, each exposed as a method (along with its sendBatch overload):
i. , ,
ii. or
iii. , , or
Use this type of Send, if:
i. The client wants to take direct control of distribution of data across partitions. In this case client is responsible for making sure there is at least one sender per event hub partition.
ii. User cannot use partition key as a mean to direct events to specific partition, yet there is a need for data correlation with partitioning scheme.
Parameters:
Returns:
send
public abstract CompletableFuture
Send EventDataBatch to a specific EventHub partition. The targeted partition is pre-determined when this PartitionSender was created. A partitionKey cannot be set when using EventDataBatch with a PartitionSender.
There are 3 ways to send to EventHubs, to understand this particular type of Send refer to the overload send(EventData data), which is the same type of Send and is used to send single EventData.
Sending a batch of EventData's is useful in the following cases:
i. Efficient send - sending a batch of maximizes the overall throughput by optimally using the number of sessions created to EventHubs' service.
ii. Send multiple 's in a Transaction. To achieve ACID properties, the Gateway Service will forward all 's in the batch to a single EventHubs' partition.
Parameters:
Returns:
send
public abstract CompletableFuture
Send EventData to a specific EventHub partition. The targeted partition is pre-determined when this PartitionSender was created.
There are 3 ways to send to EventHubs, to understand this particular type of Send refer to the overload send(EventData data), which is the same type of Send and is used to send single EventData.
Sending a batch of EventData's is useful in the following cases:
i. Efficient send - sending a batch of maximizes the overall throughput by optimally using the number of sessions created to EventHubs' service.
ii. Send multiple 's in a Transaction. To achieve ACID properties, the Gateway Service will forward all 's in the batch to a single EventHubs' partition.
Sample code (sample uses sync version of the api but concept are identical):
Gson gson = new GsonBuilder().create();
EventHubClient client = EventHubClient.createSync("__connection__");
PartitionSender senderToPartitionOne = client.createPartitionSenderSync("1");
while (true)
{
LinkedList events = new LinkedList();
for (int count = 1; count < 11; count++)
{
PayloadEvent payload = new PayloadEvent(count);
byte[] payloadBytes = gson.toJson(payload).getBytes(Charset.defaultCharset());
EventData sendEvent = EventData.create(payloadBytes);
sendEvent.getProperties().put("from", "javaClient");
events.add(sendEvent);
}
senderToPartitionOne.sendSync(events);
System.out.println(String.format("Sent Batch... Size: %s", events.size()));
}
Parameters:
Returns:
sendSync
public default void sendSync(EventData data)
Synchronous version of send(EventData data) Api.
Parameters:
Throws:
sendSync
public default void sendSync(EventDataBatch eventDatas)
Synchronous version of send(EventDataBatch eventDatas)
Parameters:
Throws:
sendSync
public default void sendSync(Iterable
Synchronous version of send(Iterable<EventData> eventDatas) .
Parameters:
Throws:
Applies to
Azure SDK for Java