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

Modifier and Type Method and Description
abstract CompletableFuture<Void> close()
abstract void closeSync()
default EventDataBatch createBatch()

Creates an Empty Collection of EventData.

abstract EventDataBatch createBatch(BatchOptions options)

Creates an Empty Collection of EventData.

abstract String getPartitionId()

The partition id that will receive events from this sender.

abstract CompletableFuture<Void> send(EventData data)

Send EventData to a specific EventHub partition.

abstract CompletableFuture<Void> send(EventDataBatch eventDatas)

Send EventDataBatch to a specific EventHub partition.

abstract CompletableFuture<Void> send(Iterable<EventData> eventDatas)

Send EventData to a specific EventHub partition.

default void sendSync(EventData data)

Synchronous version of send(EventData data) Api.

default void sendSync(EventDataBatch eventDatas)

Synchronous version of send(EventDataBatch eventDatas)

default void sendSync(Iterable<EventData> eventDatas)

Synchronous version of send(Iterable<EventData> eventDatas) .

Method Details

close

public abstract CompletableFuture close()

closeSync

public abstract void closeSync()

Throws:

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:

the empty EventDataBatch, after negotiating maximum message size with EventHubs service

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:

options - see BatchOptions for more usage details

Returns:

the empty EventDataBatch, after negotiating maximum message size with EventHubs service

getPartitionId

public abstract String getPartitionId()

The partition id that will receive events from this sender.

Returns:

the partition id the PartitionSender is connected to.

send

public abstract CompletableFuture send(EventData data)

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:

data - the EventData to be sent.

Returns:

a CompletableFuture that can be completed when the send operations is done..

send

public abstract CompletableFuture send(EventDataBatch eventDatas)

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:

eventDatas - EventDataBatch to send to EventHub

Returns:

a CompletableFuture that can be completed when the send operation is done..

send

public abstract CompletableFuture send(Iterable eventDatas)

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:

eventDatas - batch of events to send to EventHub

Returns:

a CompletableFuture that can be completed when the send operations is done..

sendSync

public default void sendSync(EventData data)

Synchronous version of send(EventData data) Api.

Parameters:

data - the EventData to be sent.

Throws:

EventHubException - if the total size of the EventData exceeds a pre-defined limit set by the service. Default is 256k bytes.

sendSync

public default void sendSync(EventDataBatch eventDatas)

Synchronous version of send(EventDataBatch eventDatas)

Parameters:

eventDatas - EventDataBatch to send to EventHub

Throws:

EventHubException - if Service Bus service encountered problems during the operation.

sendSync

public default void sendSync(Iterable eventDatas)

Synchronous version of send(Iterable<EventData> eventDatas) .

Parameters:

eventDatas - batch of events to send to EventHub

Throws:

EventHubException - if Service Bus service encountered problems during the operation.

Applies to