private void receiveQueueMessage() throws ServiceBusException, InterruptedException { queueClient.registerMessageHandler(new MessageHandler(), new MessageHandlerOptions()); TimeUnit.SECONDS.sleep(5); queueClient.close(); }
@Override public void sendMessage(IMessage message) throws ResourceException { try { sbConnector.send(message); } catch (InterruptedException | ServiceBusException ex) { throw new ResourceException(ex); } }
@Override public void cancelScheduledMessage(long sequenceNumber) throws InterruptedException, ServiceBusException { Utils.completeFuture(this.cancelScheduledMessageAsync(sequenceNumber)); }
@Bean @Scope("prototype") @ConditionalOnMissingBean @ConditionalOnProperty(prefix = "azure.servicebus", value = {"queue-name", "queue-receive-mode"}) public QueueClient queueClient() throws InterruptedException, ServiceBusException { return new QueueClient(new ConnectionStringBuilder(properties.getConnectionString(), properties.getQueueName()), properties.getQueueReceiveMode()); }
public AzureSBListener(AzureSBActivationSpec asbSpec, BootstrapContext context, MessageEndpointFactory endpointFactory) throws ResourceException { activationSpec = asbSpec; this.context = context; this.endpointFactory = endpointFactory; SharedAccessSignatureTokenProvider tokenProvider = new SharedAccessSignatureTokenProvider(asbSpec.getSasKeyName(), asbSpec.getSasKey(),60); ClientSettings settings = new ClientSettings(tokenProvider, RetryPolicy.getDefault(), Duration.ofSeconds(asbSpec.getPollTimeout())); try { client = new QueueClient(asbSpec.getNameSpace(), asbSpec.getQueueName(), settings, ReceiveMode.RECEIVEANDDELETE); client.setPrefetchCount(activationSpec.getPreFetchCount()); } catch (InterruptedException | ServiceBusException ex) { Logger.getLogger(AzureSBListener.class.getName()).log(Level.SEVERE, "Error creating listener for queue " + activationSpec.getQueueName(), ex); throw new ResourceException(ex); } }
public static void consumeMessages() throws Exception { assumeHasAzureSBEnv(); final String connectionString = azureSBConnectionStringFromEnv(); final QueueClient queueClient = new QueueClient(new ConnectionStringBuilder(connectionString), ReceiveMode.PeekLock); receiveMessages(queueClient); Thread.sleep(getAzureTimeoutFromEnvInMillis()); queueClient.close(); }
public void subscribe() throws ResourceException { try { client.registerMessageHandler(this); } catch (InterruptedException | ServiceBusException ex) { Logger.getLogger(AzureSBListener.class.getName()).log(Level.SEVERE, "Error subscribing to queue " + activationSpec.getQueueName(), ex); throw new ResourceException(ex); } }
public void close() { client.closeAsync(); }
@Bean @ConditionalOnMissingBean @ConditionalOnProperty(prefix = "azure.servicebus", value = {"queue-name", "queue-receive-mode"}) public QueueClient queueClient() throws InterruptedException, ServiceBusException { return new QueueClient(new ConnectionStringBuilder(properties.getConnectionString(), properties.getQueueName()), properties.getQueueReceiveMode()); }
public AzureSBListener(AzureSBActivationSpec asbSpec, BootstrapContext context, MessageEndpointFactory endpointFactory) throws ResourceException { activationSpec = asbSpec; this.context = context; this.endpointFactory = endpointFactory; SharedAccessSignatureTokenProvider tokenProvider = new SharedAccessSignatureTokenProvider(asbSpec.getSasKeyName(), asbSpec.getSasKey(),60); ClientSettings settings = new ClientSettings(tokenProvider, RetryPolicy.getDefault(), Duration.ofSeconds(asbSpec.getPollTimeout())); try { client = new QueueClient(asbSpec.getNameSpace(), asbSpec.getQueueName(), settings, ReceiveMode.RECEIVEANDDELETE); client.setPrefetchCount(activationSpec.getPreFetchCount()); } catch (InterruptedException | ServiceBusException ex) { Logger.getLogger(AzureSBListener.class.getName()).log(Level.SEVERE, "Error creating listener for queue " + activationSpec.getQueueName(), ex); throw new ResourceException(ex); } }
public void subscribe() throws ResourceException { try { client.registerMessageHandler(this); } catch (InterruptedException | ServiceBusException ex) { Logger.getLogger(AzureSBListener.class.getName()).log(Level.SEVERE, "Error subscribing to queue " + activationSpec.getQueueName(), ex); throw new ResourceException(ex); } }
public void close() { client.closeAsync(); }
@Bean @ConditionalOnMissingBean @ConditionalOnProperty(prefix = "azure.servicebus", value = {"queue-name", "queue-receive-mode"}) public QueueClient queueClient() throws InterruptedException, ServiceBusException { trackCustomEvent(); return new QueueClient(new ConnectionStringBuilder(properties.getConnectionString(), properties.getQueueName()), properties.getQueueReceiveMode()); }
@PostConstruct private void postConstruct() { LOG.debug("postConstruct start..."); try { LOG.debug("registering queue handler..."); queueClientForReceiving.registerMessageHandler(new MessageHandler(), new MessageHandlerOptions()); LOG.debug("done registering handlers..."); } catch (InterruptedException e) { LOG.error("Error registering message handler", e); } catch (ServiceBusException e) { LOG.error("Error registering message handler", e); } LOG.debug("postConstruct end."); }
private void sendQueueMessage() throws ServiceBusException, InterruptedException { final String messageBody = "queue message"; LOG.debug("Sending message: " + messageBody); final Message message = new Message( messageBody.getBytes(StandardCharsets.UTF_8)); queueClientForSending.send(message); }
@Bean @ConditionalOnMissingBean @ConditionalOnProperty(prefix = "azure.servicebus", value = {"queue-name", "queue-receive-mode"}) public QueueClient queueClient() throws InterruptedException, ServiceBusException { trackCustomEvent(); return new QueueClient(new ConnectionStringBuilder(properties.getConnectionString(), properties.getQueueName()), properties.getQueueReceiveMode()); }
private static void receiveMessages(QueueClient queueClient) throws InterruptedException, ServiceBusException { queueClient.registerMessageHandler(new IMessageHandler() { public CompletableFuture<Void> onMessageAsync(IMessage message) { return CompletableFuture.completedFuture(null); } public void notifyException(Throwable exception, ExceptionPhase phase) {} }, new MessageHandlerOptions(10000, true, Duration.ofMinutes(2))); } }
@Override public void sendMessage(IMessage message) throws ResourceException { try { sbConnector.send(message); } catch (InterruptedException | ServiceBusException ex) { throw new ResourceException(ex); } }
AzureSBManagedConnection(AzureSBManagedConnectionFactory aThis, Subject subject, ConnectionRequestInfo cxRequestInfo) { cf = aThis; listeners = new HashSet<>(); SharedAccessSignatureTokenProvider tokenProvider = new SharedAccessSignatureTokenProvider(cf.getSasKeyName(), cf.getSasKey(), 60); try { sbConnector = new QueueClient(cf.getNameSpace(),cf.getQueueName(),new ClientSettings(tokenProvider, RetryPolicy.getDefault(), Duration.ofSeconds(cf.getTimeOut())),ReceiveMode.RECEIVEANDDELETE); } catch (InterruptedException | ServiceBusException ex) { Logger.getLogger(AzureSBManagedConnection.class.getName()).log(Level.SEVERE, null, ex); } }
private void sendQueueMessage() throws ServiceBusException, InterruptedException { final String messageBody = "queue message"; System.out.println("Sending message: " + messageBody); final Message message = new Message(messageBody.getBytes(StandardCharsets.UTF_8)); queueClient.send(message); }