@Override public void close() { if (receiver != null) { try { receiver.close().whenComplete((voidargs, error) -> { try { if (error != null) { logger.error("Exception during receiver close phase" + error.toString()); } ehClient.closeSync(); } catch (Exception e) { logger.error("Exception during ehclient close phase" + e.toString()); } }).get(); } catch (InterruptedException e) { logger.error("Exception occured during close phase" + e.toString()); } catch (ExecutionException e) { logger.error("Exception occured during close phase" + e.toString()); } logger.info("closed eventhub receiver: partitionId=" + partitionId); receiver = null; ehClient = null; } }
@OnStopped public void tearDown() throws ProcessException { for (final PartitionReceiver receiver : partitionToReceiverMap.values()) { if (null != receiver) { receiver.close(); } } partitionToReceiverMap.clear(); try { if (null != eventHubClient) { eventHubClient.closeSync(); } } catch (final ServiceBusException e) { throw new ProcessException(e); } }
private void renewPartitionReceiver(SystemStreamPartition ssp) { String streamId = config.getStreamId(ssp.getStream()); EventHubClientManager eventHubClientManager = perPartitionEventHubManagers.get(ssp); String offset = streamPartitionOffsets.get(ssp); Integer partitionId = ssp.getPartition().getPartitionId(); String consumerGroup = config.getStreamConsumerGroup(ssp.getSystem(), streamId); try { // Close current receiver streamPartitionReceivers.get(ssp).close().get(DEFAULT_SHUTDOWN_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); // Recreate receiver PartitionReceiver receiver = eventHubClientManager.getEventHubClient() .createReceiverSync(consumerGroup, partitionId.toString(), EventPosition.fromOffset(offset, !offset.equals(EventHubSystemConsumer.START_OF_STREAM))); receiver.setPrefetchCount(prefetchCount); // Timeout for EventHubClient receive receiver.setReceiveTimeout(DEFAULT_EVENTHUB_RECEIVER_TIMEOUT); // Create and start receiver thread with handler receiver.setReceiveHandler(streamPartitionHandlers.get(ssp)); streamPartitionReceivers.put(ssp, receiver); } catch (Exception e) { eventHubNonTransientError.set(new SamzaException( String.format("Failed to recreate receiver for EventHubs after ReceiverHandlerError (ssp=%s)", ssp), e)); } }
.thenComposeAsync((partitionReceiverTemp) -> return (partitionReceiverTemp != null) ? partitionReceiverTemp.close() : CompletableFuture.completedFuture(null); }, this.hostContext.getExecutor()) .handleAsync((empty, e) ->