Source:
public synchronized void send(String destination, OutgoingMessageEnvelope envelope) { if (!isStarted) { throw new SamzaException("Trying to call send before the producer is started."); } if (!eventHubClients.containsKey(destination)) { String msg = String.format("Trying to send event to a destination {%s} that is not registered.", destination); LOG.error(msg); throw new SamzaException(msg); } if (sendExceptionOnCallback != null) { SamzaException e = new SamzaException(sendExceptionOnCallback); sendExceptionOnCallback = null; pendingFutures.clear(); LOG.error("One of the previous sends failed."); throw e; } EventData eventData = createEventData(destination, envelope); int eventDataLength = eventData.getBytes() == null ? 0 : eventData.getBytes().length; eventWriteRate.get(destination).inc(); aggEventWriteRate.inc(); eventByteWriteRate.get(destination).inc(eventDataLength); aggEventByteWriteRate.inc(eventDataLength); EventHubClientWrapper ehClient = eventHubClients.get(destination); Instant startTime = Instant.now(); CompletableFuture<Void> sendResult = sendToEventHub(destination, eventData, getEnvelopePartitionId(envelope), ehClient.getEventHubClient()); Instant endTime = Instant.now(); long latencyMs = Duration.between(startTime, endTime).toMillis(); sendLatency.get(destination).update(latencyMs); aggSendLatency.update(latencyMs); long messageId = ++this.messageId; if (messageId == Long.MAX_VALUE) { this.messageId = 0; } pendingFutures.put(messageId, sendResult); sendResult.handle((aVoid, throwable) -> { long callbackLatencyMs = Duration.between(endTime, Instant.now()).toMillis(); sendCallbackLatency.get(destination).update(callbackLatencyMs); aggSendCallbackLatency.update(callbackLatencyMs); if (throwable != null) { sendErrors.get(destination).inc(); aggSendErrors.inc(); LOG.error("Send message to event hub: failed with exception: ", destination, throwable); sendExceptionOnCallback = throwable; } pendingFutures.remove(messageId); return aVoid; }); }

Target:
public synchronized void send(String destination, OutgoingMessageEnvelope envelope) { if (!isStarted) { throw new SamzaException("Trying to call send before the producer is started."); } if (!eventHubClients.containsKey(destination)) { String msg = String.format("Trying to send event to a destination {%s} that is not registered.", destination); throw new SamzaException(msg); } checkCallbackThrowable("Received exception on message send"); EventData eventData = createEventData(destination, envelope); int eventDataLength = eventData.getBytes() == null ? 0 : eventData.getBytes().length; eventWriteRate.get(destination).inc(); aggEventWriteRate.inc(); eventByteWriteRate.get(destination).inc(eventDataLength); aggEventByteWriteRate.inc(eventDataLength); EventHubClientManager ehClient = eventHubClients.get(destination); long beforeSendTimeMs = System.currentTimeMillis(); CompletableFuture<Void> sendResult = sendToEventHub(destination, eventData, getEnvelopePartitionId(envelope), ehClient.getEventHubClient()); long afterSendTimeMs = System.currentTimeMillis(); long latencyMs = afterSendTimeMs - beforeSendTimeMs; sendLatency.get(destination).update(latencyMs); aggSendLatency.update(latencyMs); pendingFutures.add(sendResult); sendResult.handle((aVoid, throwable) -> { long callbackLatencyMs = System.currentTimeMillis() - afterSendTimeMs; sendCallbackLatency.get(destination).update(callbackLatencyMs); aggSendCallbackLatency.update(callbackLatencyMs); if (throwable != null) { sendErrors.get(destination).inc(); aggSendErrors.inc(); LOG.error("Send message to event hub: failed with exception: ", destination, throwable); sendExceptionOnCallback.compareAndSet(null, throwable); } return aVoid; }); }