/** * Synchronous version of {@link #send(EventDataBatch)} * * @param eventDatas EventDataBatch to send to EventHub * @throws EventHubException if Service Bus service encountered problems during the operation. */ default void sendSync(final EventDataBatch eventDatas) throws EventHubException { ExceptionUtil.syncVoid(() -> this.send(eventDatas).get()); }
/** * Synchronous version of {@link #send(Iterable)} . * * @param eventDatas batch of events to send to EventHub * @throws EventHubException if Service Bus service encountered problems during the operation. */ default void sendSync(final Iterable<EventData> eventDatas) throws EventHubException { ExceptionUtil.syncVoid(() -> this.send(eventDatas).get()); }
/** * Synchronous version of {@link #send(EventData)} Api. * * @param data the {@link EventData} to be sent. * @throws PayloadSizeExceededException if the total size of the {@link EventData} exceeds a pre-defined limit set by the service. Default is 256k bytes. * @throws EventHubException if Service Bus service encountered problems during the operation. */ default void sendSync(final EventData data) throws EventHubException { ExceptionUtil.syncVoid(() -> this.send(data).get()); }
private CompletableFuture<Void> doSend(String eventHubName, PartitionSupplier partitionSupplier, List<EventData> eventData) { try { EventHubClient client = this.clientFactory.getOrCreateClient(eventHubName); if (partitionSupplier == null) { return client.send(eventData); } else if (!Strings.isNullOrEmpty(partitionSupplier.getPartitionId())) { return this.clientFactory.getOrCreatePartitionSender(eventHubName, partitionSupplier.getPartitionId()) .send(eventData); } else if (!Strings.isNullOrEmpty(partitionSupplier.getPartitionKey())) { return client.send(eventData, partitionSupplier.getPartitionKey()); } else { return client.send(eventData); } } catch (EventHubRuntimeException e) { log.error(String.format("Failed to send to '%s' ", eventHubName), e); CompletableFuture<Void> future = new CompletableFuture<>(); future.completeExceptionally(e); return future; } }
private CompletableFuture<Void> doSend(String eventHubName, PartitionSupplier partitionSupplier, List<EventData> eventData) { try { EventHubClient client = this.clientFactory.getOrCreateClient(eventHubName); if (partitionSupplier == null) { return client.send(eventData); } else if (!Strings.isNullOrEmpty(partitionSupplier.getPartitionId())) { return this.clientFactory.getOrCreatePartitionSender(eventHubName, partitionSupplier.getPartitionId()) .send(eventData); } else if (!Strings.isNullOrEmpty(partitionSupplier.getPartitionKey())) { return client.send(eventData, partitionSupplier.getPartitionKey()); } else { return client.send(eventData); } } catch (EventHubRuntimeException e) { log.error(String.format("Failed to send to '%s' ", eventHubName), e); CompletableFuture<Void> future = new CompletableFuture<>(); future.completeExceptionally(e); return future; } }
private CompletableFuture<Void> sendToEventHub(String streamId, EventData eventData, Object partitionKey, EventHubClient eventHubClient) { if (PartitioningMethod.ROUND_ROBIN.equals(partitioningMethod)) { return eventHubClient.send(eventData); } else if (PartitioningMethod.EVENT_HUB_HASHING.equals(partitioningMethod)) { if (partitionKey == null) { throw new SamzaException("Partition key cannot be null for EventHub hashing"); } return eventHubClient.send(eventData, convertPartitionKeyToString(partitionKey)); } else if (PartitioningMethod.PARTITION_KEY_AS_PARTITION.equals(partitioningMethod)) { if (!(partitionKey instanceof Integer)) { String msg = "Partition key should be of type Integer"; throw new SamzaException(msg); } Integer numPartition = streamPartitionSenders.get(streamId).size(); Integer destinationPartition = (Integer) partitionKey % numPartition; PartitionSender sender = streamPartitionSenders.get(streamId).get(destinationPartition); return sender.send(eventData); } else { throw new SamzaException("Unknown partitioning method " + partitioningMethod); } }
PowerMockito.when(mockPartitionSender0.send(any(EventData.class))) .then((Answer<CompletableFuture<Void>>) invocationOnMock -> { EventData data = invocationOnMock.getArgumentAt(0, EventData.class); return new CompletableFuture<>(); }); PowerMockito.when(mockPartitionSender1.send(any(EventData.class))) .then((Answer<CompletableFuture<Void>>) invocationOnMock -> { EventData data = invocationOnMock.getArgumentAt(0, EventData.class);