@RabbitListener(bindings = @QueueBinding( exchange = @Exchange(value = "log4j2Sample", type = ExchangeTypes.FANOUT), value = @org.springframework.amqp.rabbit.annotation.Queue)) public void echoLogs(String logMessage) { System.out.println("Logs over Log4J AmqpAppender: " + logMessage); }
private void registerBindings(QueueBinding binding, String queueName, String exchangeName, String exchangeType) { final String[] routingKeys; if (exchangeType.equals(ExchangeTypes.FANOUT) || binding.key().length == 0) { routingKeys = new String[] { "" }; } else { final int length = binding.key().length; routingKeys = new String[length]; for (int i = 0; i < length; ++i) { routingKeys[i] = resolveExpressionAsString(binding.key()[i], "@QueueBinding.key"); } } final Map<String, Object> bindingArguments = resolveArguments(binding.arguments()); final boolean bindingIgnoreExceptions = resolveExpressionAsBoolean(binding.ignoreDeclarationExceptions()); boolean declare = resolveExpressionAsBoolean(binding.declare()); for (String routingKey : routingKeys) { final Binding actualBinding = new Binding(queueName, DestinationType.QUEUE, exchangeName, routingKey, bindingArguments); actualBinding.setIgnoreDeclarationExceptions(bindingIgnoreExceptions); actualBinding.setShouldDeclare(declare); if (binding.admins().length > 0) { actualBinding.setAdminsThatShouldDeclare((Object[]) binding.admins()); } ((ConfigurableBeanFactory) this.beanFactory) .registerSingleton(exchangeName + "." + queueName + ++this.increment, actualBinding); } }
private void declareExchangeAndBinding(QueueBinding binding, String queueName) { org.springframework.amqp.rabbit.annotation.Exchange bindingExchange = binding.exchange(); String exchangeName = resolveExpressionAsString(bindingExchange.value(), "@Exchange.exchange"); Assert.isTrue(StringUtils.hasText(exchangeName), () -> "Exchange name required; binding queue " + queueName);
private void declareExchangeAndBinding(QueueBinding binding, String queueName) { org.springframework.amqp.rabbit.annotation.Exchange bindingExchange = binding.exchange(); String exchangeName = resolveExpressionAsString(bindingExchange.value(), "@Exchange.exchange"); Assert.isTrue(StringUtils.hasText(exchangeName), () -> "Exchange name required; binding queue " + queueName);
/** * Dummy method to handle the shipGoods command message - as we do not have a * shipping system available in this small example */ @RabbitListener(bindings = @QueueBinding( // value = @Queue(value = "shipping_create_test", durable = "true"), // exchange = @Exchange(value = "shipping", type = "topic", durable = "true"), // key = "*")) @Transactional public void dummyShipGoodsCommand(String orderId) { // and call back directly with a generated transactionId handleGoodsShippedEvent(orderId, UUID.randomUUID().toString()); }
private void registerBindings(QueueBinding binding, String queueName, String exchangeName, String exchangeType) { final String[] routingKeys; if (exchangeType.equals(ExchangeTypes.FANOUT) || binding.key().length == 0) { routingKeys = new String[] { "" }; } else { final int length = binding.key().length; routingKeys = new String[length]; for (int i = 0; i < length; ++i) { routingKeys[i] = resolveExpressionAsString(binding.key()[i], "@QueueBinding.key"); } } final Map<String, Object> bindingArguments = resolveArguments(binding.arguments()); final boolean bindingIgnoreExceptions = resolveExpressionAsBoolean(binding.ignoreDeclarationExceptions()); boolean declare = resolveExpressionAsBoolean(binding.declare()); for (String routingKey : routingKeys) { final Binding actualBinding = new Binding(queueName, DestinationType.QUEUE, exchangeName, routingKey, bindingArguments); actualBinding.setIgnoreDeclarationExceptions(bindingIgnoreExceptions); actualBinding.setShouldDeclare(declare); if (binding.admins().length > 0) { actualBinding.setAdminsThatShouldDeclare((Object[]) binding.admins()); } ((ConfigurableBeanFactory) this.beanFactory) .registerSingleton(exchangeName + "." + queueName + ++this.increment, actualBinding); } }
@RabbitListener( bindings = @QueueBinding(value = @Queue, exchange = @Exchange( value = ICONATOR_ENTRY_EXCHANGE,
@Override @RabbitListener( bindings = @QueueBinding( value = @Queue( value = RabbitConfiguration.QUEUE_NAME_VNFM_CORE_ACTIONS_REPLY, durable = RabbitConfiguration.QUEUE_DURABLE, autoDelete = RabbitConfiguration.QUEUE_AUTODELETE), exchange = @Exchange( value = RabbitConfiguration.EXCHANGE_NAME_OPENBATON, ignoreDeclarationExceptions = "true", type = RabbitConfiguration.EXCHANGE_TYPE_OPENBATON, durable = RabbitConfiguration.EXCHANGE_DURABLE_OPENBATON), key = RabbitConfiguration.QUEUE_NAME_VNFM_CORE_ACTIONS_REPLY)) public String actionFinished(String nfvMessage) throws ExecutionException, InterruptedException { NFVMessage message = gson.fromJson(nfvMessage, NFVMessage.class); log.debug("NFVO - core module received (via MB): " + message.getAction()); log.debug("Received ACTION: " + message.getAction()); Future<NFVMessage> res = stateHandler.executeAction(message); String result = gson.toJson(res.get()); log.debug("Concluded ACTION: " + message.getAction()); return result; }
@RabbitListener( bindings = @QueueBinding(value = @Queue, exchange = @Exchange( value = ICONATOR_ENTRY_EXCHANGE, type = ExchangeTypes.TOPIC, ignoreDeclarationExceptions = "true", durable = "true" ), key = BLOCK_NR_ETHEREUM_ROUTING_KEY) ) public void receiveMessage(BlockNREthereumMessage message) { try { Optional<BlockNREthereumMessage> optionalBlockNREthereumMessage = ofNullable(message); optionalBlockNREthereumMessage.ifPresent((ethereumMessage) -> { blockNr = ethereumMessage.getBlockNr(); timestamp = ethereumMessage.getTimestamp(); }); } catch (Exception e) { LOG.error("Error adding addresses to be monited by 'iconator-monitor'.", e); } }
@RabbitListener( bindings = @QueueBinding(value = @Queue, exchange = @Exchange( value = ICONATOR_ENTRY_EXCHANGE, type = ExchangeTypes.TOPIC, ignoreDeclarationExceptions = "true", durable = "true" ), key = BLOCK_NR_BITCOIN_ROUTING_KEY) ) public void receiveMessage(BlockNRBitcoinMessage message) { try { Optional<BlockNRBitcoinMessage> optionalBlockNRBitcoinMessage = ofNullable(message); optionalBlockNRBitcoinMessage.ifPresent((bitcoinMessage) -> { blockNr = bitcoinMessage.getBlockNr(); timestamp = bitcoinMessage.getTimestamp(); }); } catch (Exception e) { LOG.error("Error adding addresses to be monited by 'iconator-monitor'.", e); } }
@RabbitListener(bindings = { @QueueBinding( value = @Queue, exchange = @Exchange(value = RabbitMQConfiguration.EXCHANGE_NAME, type = ExchangeTypes.TOPIC), key = "upper" ) }) public void onMessage(Message message) { String text = new String(message.getBody()); System.out.println("ToUpperCase.onMessage - " + text); String result = text.toUpperCase(); template.convertAndSend(message.getMessageProperties().getReplyTo(), result); } }
@RabbitListener(bindings = @QueueBinding( value = @Queue(value = QUEUE, durable = "false"), exchange = @Exchange(value = EXCHANGE, type = ExchangeTypes.TOPIC))) public void receiveMessage(String message) { linkRepository.incrementClickCountByOne(message); } }
@Override @RabbitListener( bindings = @QueueBinding( value = @Queue( value = RabbitConfiguration.QUEUE_NAME_VNFM_CORE_ACTIONS, durable = RabbitConfiguration.QUEUE_DURABLE, autoDelete = RabbitConfiguration.QUEUE_AUTODELETE), exchange = @Exchange( value = RabbitConfiguration.EXCHANGE_NAME_OPENBATON, ignoreDeclarationExceptions = "true", type = RabbitConfiguration.EXCHANGE_TYPE_OPENBATON, durable = RabbitConfiguration.EXCHANGE_DURABLE_OPENBATON), key = RabbitConfiguration.QUEUE_NAME_VNFM_CORE_ACTIONS)) public void actionFinishedVoid(String nfvMessage) throws ExecutionException, InterruptedException { NFVMessage message = gson.fromJson(nfvMessage, NFVMessage.class); log.debug("NFVO - core module received (via MB)" + message.getAction()); log.debug("----------Executing ACTION: " + message.getAction()); stateHandler.executeAction(message).get(); log.debug("-----------Finished ACTION: " + message.getAction()); } }
@RabbitListener( bindings = @QueueBinding(value = @Queue(durable = "true"), exchange = @Exchange( value = ICONATOR_ENTRY_EXCHANGE, type = ExchangeTypes.TOPIC, ignoreDeclarationExceptions = "true", durable = "true" ), key = ADDRESS_SET_WALLET_ROUTING_KEY) ) public void receiveMessage(SetWalletAddressMessage messageObject) { try { Optional<SetWalletAddressMessage> optionalSetWalletAddressMessage = ofNullable(messageObject); optionalSetWalletAddressMessage.ifPresent((m) -> { ofNullable(m.getInvestor()).ifPresent((investor) -> { long timestamp = investor.getCreationDate().getTime(); bitcoinMonitor.addPaymentAddressesForMonitoring(investor.getPayInBitcoinAddress(), timestamp); ethereumMonitor.addPaymentAddressesForMonitoring(investor.getPayInEtherAddress(), timestamp); }); }); } catch (Exception e) { LOG.error("Error adding addresses to be monited by 'iconator-monitor'.", e); } }
@RabbitListener( bindings = @QueueBinding( value = @Queue(
@RabbitListener(bindings = { @QueueBinding( value = @Queue, exchange = @Exchange(value = RabbitMQConfiguration.EXCHANGE_NAME, type = ExchangeTypes.TOPIC), key = "prepend" ) }) public void onMessage(StringMessage msg, Message message) { String text = msg.getBody(); System.out.println("PrependHello.onMessage - " + text); String result = "hello, " + text; template.convertAndSend(message.getMessageProperties().getReplyTo(), new StringMessage(result)); } }
@RabbitListener( bindings = @QueueBinding(value = @Queue(value = KYC_REMINDER_EMAIL_SENT_QUEUE, autoDelete = "false"), exchange = @Exchange( value = ICONATOR_ENTRY_EXCHANGE, type = ExchangeTypes.TOPIC, ignoreDeclarationExceptions = "true", durable = "true" ), key = KYC_REMINDER_EMAIL_SENT_ROUTING_KEY) ) public void receiveMessage(KycReminderEmailSentMessage message) { try { long investorId = investorService.getInvestorByEmail(message.getEmailAddress()).getId(); kycInfoService.increaseNumberOfRemindersSent(investorId); LOG.debug("Increased numberOfRemindersSent for investor with ID {} by 1", investorId); } catch (InvestorNotFoundException e) { LOG.error("Investor with address {} not found", message.getEmailAddress()); } }
@RabbitListener( bindings = @QueueBinding(value = @Queue(value = KYC_START_EMAIL_SENT_QUEUE, autoDelete = "false"), exchange = @Exchange( value = ICONATOR_ENTRY_EXCHANGE, type = ExchangeTypes.TOPIC, ignoreDeclarationExceptions = "true", durable = "true" ), key = KYC_START_EMAIL_SENT_ROUTING_KEY) ) public void receiveMessage(KycStartEmailSentMessage message) { try { long investorId = investorService.getInvestorByEmail(message.getEmailAddress()).getId(); kycInfoService.setKycStartEmailSent(investorId); LOG.debug("Set kycStartEmailSent for investor with ID {} to true", investorId); } catch (InvestorNotFoundException e) { LOG.error("Investor with address {} not found", message.getEmailAddress()); } }
@RabbitListener( bindings = @QueueBinding(value = @Queue(value = REGISTER_SUMMARY_EMAIL_QUEUE, autoDelete = "false"), exchange = @Exchange( value = ICONATOR_ENTRY_EXCHANGE, type = ExchangeTypes.TOPIC, ignoreDeclarationExceptions = "true", durable = "true" ), key = REGISTER_SUMMARY_EMAIL_ROUTING_KEY) ) public void receiveMessage(SummaryEmailMessage messageObject) { try { // TODO: 05.03.18 Guil: // Add a retry mechanism (e.g., for when the SMTP server is offline) mailService.sendSummaryEmail(messageObject.getInvestor().toInvestor()); } catch (Exception e) { // TODO: 05.03.18 Guil: // Instead of just output the error, send to a structured log, // e.g., logstash or, also, send an email to an admin LOG.error("Email not sent.", e); } }
@Override @RabbitListener( bindings = @QueueBinding( value = @Queue( value = RabbitConfiguration.QUEUE_NAME_EVENT_UNREGISTER, durable = RabbitConfiguration.QUEUE_DURABLE, autoDelete = RabbitConfiguration.QUEUE_AUTODELETE), exchange = @Exchange( value = RabbitConfiguration.EXCHANGE_NAME_OPENBATON, ignoreDeclarationExceptions = "true", type = RabbitConfiguration.EXCHANGE_TYPE_OPENBATON, durable = RabbitConfiguration.EXCHANGE_DURABLE_OPENBATON), key = RabbitConfiguration.QUEUE_NAME_EVENT_UNREGISTER)) public void unregister(String id) throws NotFoundException { eventManagement.removeUnreachableEndpoints(); EventEndpoint endpoint = eventEndpointRepository.findFirstById(id); if (endpoint == null) throw new NotFoundException("No event found with ID " + id); log.info("Removing EventEndpoint with id: " + id); eventEndpointRepository.delete(id); } }