@Override public Map<Symbol, Object> getProperties() { if (!this.isEpochReceiver && (this.receiverOptions == null || this.receiverOptions.getIdentifier() == null)) { return null; } final Map<Symbol, Object> properties = new HashMap<>(); if (this.isEpochReceiver) { properties.put(AmqpConstants.EPOCH, (Object) this.epoch); } if (this.receiverOptions != null && this.receiverOptions.getIdentifier() != null) { properties.put(AmqpConstants.RECEIVER_IDENTIFIER_NAME, (Object) this.receiverOptions.getIdentifier()); } return properties; }
@Override public Symbol[] getDesiredCapabilities() { return this.receiverOptions != null && this.receiverOptions.getReceiverRuntimeMetricEnabled() ? new Symbol[]{AmqpConstants.ENABLE_RECEIVER_RUNTIME_METRIC_NAME} : null; } }
/** * Set an identifier to {@link PartitionReceiver}. * <p> * This identifier will be used by EventHubs service when reporting any errors across receivers, and is caused by this receiver. * For example, when receiver quota limit is hit, while a user is trying to create New receiver, * EventHubs service will throw {@link QuotaExceededException} and will include this identifier. * So, its very critical to choose a value, which can uniquely identify the whereabouts of {@link PartitionReceiver}. * <p> * </p> * * @param value string to identify {@link PartitionReceiver} */ public void setIdentifier(final String value) { ReceiverOptions.validateReceiverIdentifier(value); this.identifier = value; }
ReceiverOptions options = new ReceiverOptions(); options.setReceiverRuntimeMetricEnabled(this.hostContext.getEventProcessorOptions().getReceiverRuntimeMetricEnabled()); options.setPrefetchCount(this.hostContext.getEventProcessorOptions().getPrefetchCount());
static CompletableFuture<PartitionReceiver> create(MessagingFactory factory, final String eventHubName, final String consumerGroupName, final String partitionId, final EventPosition eventPosition, final long epoch, final boolean isEpochReceiver, ReceiverOptions receiverOptions, final ScheduledExecutorService executor) { if (epoch < NULL_EPOCH) { throw new IllegalArgumentException("epoch cannot be a negative value. Please specify a zero or positive long value."); } if (StringUtil.isNullOrWhiteSpace(consumerGroupName)) { throw new IllegalArgumentException("specify valid string for argument - 'consumerGroupName'"); } if (receiverOptions == null) { receiverOptions = new ReceiverOptions(); } final PartitionReceiverImpl receiver = new PartitionReceiverImpl(factory, eventHubName, consumerGroupName, partitionId, (EventPositionImpl) eventPosition, epoch, isEpochReceiver, receiverOptions, executor); return receiver.createInternalReceiver().thenApplyAsync(new Function<Void, PartitionReceiver>() { public PartitionReceiver apply(Void a) { return receiver; } }, executor); }
private CompletableFuture<Void> createInternalReceiver() { return MessageReceiver.create(this.underlyingFactory, this.getClientId().concat("-InternalReceiver"), String.format("%s/ConsumerGroups/%s/Partitions/%s", this.eventHubName, this.consumerGroupName, this.partitionId), this.receiverOptions.getPrefetchCount(), this) .thenAcceptAsync(new Consumer<MessageReceiver>() { public void accept(MessageReceiver r) { PartitionReceiverImpl.this.internalReceiver = r; } }, this.executor); }
private PartitionReceiverImpl(MessagingFactory factory, final String eventHubName, final String consumerGroupName, final String partitionId, final EventPositionImpl eventPosition, final Long epoch, final boolean isEpochReceiver, final ReceiverOptions receiverOptions, final ScheduledExecutorService executor) { super("PartitionReceiverImpl".concat(StringUtil.getRandomString()), null, executor); this.underlyingFactory = factory; this.eventHubName = eventHubName; this.consumerGroupName = consumerGroupName; this.partitionId = partitionId; this.eventPosition = eventPosition; this.epoch = epoch; this.isEpochReceiver = isEpochReceiver; this.receiveHandlerLock = new Object(); this.receiverOptions = receiverOptions; this.runtimeInformation = (this.receiverOptions != null && this.receiverOptions.getReceiverRuntimeMetricEnabled()) ? new ReceiverRuntimeInformation(partitionId) : null; this.currentEventPosition = EventPosition.fromStartOfStream(); }
@Override public Iterable<EventData> apply(Collection<Message> amqpMessages) { PassByRef<MessageWrapper> lastMessageRef = null; if (PartitionReceiverImpl.this.receiverOptions != null && PartitionReceiverImpl.this.receiverOptions.getReceiverRuntimeMetricEnabled()) lastMessageRef = new PassByRef<>(); final Iterable<EventData> events = EventDataUtil.toEventDataCollection(amqpMessages, lastMessageRef); if (lastMessageRef != null && lastMessageRef.get() != null) { final DeliveryAnnotations deliveryAnnotations = lastMessageRef.get().getMessage().getDeliveryAnnotations(); if (deliveryAnnotations != null && deliveryAnnotations.getValue() != null) { final Map<Symbol, Object> deliveryAnnotationsMap = deliveryAnnotations.getValue(); PartitionReceiverImpl.this.runtimeInformation.setRuntimeInformation( (long) deliveryAnnotationsMap.get(ClientConstants.LAST_ENQUEUED_SEQUENCE_NUMBER), ((Date) deliveryAnnotationsMap.get(ClientConstants.LAST_ENQUEUED_TIME_UTC)).toInstant(), (String) deliveryAnnotationsMap.get(ClientConstants.LAST_ENQUEUED_OFFSET)); } PartitionReceiverImpl.this.currentEventPosition = lastMessageRef.get().getEventPosition(); } return events; } }, this.executor);