org.springframework.amqp.rabbit.annotation.RabbitHandler Java Examples
The following examples show how to use
org.springframework.amqp.rabbit.annotation.RabbitHandler
.
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 |
Example #2
@RabbitHandler public void handle(String msg){ LOGGER.info("receive order message msg:{}",msg); String[] temp = msg.split("&"); if(temp.length != 2){ LOGGER.warn("处方单超时处理失败: msg:{}",msg); return; Long id = new Long(temp[0]); int type = Integer.parseInt(temp[1]); int handleCount = 0; if(type == 4){ handleCount = dmsFeeRabbitMQService.herbalOutOfTime(id); }else if(type == 5){ handleCount = dmsFeeRabbitMQService.medicineOutOfTime(id); }else{ handleCount = dmsFeeRabbitMQService.nonDrugOutOfTime(id); System.out.println("处理结果:" + handleCount);
Example #3
@RabbitHandler public void handle(String msg){ LOGGER.info("receive order message msg:{}",msg); String[] temp = msg.split("&"); if(temp.length != 2){ LOGGER.warn("处方单超时处理失败: msg:{}",msg); return; Long id = new Long(temp[0]); int type = Integer.parseInt(temp[1]); int handleCount = 0; if(type == 4){ handleCount = dmsFeeRabbitMQService.herbalOutOfTime(id); }else if(type == 5){ handleCount = dmsFeeRabbitMQService.medicineOutOfTime(id); }else{ handleCount = dmsFeeRabbitMQService.nonDrugOutOfTime(id); System.out.println("处理结果:" + handleCount);
Example #4
@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 #5
@RabbitHandler public void handle(String msg){ LOGGER.info("receive order message msg:{}",msg); String[] temp = msg.split("&"); if(temp.length != 2){ LOGGER.warn("处方单超时处理失败: msg:{}",msg); return; Long id = new Long(temp[0]); int type = Integer.parseInt(temp[1]); int handleCount = 0; if(type == 4){ handleCount = dmsFeeRabbitMQService.herbalOutOfTime(id); }else if(type == 5){ handleCount = dmsFeeRabbitMQService.medicineOutOfTime(id); }else{ handleCount = dmsFeeRabbitMQService.nonDrugOutOfTime(id); System.out.println("处理结果:" + handleCount);
Example #6
@RabbitHandler public void handle(String msg){ LOGGER.info("receive order message msg:{}",msg); String[] temp = msg.split("&"); if(temp.length != 2){ LOGGER.warn("处方单超时处理失败: msg:{}",msg); return; Long id = new Long(temp[0]); int type = Integer.parseInt(temp[1]); int handleCount = 0; if(type == 4){ handleCount = dmsFeeRabbitMQService.herbalOutOfTime(id); }else if(type == 5){ handleCount = dmsFeeRabbitMQService.medicineOutOfTime(id); }else{ handleCount = dmsFeeRabbitMQService.nonDrugOutOfTime(id); System.out.println("处理结果:" + handleCount);
Example #7
@RabbitHandler public void process(String sendMsg, Channel channel, Message message) { System.out.println("AckReceiver : 收到发送消息 " + sendMsg + ",收到消息时间" + LocalDateTime.now(ZoneId.systemDefault())); try { //告诉服务器收到这条消息已经被当前消费者消费了,可以在队列安全删除,这样后面就不会再重发了, //否则消息服务器以为这条消息没处理掉,后续还会再发 //第二个参数是消息的标识,false只确认当前一个消息收到,true确认所有consumer获得的消息 channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); System.out.println("process success"); } catch (Exception e) { System.out.println("process fail"); try { //ack返回false,并重新回到队列 channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, true); } catch (IOException e1) { e1.printStackTrace(); e.printStackTrace();
Example #8
@RabbitHandler public void process(String sendMsg, Channel channel, Message message) { System.out.println("AckReceiver : 收到发送消息 " + sendMsg.toString() + ",收到消息时间" + LocalDateTime.now(ZoneId.systemDefault())); MessageObj messageObj = JSON.parseObject(sendMsg, MessageObj.class); System.out.println(messageObj.toString()); try { //告诉服务器收到这条消息已经被当前消费者消费了,可以在队列安全删除,这样后面就不会再重发了, //否则消息服务器以为这条消息没处理掉,后续还会再发 //第二个参数是消息的标识,false只确认当前一个消息收到,true确认所有consumer获得的消息 channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); System.out.println("receiver success"); } catch (Exception e) { System.out.println("receiver fail"); e.printStackTrace();
Example #9
|
* 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);