public final class PartitionSender extends ClientEntity
EventHubClient.send(com.microsoft.azure.eventhubs.EventData) method.| Modifier and Type | Method and Description |
|---|---|
CompletableFuture<Void> |
onClose() |
CompletableFuture<Void> |
send(EventData data)
Send
EventData to a specific EventHub partition. |
CompletableFuture<Void> |
send(Iterable<EventData> eventDatas)
Send
EventData to a specific EventHub partition. |
void |
sendSync(EventData data)
Synchronous version of
send(EventData) Api. |
void |
sendSync(Iterable<EventData> eventDatas)
Synchronous version of
send(Iterable) . |
close, closeSync, getClientId, getLastKnownError, setClosed, throwIfClosedpublic final void sendSync(EventData data) throws ServiceBusException
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.ServiceBusException - if Service Bus service encountered problems during the operation.public final 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)orEventHubClient.send(Iterable)ii.EventHubClient.send(EventData, String)orEventHubClient.send(Iterable, String)iii.send(EventData)orsend(Iterable)
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.public final void sendSync(Iterable<EventData> eventDatas) throws ServiceBusException
send(Iterable) .eventDatas - batch of events to send to EventHubServiceBusException - if Service Bus service encountered problems during the operation.public final CompletableFuture<Void> send(Iterable<EventData> eventDatas) throws ServiceBusException
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.createFromConnectionStringSync("__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 = new EventData(payloadBytes);
MapString, String applicationProperties = new HashMapString, String();
applicationProperties.put("from", "javaClient");
sendEvent.setProperties(applicationProperties);
events.add(sendEvent);
}
senderToPartitionOne.sendSync(events);
System.out.println(String.format("Sent Batch... Size: %s", events.size()));
}
eventDatas - batch of events to send to EventHubPayloadSizeExceededException - if the total size of the EventData exceeds a pre-defined limit set by the service. Default is 256k bytes.ServiceBusException - if Service Bus service encountered problems during the operation.public CompletableFuture<Void> onClose()
onClose in class ClientEntityCopyright © 2017. All rights reserved.