Package com.microsoft.azure.eventhubs
Interface PartitionSender
-
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, useEventHubClient.send(com.microsoft.azure.eventhubs.EventData)
method.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description CompletableFuture<Void>
close()
void
closeSync()
default EventDataBatch
createBatch()
Creates an Empty Collection ofEventData
.EventDataBatch
createBatch(BatchOptions options)
Creates an Empty Collection ofEventData
.String
getPartitionId()
The partition id that will receive events from this sender.CompletableFuture<Void>
send(EventData data)
SendEventData
to a specific EventHub partition.CompletableFuture<Void>
send(EventDataBatch eventDatas)
SendEventDataBatch
to a specific EventHub partition.CompletableFuture<Void>
send(Iterable<EventData> eventDatas)
SendEventData
to a specific EventHub partition.default void
sendSync(EventData data)
Synchronous version ofsend(EventData)
Api.default void
sendSync(EventDataBatch eventDatas)
Synchronous version ofsend(EventDataBatch)
default void
sendSync(Iterable<EventData> eventDatas)
Synchronous version ofsend(Iterable)
.
-
-
-
Method Detail
-
getPartitionId
String getPartitionId()
The partition id that will receive events from this sender.- Returns:
- the partition id the PartitionSender is connected to.
-
createBatch
EventDataBatch createBatch(BatchOptions options)
Creates an Empty Collection ofEventData
. The same partitionKey must be used while sending these events usingsend(EventDataBatch)
.- Parameters:
options
- seeBatchOptions
for more usage details- Returns:
- the empty
EventDataBatch
, after negotiating maximum message size with EventHubs service
-
createBatch
default EventDataBatch createBatch()
Creates an Empty Collection ofEventData
. The same partitionKey must be used while sending these events usingsend(EventDataBatch)
.- Returns:
- the empty
EventDataBatch
, after negotiating maximum message size with EventHubs service
-
sendSync
default void sendSync(EventData data) throws EventHubException
Synchronous version ofsend(EventData)
Api.- Parameters:
data
- theEventData
to be sent.- Throws:
PayloadSizeExceededException
- if the total size of theEventData
exceeds a pre-defined limit set by the service. Default is 256k bytes.EventHubException
- if Service Bus service encountered problems during the operation.
-
send
CompletableFuture<Void> send(EventData data)
SendEventData
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.
- Parameters:
data
- theEventData
to be sent.- Returns:
- a CompletableFuture that can be completed when the send operations is done..
-
sendSync
default void sendSync(Iterable<EventData> eventDatas) throws EventHubException
Synchronous version ofsend(Iterable)
.- Parameters:
eventDatas
- batch of events to send to EventHub- Throws:
EventHubException
- if Service Bus service encountered problems during the operation.
-
send
CompletableFuture<Void> send(Iterable<EventData> eventDatas)
SendEventData
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 singleEventData
.Sending a batch of
EventData
's is useful in the following cases:i. Efficient send - sending a batch of
EventData
maximizes 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) { LinkedList<EventData> events = new LinkedList<EventData>(); 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
default void sendSync(EventDataBatch eventDatas) throws EventHubException
Synchronous version ofsend(EventDataBatch)
- Parameters:
eventDatas
- EventDataBatch to send to EventHub- Throws:
EventHubException
- if Service Bus service encountered problems during the operation.
-
send
CompletableFuture<Void> send(EventDataBatch eventDatas)
SendEventDataBatch
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 singleEventData
.Sending a batch of
EventData
's is useful in the following cases:i. Efficient send - sending a batch of
EventData
maximizes 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.- Parameters:
eventDatas
- EventDataBatch to send to EventHub- Returns:
- a CompletableFuture that can be completed when the send operation is done..
- See Also:
send(Iterable)
,EventDataBatch
-
close
CompletableFuture<Void> close()
-
closeSync
void closeSync() throws EventHubException
- Throws:
EventHubException
-
-