public EventHubSpoutConfig(String username, String password, String namespace, String entityPath, int partitionCount) { this.userName = username; this.password = password; this.connectionString = new ConnectionStringBuilder(namespace, entityPath, username, password).toString(); this.namespace = namespace; this.entityPath = entityPath; this.partitionCount = partitionCount; }
/** * A signature which contains the duration. * After the duration is expired, the signature becomes invalid */ public void refreshSignature () { if (postStartTimestamp == 0 || (System.nanoTime() - postStartTimestamp) > Duration.ofMinutes(sigExpireInMinute).toNanos()) { // generate signature try { signature = SharedAccessSignatureTokenProvider .generateSharedAccessSignature(sasKeyName, sasKey, namespaceName, Duration.ofMinutes(sigExpireInMinute)); postStartTimestamp = System.nanoTime(); LOG.info ("Signature is refreshing: " + signature); } catch (Exception e) { throw new RuntimeException(e); } } }
throw new EventHubException(e); } catch (ServiceBusException e) { logger.error("Exception in creating Receiver" + e.toString()); throw new EventHubException(e);
/** * Creates a message receiver to the entity using the client settings in PeekLock mode * @param namespaceName namespace of entity * @param entityPath path of the entity * @param clientSettings client settings * @return IMessageReceiver instance * @throws InterruptedException if the current thread was interrupted while waiting * @throws ServiceBusException if the receiver cannot be created */ public static IMessageReceiver createMessageReceiverFromEntityPath(String namespaceName, String entityPath, ClientSettings clientSettings) throws InterruptedException, ServiceBusException { return Utils.completeFuture(createMessageReceiverFromEntityPathAsync(namespaceName, entityPath, clientSettings)); }
/** * Creates a message sender to the entity using the client settings. * @param namespaceName namespace of entity * @param entityPath path of entity * @param clientSettings client settings * @return IMessageSender instance * @throws InterruptedException if the current thread was interrupted while waiting * @throws ServiceBusException if the sender cannot be created */ public static IMessageSender createMessageSenderFromEntityPath(String namespaceName, String entityPath, ClientSettings clientSettings) throws InterruptedException, ServiceBusException { return Utils.completeFuture(createMessageSenderFromEntityPathAsync(namespaceName, entityPath, clientSettings)); }
@Override public void deadLetter(UUID lockToken, String deadLetterReason, String deadLetterErrorDescription, TransactionContext transaction) throws InterruptedException, ServiceBusException { this.checkInnerReceiveCreated(); this.innerReceiver.deadLetter(lockToken, deadLetterReason, deadLetterErrorDescription, transaction); }
@Override public void abandon(UUID lockToken, TransactionContext transaction) throws InterruptedException, ServiceBusException { this.checkInnerReceiveCreated(); this.innerReceiver.abandon(lockToken, transaction); }
@OnScheduled public void onScheduled(final ProcessContext context) throws ProcessException, URISyntaxException { final BlockingQueue<String> partitionNames = new LinkedBlockingQueue<>(); for (int i = 0; i < context.getProperty(NUM_PARTITIONS).asInteger(); i++) { partitionNames.add(String.valueOf(i)); } this.partitionNames = partitionNames; final String policyName = context.getProperty(ACCESS_POLICY).getValue(); final String policyKey = context.getProperty(POLICY_PRIMARY_KEY).getValue(); final String namespace = context.getProperty(NAMESPACE).getValue(); final String eventHubName = context.getProperty(EVENT_HUB_NAME).getValue(); final String serviceBusEndpoint = context.getProperty(SERVICE_BUS_ENDPOINT).getValue(); if(context.getProperty(ENQUEUE_TIME).isSet()) { configuredEnqueueTime = Instant.parse(context.getProperty(ENQUEUE_TIME).toString()); } else { configuredEnqueueTime = null; } if(context.getProperty(RECEIVER_FETCH_SIZE).isSet()) { receiverFetchSize = context.getProperty(RECEIVER_FETCH_SIZE).asInteger(); } else { receiverFetchSize = 100; } if(context.getProperty(RECEIVER_FETCH_TIMEOUT).isSet()) { receiverFetchTimeout = Duration.ofMillis(context.getProperty(RECEIVER_FETCH_TIMEOUT).asLong()); } else { receiverFetchTimeout = null; } final String connectionString = new ConnectionStringBuilder(new URI("amqps://"+namespace+serviceBusEndpoint), eventHubName, policyName, policyKey).toString(); setupReceiver(connectionString); }
@Override public CompletableFuture<Void> abandonAsync(UUID lockToken, Map<String, Object> propertiesToModify, TransactionContext transaction) { this.checkInnerReceiveCreated(); return this.innerReceiver.abandonAsync(lockToken, propertiesToModify, transaction); }
@Override public CompletableFuture<Void> deadLetterAsync(UUID lockToken, String deadLetterReason, String deadLetterErrorDescription, TransactionContext transaction) { this.checkInnerReceiveCreated(); return this.innerReceiver.deadLetterAsync(lockToken, deadLetterReason, deadLetterErrorDescription, transaction); }
@Override public CompletableFuture<Void> completeAsync(UUID lockToken, TransactionContext transaction) { this.checkInnerReceiveCreated(); return this.innerReceiver.completeAsync(lockToken, transaction); }
protected String getConnectionString(final String namespace, final String eventHubName, final String policyName, final String policyKey){ return new ConnectionStringBuilder(namespace, eventHubName, policyName, policyKey).toString(); } protected void sendMessage(final byte[] buffer) throws ProcessException {
/** * Creates a message receiver to the entity using the client settings in PeekLock mode * @param namespaceEndpointURI endpoint uri of entity namespace * @param entityPath path of the entity * @param clientSettings client settings * @return IMessageReceiver instance * @throws InterruptedException if the current thread was interrupted while waiting * @throws ServiceBusException if the receiver cannot be created */ public static IMessageReceiver createMessageReceiverFromEntityPath(URI namespaceEndpointURI, String entityPath, ClientSettings clientSettings) throws InterruptedException, ServiceBusException { return Utils.completeFuture(createMessageReceiverFromEntityPathAsync(namespaceEndpointURI, entityPath, clientSettings)); }
/** * Creates a message sender to the entity using the client settings. * @param namespaceEndpointURI endpoint uri of entity namespace * @param entityPath path of entity * @param clientSettings client settings * @return IMessageSender instance * @throws InterruptedException if the current thread was interrupted while waiting * @throws ServiceBusException if the sender cannot be created */ public static IMessageSender createMessageSenderFromEntityPath(URI namespaceEndpointURI, String entityPath, ClientSettings clientSettings) throws InterruptedException, ServiceBusException { return Utils.completeFuture(createMessageSenderFromEntityPathAsync(namespaceEndpointURI, entityPath, clientSettings)); }
@Override public void deadLetter(UUID lockToken, String deadLetterReason, String deadLetterErrorDescription, Map<String, Object> propertiesToModify, TransactionContext transaction) throws InterruptedException, ServiceBusException { this.checkInnerReceiveCreated(); this.innerReceiver.deadLetter(lockToken, deadLetterReason, deadLetterErrorDescription, propertiesToModify, transaction); }
@Override public void abandon(UUID lockToken, Map<String, Object> propertiesToModify, TransactionContext transaction) throws InterruptedException, ServiceBusException { this.checkInnerReceiveCreated(); this.innerReceiver.abandon(lockToken, propertiesToModify, transaction); }
@Override public EventDataWrap receive() { long start = System.currentTimeMillis(); Iterable<EventData> receivedEvents = null; /*Get one message at a time for backward compatibility behaviour*/ try { receivedEvents = receiver.receiveSync(1); } catch (ServiceBusException e) { logger.error("Exception occured during receive" + e.toString()); return null; } long end = System.currentTimeMillis(); long millis = (end - start); receiveApiLatencyMean.update(millis); receiveApiCallCount.incr(); if (receivedEvents == null || receivedEvents.spliterator().getExactSizeIfKnown() == 0) { return null; } receiveMessageCount.incr(); EventData receivedEvent = receivedEvents.iterator().next(); MessageId messageId = new MessageId(partitionId, receivedEvent.getSystemProperties().getOffset(), receivedEvent.getSystemProperties().getSequenceNumber()); return EventDataWrap.create(receivedEvent, messageId); }
public EventHubBoltConfig(String userName, String password, String namespace, String targetFqnAddress, String entityPath, boolean partitionMode, IEventDataFormat dataFormat) { this.connectionString = new ConnectionStringBuilder(namespace, entityPath, userName, password).toString(); this.entityPath = entityPath; this.partitionMode = partitionMode; this.dataFormat = dataFormat; if (this.dataFormat == null) { this.dataFormat = new DefaultEventDataFormat(); } }
/** * Creates a message receiver to the entity. * @param messagingFactory messaging factory (which represents a connection) on which receiver needs to be created * @param entityPath path of the entity * @param receiveMode PeekLock or ReceiveAndDelete * @return IMessageReceiver instance * @throws InterruptedException if the current thread was interrupted while waiting * @throws ServiceBusException if the receiver cannot be created */ public static IMessageReceiver createMessageReceiverFromEntityPath(MessagingFactory messagingFactory, String entityPath, ReceiveMode receiveMode) throws InterruptedException, ServiceBusException { return Utils.completeFuture(createMessageReceiverFromEntityPathAsync(messagingFactory, entityPath, receiveMode)); }
final ConnectionStringBuilder eventHubConnectionString = new ConnectionStringBuilder(namespaceName, eventHubName, sasName, sasKey); eventProcessorHost = new EventProcessorHost(consumerHostname, eventHubName, consumerGroupName, eventHubConnectionString.toString(), storageConnectionString, containerName);