/** * Synchronous version of {@link #send(EventData, String)}. * * @param eventData the {@link EventData} to be sent. * @param partitionKey the partitionKey will be hash'ed to determine the partitionId to send the eventData to. On the Received message this can be accessed at {@link EventData.SystemProperties#getPartitionKey()} * @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 eventData, final String partitionKey) throws EventHubException { ExceptionUtil.syncVoid(() -> this.send(eventData, partitionKey).get()); }
/** * Synchronous version of {@link #send(EventData)}. * * @param data the {@link EventData} to be sent. * @throws PayloadSizeExceededException if the total size of the {@link EventData} exceeds a predefined limit set by the service. Default is 256k bytes. * @throws EventHubException if Service Bus service encountered problems during the operation. * @throws UnresolvedAddressException if there are Client to Service network connectivity issues, if the Azure DNS resolution of the ServiceBus Namespace fails (ex: namespace deleted etc.) */ default void sendSync(final EventData data) throws EventHubException { ExceptionUtil.syncVoid(() -> this.send(data).get()); }
/** * 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, String)}. * * @param eventDatas the batch of events to send to EventHub * @param partitionKey the partitionKey will be hash'ed to determine the partitionId to send the eventData to. On the Received message this can be accessed at {@link EventData.SystemProperties#getPartitionKey()} * @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. * @throws UnresolvedAddressException if there are Client to Service network connectivity issues, if the Azure DNS resolution of the ServiceBus Namespace fails (ex: namespace deleted etc.) */ default void sendSync(final Iterable<EventData> eventDatas, final String partitionKey) throws EventHubException { ExceptionUtil.syncVoid(() -> this.send(eventDatas, partitionKey).get()); }
/** * Synchronous version of {@link #send(Iterable)}. * * @param eventDatas batch of events to send to EventHub * @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. * @throws UnresolvedAddressException if there are Client to Service network connectivity issues, if the Azure DNS resolution of the ServiceBus Namespace fails (ex: namespace deleted etc.) */ default void sendSync(final Iterable<EventData> eventDatas) throws EventHubException { ExceptionUtil.syncVoid(() -> this.send(eventDatas).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(mockEventHubClient.send(any(EventData.class), anyString())) .then((Answer<CompletableFuture<Void>>) invocationOnMock -> { EventData data = invocationOnMock.getArgumentAt(0, EventData.class);