org.springframework.amqp.rabbit.annotation.Exchange Java Examples
The following examples show how to use
org.springframework.amqp.rabbit.annotation.Exchange.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RabbitReceiver.java From code with Apache License 2.0 | 7 votes |
/** * * spring.rabbitmq.listener.order.queue.name=queue-2 spring.rabbitmq.listener.order.queue.durable=true spring.rabbitmq.listener.order.exchange.name=exchange-1 spring.rabbitmq.listener.order.exchange.durable=true spring.rabbitmq.listener.order.exchange.type=topic spring.rabbitmq.listener.order.exchange.ignoreDeclarationExceptions=true spring.rabbitmq.listener.order.key=springboot.* * @param order * @param channel * @param headers * @throws Exception */ @RabbitListener(bindings = @QueueBinding( value = @Queue(value = "${spring.rabbitmq.listener.order.queue.name}", durable="${spring.rabbitmq.listener.order.queue.durable}"), exchange = @Exchange(value = "${spring.rabbitmq.listener.order.exchange.name}", durable="${spring.rabbitmq.listener.order.exchange.durable}", type= "${spring.rabbitmq.listener.order.exchange.type}", ignoreDeclarationExceptions = "${spring.rabbitmq.listener.order.exchange.ignoreDeclarationExceptions}"), key = "${spring.rabbitmq.listener.order.key}" ) ) @RabbitHandler public void onOrderMessage(@Payload com.bfxy.springboot.entity.Order order, Channel channel, @Headers Map<String, Object> headers) throws Exception { System.err.println("--------------------------------------"); System.err.println("消费端order: " + order.getId()); Long deliveryTag = (Long)headers.get(AmqpHeaders.DELIVERY_TAG); //手工ACK channel.basicAck(deliveryTag, false); }
Example #2
Source File: GoodsListener.java From leyou with Apache License 2.0 | 6 votes |
/** * 处理delete的消息 * * @param id */ @RabbitListener(bindings = @QueueBinding( value = @Queue(value = "leyou.delete.index.queue", durable = "true"), exchange = @Exchange( value = "leyou.item.exchange", ignoreDeclarationExceptions = "true", type = ExchangeTypes.TOPIC), key = "item.delete") ) public void listenDelete(Long id) { if (id == null) { return; } // 删除索引 this.searchService.deleteIndex(id); }
Example #3
Source File: GoodsListener.java From leyou with Apache License 2.0 | 6 votes |
/** * 处理insert和update的消息 * * @param id * @throws Exception */ @RabbitListener(bindings = @QueueBinding( value = @Queue(value = "leyou.create.index.queue", durable = "true"), exchange = @Exchange( value = "leyou.item.exchange", ignoreDeclarationExceptions = "true", type = ExchangeTypes.TOPIC), key = {"item.insert", "item.update"}) ) public void listenCreate(Long id) throws Exception { if (id == null) { return; } // 创建或更新索引 this.searchService.createIndex(id); }
Example #4
Source File: SmsListener.java From leyou with Apache License 2.0 | 6 votes |
@RabbitListener(bindings = @QueueBinding( value = @Queue(value = "leyou.sms.queue", durable = "true"), exchange = @Exchange(value = "leyou.sms.exchange", ignoreDeclarationExceptions = "true"), key = {"sms.verify.code"})) public void listenSms(Map<String, String> msg) throws Exception { if (msg == null || msg.size() <= 0) { // 放弃处理 return; } String phone = msg.get("phone"); String code = msg.get("code"); if (StringUtils.isBlank(phone) || StringUtils.isBlank(code)) { // 放弃处理 return; } // 发送消息 SendSmsResponse resp = this.smsUtils.sendSms(phone, code, prop.getSignName(), prop.getVerifyCodeTemplate()); }
Example #5
Source File: RabbitReceiver.java From code with Apache License 2.0 | 6 votes |
@RabbitListener(bindings = @QueueBinding( value = @Queue(value = "queue-1", durable="true"), exchange = @Exchange(value = "exchange-1", durable="true", type= "topic", ignoreDeclarationExceptions = "true"), key = "springboot.*" ) ) @RabbitHandler public void onMessage(Message message, Channel channel) throws Exception { System.err.println("--------------------------------------"); System.err.println("消费端Payload: " + message.getPayload()); Long deliveryTag = (Long)message.getHeaders().get(AmqpHeaders.DELIVERY_TAG); //手工ACK channel.basicAck(deliveryTag, false); }
Example #6
Source File: EventDispatcher.java From NFVO with Apache License 2.0 | 6 votes |
@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); }
Example #7
Source File: RabbitVnfmReceiver.java From NFVO with Apache License 2.0 | 6 votes |
@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()); }
Example #8
Source File: ToUpperCase.java From cukes with Apache License 2.0 | 5 votes |
@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); }
Example #9
Source File: PrependHello.java From cukes with Apache License 2.0 | 5 votes |
@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)); }
Example #10
Source File: EventDispatcher.java From NFVO with Apache License 2.0 | 5 votes |
@Override @RabbitListener( bindings = @QueueBinding( value = @Queue( value = RabbitConfiguration.QUEUE_NAME_EVENT_REGISTER, 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_REGISTER)) public EventEndpoint register(String endpoint_json) throws MissingParameterException { EventEndpoint endpoint = gson.fromJson(endpoint_json, EventEndpoint.class); if (endpoint.getProjectId() == null) { throw new MissingParameterException("The Event Endpoint needs a project id"); } if (!endpointAlreadyExists(endpoint)) return saveEventEndpoint(endpoint); return getEndpointAlreadyRegistered(endpoint); }
Example #11
Source File: RabbitVnfmReceiver.java From NFVO with Apache License 2.0 | 5 votes |
@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; }
Example #12
Source File: RabbitManager.java From spring-cloud-contract with Apache License 2.0 | 5 votes |
@RabbitListener( bindings = @QueueBinding( value = @Queue, exchange = @Exchange(value = "input", durable = "true", autoDelete = "false", type = "topic"), key = "event2")) public void newBook2(Book book, @Headers Map<String, String> headers) { LOG.info("newBook2 Received new book with bookname = " + book.getName()); LOG.info("newBook2 Headers = " + headers); this.service.sendBook(book, headers.get("amqp_replyTo")); }
Example #13
Source File: RabbitManager.java From spring-cloud-contract with Apache License 2.0 | 5 votes |
@RabbitListener( bindings = @QueueBinding( value = @Queue, exchange = @Exchange(value = "input", durable = "true", autoDelete = "false", type = "topic"), key = "event")) public void newBook(Book book, @Headers Map<String, String> headers) { LOG.info("Received new book with bookname = " + book.getName()); LOG.info("Headers = " + headers); this.service.sendBook(book, headers.get("amqp_replyTo")); }
Example #14
Source File: AmqpReceiver.java From camunda-spring-boot-amqp-microservice-cloud-example with Apache License 2.0 | 5 votes |
/** * 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()); }
Example #15
Source File: CommentService.java From Learning-Spring-Boot-2.0-Second-Edition with MIT License | 5 votes |
@RabbitListener(bindings = @QueueBinding( value = @Queue, exchange = @Exchange(value = "learning-spring-boot"), key = "comments.new" )) public void save(Comment newComment) { repository .save(newComment) .log("commentService-save") .subscribe(); }
Example #16
Source File: CommentService.java From Learning-Spring-Boot-2.0-Second-Edition with MIT License | 5 votes |
@RabbitListener(bindings = @QueueBinding( value = @Queue, exchange = @Exchange(value = "learning-spring-boot"), key = "comments.new" )) public void save(Comment newComment) { repository .save(newComment) .log("commentService-save") .subscribe(comment -> { meterRegistry .counter("comments.consumed", "imageId", comment.getImageId()) .increment(); }); }
Example #17
Source File: BaseRabbitIntegrationTest.java From eventeum with Apache License 2.0 | 5 votes |
@RabbitListener(bindings = @QueueBinding( key = "thisIsRoutingKey.*", value = @Queue("ThisIsAEventsQueue"), exchange = @Exchange(value = "ThisIsAExchange", type = ExchangeTypes.TOPIC) )) public void onEvent(EventeumMessage message) { if(message.getDetails() instanceof ContractEventDetails){ getBroadcastContractEvents().add((ContractEventDetails) message.getDetails()); } else if(message.getDetails() instanceof BlockDetails){ getBroadcastBlockMessages().add((BlockDetails) message.getDetails()); } }
Example #18
Source File: RabbitBroadcasterDBEventStoreIT.java From eventeum with Apache License 2.0 | 5 votes |
@RabbitListener(bindings = @QueueBinding( key = "blockEvents", value = @Queue("blockEvents"), exchange = @Exchange(value = "ThisIsAExchange", type = ExchangeTypes.TOPIC) )) public void onBlockEvent(EventeumMessage message) { onBlockMessageReceived((BlockDetails) message.getDetails()); }
Example #19
Source File: RabbitBroadcasterDBEventStoreIT.java From eventeum with Apache License 2.0 | 5 votes |
@RabbitListener(bindings = @QueueBinding( key = "transactionEvents.*", value = @Queue("transactionEvents"), exchange = @Exchange(value = "ThisIsAExchange", type = ExchangeTypes.TOPIC) )) public void onTransactionEvent(EventeumMessage message) { onTransactionMessageReceived((TransactionDetails) message.getDetails()); }
Example #20
Source File: RabbitBroadcasterDBEventStoreIT.java From eventeum with Apache License 2.0 | 5 votes |
@RabbitListener(bindings = @QueueBinding( key = "contractEvents.*", value = @Queue("contractEvents"), exchange = @Exchange(value = "ThisIsAExchange", type = ExchangeTypes.TOPIC) )) public void onContractEvent(EventeumMessage message) { if(message.getDetails() instanceof ContractEventDetails){ onContractEventMessageReceived((ContractEventDetails) message.getDetails()); } else if(message.getDetails() instanceof TransactionDetails){ onTransactionMessageReceived((TransactionDetails) message.getDetails()); } }
Example #21
Source File: AmqpReceiver.java From code with Apache License 2.0 | 5 votes |
/** * 水果供应商服务 接收消息 * @param message */ @RabbitListener(bindings = @QueueBinding( exchange = @Exchange("myOrder"), key = "fruit", value = @Queue("fruitOrder") )) public void processFruit(String message) { log.info("fruit MqReceiver: {}", message); }
Example #22
Source File: AmqpReceiver.java From code with Apache License 2.0 | 5 votes |
/** * 数码供应商服务 接收消息 * @param message */ @RabbitListener(bindings = @QueueBinding( exchange = @Exchange("myOrder"), key = "computer", value = @Queue("computerOrder") )) public void processComputer(String message) { log.info("computer MqReceiver: {}", message); }
Example #23
Source File: AmqpReceiver.java From code with Apache License 2.0 | 5 votes |
/** * 1.手动创建队列 @RabbitListener(queues = "myQueue") * 2.自动创建队列 @RabbitListener(queuesToDeclare = @Queue("myQueue")) * 3.自动创建Exchange与Queue绑定 */ @RabbitListener(bindings = @QueueBinding( value = @Queue("myQueue"), exchange = @Exchange("myExchange") )) public void process(String message) { log.info("MqReceiver={}", message); }
Example #24
Source File: GoodsListener.java From leyou with Apache License 2.0 | 5 votes |
/** * 处理delete的消息 * * @param id */ @RabbitListener(bindings = @QueueBinding( value = @Queue(value = "leyou.delete.web.queue", durable = "true"), exchange = @Exchange( value = "leyou.item.exchange", ignoreDeclarationExceptions = "true", type = ExchangeTypes.TOPIC), key = "item.delete")) public void listenDelete(Long id) { if (id == null) { return; } // 删除页面 goodsHtmlService.deleteHtml(id); }
Example #25
Source File: GoodsListener.java From leyou with Apache License 2.0 | 5 votes |
/** * 处理insert和update的消息 * * @param id * @throws Exception */ @RabbitListener(bindings = @QueueBinding( value = @Queue(value = "leyou.create.web.queue", durable = "true"), exchange = @Exchange( value = "leyou.item.exchange", ignoreDeclarationExceptions = "true", type = ExchangeTypes.TOPIC), key = {"item.insert", "item.update"})) public void listenCreate(Long id) throws Exception { if (id == null) { return; } // 创建页面 goodsHtmlService.createHtml(id); }
Example #26
Source File: MessageSubscriberRabbitListener.java From spring-cloud-contract with Apache License 2.0 | 4 votes |
@RabbitListener(bindings = @QueueBinding(value = @Queue("test.queue"), exchange = @Exchange(value = "contract-test.exchange", ignoreDeclarationExceptions = "true"))) public void handlePerson(Person person) { this.person = person; }