public interface PartitionSender
EventHubClient.send(com.microsoft.azure.eventhubs.EventData) method.| Modifier and Type | Method and Description |
|---|---|
CompletableFuture<Void> |
close() |
void |
closeSync() |
default EventDataBatch |
createBatch()
Creates an Empty Collection of
EventData. |
EventDataBatch |
createBatch(BatchOptions options)
Creates an Empty Collection of
EventData. |
String |
getPartitionId()
The partition id that will receive events from this sender.
|
CompletableFuture<Void> |
send(EventData data)
Send
EventData to a specific EventHub partition. |
CompletableFuture<Void> |
send(EventDataBatch eventDatas)
Send
EventDataBatch to a specific EventHub partition. |
CompletableFuture<Void> |
send(Iterable<EventData> eventDatas)
Send
EventData to a specific EventHub partition. |
default void |
sendSync(EventData data)
Synchronous version of
send(EventData) Api. |
default void |
sendSync(EventDataBatch eventDatas)
Synchronous version of
send(EventDataBatch) |
default void |
sendSync(Iterable<EventData> eventDatas)
Synchronous version of
send(Iterable) . |
String getPartitionId()
EventDataBatch createBatch(BatchOptions options)
EventData.
The same partitionKey must be used while sending these events using send(EventDataBatch).options - see BatchOptions for more usage detailsEventDataBatch, after negotiating maximum message size with EventHubs servicedefault EventDataBatch createBatch()
EventData.
The same partitionKey must be used while sending these events using send(EventDataBatch).EventDataBatch, after negotiating maximum message size with EventHubs servicedefault void sendSync(EventData data) throws EventHubException
send(EventData) Api.data - the EventData to be sent.PayloadSizeExceededException - if the total size of the EventData exceeds a pre-defined limit set by the service. Default is 256k bytes.EventHubException - if Service Bus service encountered problems during the operation.CompletableFuture<Void> send(EventData data)
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.EventHubClient.send(EventData),EventHubClient.send(Iterable),EventHubClient.send(EventDataBatch)ii.EventHubClient.send(EventData, String)orEventHubClient.send(Iterable, String)iii.send(EventData),send(Iterable), orsend(EventDataBatch)
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.
data - the EventData to be sent.default void sendSync(Iterable<EventData> eventDatas) throws EventHubException
send(Iterable) .eventDatas - batch of events to send to EventHubEventHubException - if Service Bus service encountered problems during the operation.CompletableFuture<Void> send(Iterable<EventData> eventDatas)
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), 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 ofEventDatamaximizes the overall throughput by optimally using the number of sessions created to EventHubs' service. ii. Send multipleEventData's in a Transaction. To achieve ACID properties, the Gateway Service will forward allEventData'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)
{
LinkedListEventData events = new LinkedListEventData();
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()));
}
eventDatas - batch of events to send to EventHubdefault void sendSync(EventDataBatch eventDatas) throws EventHubException
send(EventDataBatch)eventDatas - EventDataBatch to send to EventHubEventHubException - if Service Bus service encountered problems during the operation.CompletableFuture<Void> send(EventDataBatch eventDatas)
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), 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 ofEventDatamaximizes the overall throughput by optimally using the number of sessions created to EventHubs' service. ii. Send multipleEventData's in a Transaction. To achieve ACID properties, the Gateway Service will forward allEventData's in the batch to a single EventHubs' partition.
eventDatas - EventDataBatch to send to EventHubsend(Iterable),
EventDataBatchCompletableFuture<Void> close()
void closeSync()
throws EventHubException
EventHubExceptionCopyright © 2019. All rights reserved.