org.springframework.amqp.AmqpException Java Examples

The following examples show how to use org.springframework.amqp.AmqpException. 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: TracingRabbitTemplate.java    From java-spring-rabbitmq with Apache License 2.0 6 votes vote down vote up
@Override
public void send(String exchange, String routingKey, Message message, CorrelationData correlationData) throws AmqpException {
  // used when sending reply to AMQP requests that expected response message
  // or when not waiting for reply (for example sending out events).
  if (routingKey.startsWith(Address.AMQ_RABBITMQ_REPLY_TO + ".")) {
    super.send(exchange, routingKey, message, correlationData);
    spanDecorator.onSendReply(message.getMessageProperties(), exchange, routingKey, tracer.activeSpan());
    return; // don't create new span for response messages
  }
  try {
    createTracingHelper()
        .doWithTracingHeadersMessage(exchange, routingKey, message, (messageWithTracingHeaders) -> {
          super.send(exchange, routingKey, messageWithTracingHeaders, correlationData);
          return null;
        });
  } catch (Throwable throwable) {
    Throwables.propagateIfPossible(throwable, AmqpException.class);
  }
}
 
Example #2
Source File: MQService.java    From WeBASE-Front with Apache License 2.0 6 votes vote down vote up
/**
 * bind new queue to existed exchange
 * @param exchangeName
 * @param queueName
 * @param routingKey
 */
public void bindQueue2Exchange(String exchangeName, String queueName, String routingKey){
    log.info("bindQueue2Exchange exchangeName:{},queueName:{},routingKey:{}",
            exchangeName, queueName, routingKey);
    Binding binding = BindingBuilder
            .bind(new Queue(queueName))
            .to(new DirectExchange(exchangeName))
            .with(routingKey);
    try {
        rabbitAdmin.declareBinding(binding);
    } catch (AmqpException ex) {
        log.error("Exchange or message queue not exists. ex:[]", ex);
        throw new FrontException(ConstantCode.EXCHANGE_OR_QUEUE_NOT_EXIST_ERROR);
    }
}
 
Example #3
Source File: RabbitGateway.java    From konker-platform with Apache License 2.0 6 votes vote down vote up
public void queueEvent(Device device, EventRoute eventRoute, Event event) {
    try {
        MessageProperties properties = new MessageProperties();
        properties.setHeader(RabbitMQDataConfig.MSG_HEADER_APIKEY, device.getApiKey());
        properties.setHeader(RabbitMQDataConfig.MSG_HEADER_EVENT_ROUTE_GUID, eventRoute.getGuid());

        Message message = new Message(toByteArray(event), properties);
        rabbitTemplate.convertAndSend("routed.events", message);

        if (!event.getIncoming().getChannel().equals("_echo")) {
            LOGGER.info(MessageFormat.format("Output tenant: {0} app: {1} channel: {2} device: {3} ts: {4} size: {5}",
                    device.getTenant().getDomainName(),
                    device.getApplication().getName(),
                    eventRoute.getOutgoing().getData().get("channel"),
                    eventRoute.getOutgoing().getDisplayName(),
                    event.getCreationTimestamp(),
                    event.getPayload().getBytes().length));

        }

    } catch (AmqpException ex) {
        LOGGER.error("AmqpException while sending message to RabbitMQ...", ex);
    }
}
 
Example #4
Source File: RabbitMQOrderSender.java    From HIS with Apache License 2.0 6 votes vote down vote up
public void sendMessage(Long orderId,int type,final long delayTimes){
    //发送信息格式:id&类型(1检查\检验\处置 4草药 5成药)
    String msg = orderId + "&" + type;
    //给延迟队列发送消息
    amqpTemplate.convertAndSend(QueueEnum.QUEUE_TTL_ORDER_CANCEL.getExchange(),
                                QueueEnum.QUEUE_TTL_ORDER_CANCEL.getRouteKey(),
                                msg,
            new MessagePostProcessor() {
                @Override
                public Message postProcessMessage(Message message) throws AmqpException {
                    //给消息设置延迟毫秒值
                     message.getMessageProperties().setExpiration(String.valueOf(delayTimes));
                     return message;
             }
    });
    LOGGER.info("send order message msg:{}",msg);
}
 
Example #5
Source File: RabbitMQOrderSender.java    From HIS with Apache License 2.0 6 votes vote down vote up
public void sendMessage(Long orderId,int type,final long delayTimes){
    //发送信息格式:id&类型(1检查\检验\处置 4草药 5成药)
    String msg = orderId + "&" + type;
    //给延迟队列发送消息
    amqpTemplate.convertAndSend(QueueEnum.QUEUE_TTL_ORDER_CANCEL.getExchange(),
                                QueueEnum.QUEUE_TTL_ORDER_CANCEL.getRouteKey(),
                                msg,
            new MessagePostProcessor() {
                @Override
                public Message postProcessMessage(Message message) throws AmqpException {
                    //给消息设置延迟毫秒值
                     message.getMessageProperties().setExpiration(String.valueOf(delayTimes));
                     return message;
             }
    });
    LOGGER.info("send order message msg:{}",msg);
}
 
Example #6
Source File: RabbitMQOrderSender.java    From HIS with Apache License 2.0 6 votes vote down vote up
public void sendMessage(Long orderId,int type,final long delayTimes){
    //发送信息格式:id&类型(1检查\检验\处置 4草药 5成药)
    String msg = orderId + "&" + type;
    //给延迟队列发送消息
    amqpTemplate.convertAndSend(QueueEnum.QUEUE_TTL_ORDER_CANCEL.getExchange(),
                                QueueEnum.QUEUE_TTL_ORDER_CANCEL.getRouteKey(),
                                msg,
            new MessagePostProcessor() {
                @Override
                public Message postProcessMessage(Message message) throws AmqpException {
                    //给消息设置延迟毫秒值
                     message.getMessageProperties().setExpiration(String.valueOf(delayTimes));
                     return message;
             }
    });
    LOGGER.info("send order message msg:{}",msg);
}
 
Example #7
Source File: RabbitMQOrderSender.java    From HIS with Apache License 2.0 6 votes vote down vote up
public void sendMessage(Long orderId,int type,final long delayTimes){
    //发送信息格式:id&类型(1检查\检验\处置 4草药 5成药)
    String msg = orderId + "&" + type;
    //给延迟队列发送消息
    amqpTemplate.convertAndSend(QueueEnum.QUEUE_TTL_ORDER_CANCEL.getExchange(),
                                QueueEnum.QUEUE_TTL_ORDER_CANCEL.getRouteKey(),
                                msg,
            new MessagePostProcessor() {
                @Override
                public Message postProcessMessage(Message message) throws AmqpException {
                    //给消息设置延迟毫秒值
                     message.getMessageProperties().setExpiration(String.valueOf(delayTimes));
                     return message;
             }
    });
    LOGGER.info("send order message msg:{}",msg);
}
 
Example #8
Source File: BasicService.java    From lemon-rabbitmq with Apache License 2.0 6 votes vote down vote up
public void sendMessage(final String serviceName, final String serviceMethodName,final String correlationId, Object request) {
	logger.info("sendMessage [this.{}, serviceMethodName:{} serviceName:{} correlationId: {}]", this.getClass(), serviceMethodName, serviceName, correlationId);
	rabbitTemplate.setCorrelationKey(correlationId);
	rabbitTemplate.convertAndSend(routingkey, request, new MessagePostProcessor() {            
    	@Override
        public Message postProcessMessage(Message message) throws AmqpException {
            message.getMessageProperties().setAppId(appId);
            message.getMessageProperties().setTimestamp(new Date());
            message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
            message.getMessageProperties().setCorrelationId(correlationId.getBytes());
            message.getMessageProperties().setHeader("ServiceMethodName", serviceMethodName);
            message.getMessageProperties().setHeader("ServiceName", serviceName);
            return message;
        }
    }, new CorrelationData(correlationId));
}
 
Example #9
Source File: ITShippingController.java    From shipping with Apache License 2.0 5 votes vote down vote up
@Test
public void doNotCrashWhenNoQueue() throws Exception {
    doThrow(new AmqpException("test error")).when(rabbitTemplate).convertAndSend(anyString(), any(Shipment.class));
    Shipment original = new Shipment("someName");
    Shipment saved = shippingController.postShipping(original);
    verify(rabbitTemplate, times(1)).convertAndSend(anyString(), any(Shipment.class));
    assertThat(original, is(equalTo(saved)));
}
 
Example #10
Source File: RabbitMqSendTracingHelper.java    From java-spring-rabbitmq with Apache License 2.0 5 votes vote down vote up
public <T> T doWithTracingHeadersMessage(String exchange, String routingKey, Object message, ProceedFunction<T> proceedCallback)
    throws Throwable {

  if (routingKey != null && routingKey.startsWith(Address.AMQ_RABBITMQ_REPLY_TO + ".")) {
    // don't create new span for response messages when sending reply to AMQP requests that expected response message
    Message convertedMessage = convertMessageIfNecessary(message);
    spanDecorator.onSendReply(convertedMessage.getMessageProperties(), exchange, routingKey, tracer.activeSpan());
    return proceedCallback.apply(convertedMessage);
  }

  Message messageWithTracingHeaders = doBefore(exchange, routingKey, message);

  try {

    T resp = proceedCallback.apply(messageWithTracingHeaders);

    if (resp == null && nullResponseMeansError) {
      Span span = tracer.scopeManager().activeSpan();
      spanDecorator.onError(null, span);
      long replyTimeout = (long) ReflectionUtils.getField(FIELD_REPLY_TIMEOUT, rabbitTemplate);
      span.log("Timeout: AMQP request message handler hasn't sent reply AMQP message in " + replyTimeout + "ms");
    }
    return resp;
  } catch (AmqpException ex) {
    spanDecorator.onError(ex, tracer.scopeManager().activeSpan());
    throw ex;
  } finally {
    Optional.ofNullable(tracer.scopeManager().activeSpan())
        .ifPresent(Span::finish);
    scope.close();
  }
}
 
Example #11
Source File: CancelOrderSender.java    From mall with Apache License 2.0 5 votes vote down vote up
public void sendMessage(Long orderId,final long delayTimes){
    //给延迟队列发送消息
    amqpTemplate.convertAndSend(QueueEnum.QUEUE_TTL_ORDER_CANCEL.getExchange(), QueueEnum.QUEUE_TTL_ORDER_CANCEL.getRouteKey(), orderId, new MessagePostProcessor() {
        @Override
        public Message postProcessMessage(Message message) throws AmqpException {
            //给消息设置延迟毫秒值
            message.getMessageProperties().setExpiration(String.valueOf(delayTimes));
            return message;
        }
    });
    LOGGER.info("send orderId:{}",orderId);
}
 
Example #12
Source File: NotifyServiceImpl.java    From fw-cloud-framework with MIT License 5 votes vote down vote up
@Override
public void notifyPayOrder(NotifyBean notifyBean, int count) {
	rabbitTemplate.convertAndSend(RabbitConfiguration.PAY_NOTIFY_DELAY_PRE_MESSAGE_TTL,
			notifyBean, new MessagePostProcessor() {

				@Override
				public Message postProcessMessage(Message message) throws AmqpException {
					message.getMessageProperties().setExpiration(count + "");
					message.getMessageProperties().setDeliveryMode(
							MessageDeliveryMode.PERSISTENT);
					return message;
				}
			});
}
 
Example #13
Source File: RabbitmqTemplate.java    From shine-mq with Apache License 2.0 5 votes vote down vote up
private Object send(String exchangeName, Object msg, MessageConverter messageConverter, SendTypeEnum type,
                    String routingKey, int expiration, int priority) throws Exception {
    check(exchangeName, routingKey);

    Object obj = null;
    String msgId = UUID.randomUUID().toString();
    EventMessage eventMessage = new EventMessage(exchangeName, routingKey, type.toString(), msg, null, msgId);
    MessageProperties messageProperties = new MessageProperties();
    //过期时间
    if (expiration > 0) {
        messageProperties.setExpiration(String.valueOf(expiration));
    }
    //消息优先级
    if (priority > 0) {
        messageProperties.setPriority(priority);
    }
    messageProperties.setMessageId(msgId);
    // 设置消息持久化
    messageProperties.setDeliveryMode(MessageDeliveryMode.PERSISTENT);
    Message message = messageConverter.toMessage(eventMessage, messageProperties);
    rabbitmqFactory.setCorrelationData(msgId, null, eventMessage, null);
    try {
        if (SendTypeEnum.RPC.equals(type)) {
            obj = eventAmqpTemplate.convertSendAndReceive(routingKey, message);
        } else {
            eventAmqpTemplate.send(exchangeName, routingKey, message);
        }
    } catch (AmqpException e) {
        logger.error("send event fail. Event Message : [{}]", eventMessage, e);
        throw new Exception("send event fail", e);
    }
    return obj;
}
 
Example #14
Source File: RabbitmqTemplate.java    From shine-mq with Apache License 2.0 5 votes vote down vote up
private Object sendWithEM(EventMessage eventMessage, int expiration, int priority, SendTypeEnum type) throws Exception {

        Object obj = null;
        MessageProperties messageProperties = new MessageProperties();
        //过期时间
        if (expiration > 0) {
            messageProperties.setExpiration(String.valueOf(expiration));
        }
        //消息优先级
        if (priority > 0) {
            messageProperties.setPriority(priority);
        }
        messageProperties.setMessageId(eventMessage.getMessageId());
        // 设置消息持久化
        messageProperties.setDeliveryMode(MessageDeliveryMode.PERSISTENT);
        Message message = messageConverter.toMessage(eventMessage, messageProperties);
        rabbitmqFactory.setCorrelationData(eventMessage.getMessageId(), eventMessage.getCoordinator(), eventMessage, null);
        try {
            if (SendTypeEnum.RPC.equals(type)) {
                obj = eventAmqpTemplate.convertSendAndReceive(eventMessage.getRoutingKey(), message);
            } else {
                eventAmqpTemplate.send(eventMessage.getExchangeName(), eventMessage.getRoutingKey(), message);
            }
        } catch (AmqpException e) {
            logger.error("send event fail. Event Message : [{}]", eventMessage, e);
            throw new Exception("send event fail", e);
        }
        return obj;
    }
 
Example #15
Source File: CancelOrderSender.java    From macrozheng-mall with MIT License 5 votes vote down vote up
public void sendMessage(Long orderId,final long delayTimes){
    //给延迟队列发送消息
    amqpTemplate.convertAndSend(QueueEnum.QUEUE_TTL_ORDER_CANCEL.getExchange(), QueueEnum.QUEUE_TTL_ORDER_CANCEL.getRouteKey(), orderId, new MessagePostProcessor() {
        @Override
        public Message postProcessMessage(Message message) throws AmqpException {
            //给消息设置延迟毫秒值
            message.getMessageProperties().setExpiration(String.valueOf(delayTimes));
            return message;
        }
    });
    LOGGER.info("send orderId:{}",orderId);
}
 
Example #16
Source File: RabbitMq4PayNotify.java    From xxpay-master with MIT License 5 votes vote down vote up
@Override
public void send(String msg, long delay) {
	_log.info("发送MQ延时消息:msg={},delay={}", msg, delay);
	rabbitTemplate.convertAndSend(PAY_NOTIFY_EXCHANGE_NAME, PAY_NOTIFY_QUEUE_NAME, msg, new MessagePostProcessor() {
		public Message postProcessMessage(Message message) throws AmqpException {
			message.getMessageProperties().setDelay((int) delay);
			return message;
		}
	});
}
 
Example #17
Source File: ShippingController.java    From shipping with Apache License 2.0 5 votes vote down vote up
@ResponseStatus(HttpStatus.OK)
@RequestMapping(method = RequestMethod.GET, path = "/health")
public
@ResponseBody
Map<String, List<HealthCheck>> getHealth() {
    Map<String, List<HealthCheck>> map = new HashMap<String, List<HealthCheck>>();
    List<HealthCheck> healthChecks = new ArrayList<HealthCheck>();
    Date dateNow = Calendar.getInstance().getTime();

    HealthCheck rabbitmq = new HealthCheck("shipping-rabbitmq", "OK", dateNow);
    HealthCheck app = new HealthCheck("shipping", "OK", dateNow);

    try {
        this.rabbitTemplate.execute(new ChannelCallback<String>() {
            @Override
            public String doInRabbit(Channel channel) throws Exception {
                Map<String, Object> serverProperties = channel.getConnection().getServerProperties();
                return serverProperties.get("version").toString();
            }
        });
    } catch ( AmqpException e ) {
        rabbitmq.setStatus("err");
    }

    healthChecks.add(rabbitmq);
    healthChecks.add(app);

    map.put("health", healthChecks);
    return map;
}
 
Example #18
Source File: RabbitOrderMessagingService.java    From spring-in-action-5-samples with Apache License 2.0 5 votes vote down vote up
public void sendOrder(Order order) {
  rabbit.convertAndSend("tacocloud.order.queue", order,
      new MessagePostProcessor() {
        @Override
        public Message postProcessMessage(Message message)
            throws AmqpException {
          MessageProperties props = message.getMessageProperties();
          props.setHeader("X_ORDER_SOURCE", "WEB");
          return message;
        } 
      });
}
 
Example #19
Source File: RabbitGateway.java    From konker-platform with Apache License 2.0 5 votes vote down vote up
public void sendEvent(String apiKey, String channel, byte[] payload) {

        try {
            MessageProperties properties = new MessageProperties();
            properties.setHeader(RabbitMQConfig.MSG_HEADER_APIKEY, apiKey);
            properties.setHeader(RabbitMQConfig.MSG_HEADER_CHANNEL, channel);

            Message message = new Message(payload, properties);

            rabbitTemplate.convertAndSend("data.sub", message);
        } catch (AmqpException ex) {
            LOGGER.error("AmqpException while sending message to RabbitMQ...", ex);
        }
    }
 
Example #20
Source File: RabbitGateway.java    From konker-platform with Apache License 2.0 5 votes vote down vote up
public void sendConfig(String apiKey, String config) {

        try {
            MessageProperties properties = new MessageProperties();
            properties.setHeader(RabbitMQConfig.MSG_HEADER_APIKEY, apiKey);

            Message message = new Message(config.getBytes("UTF-8"), properties);

            rabbitTemplate.convertAndSend("mgmt.config.sub", message);
        } catch (AmqpException | UnsupportedEncodingException ex) {
            LOGGER.error("AmqpException while sending message to RabbitMQ...", ex);
        }

    }
 
Example #21
Source File: RabbitGateway.java    From konker-platform with Apache License 2.0 5 votes vote down vote up
public void queueEventDataPub(String apiKey, String channel, Long epochMilli, byte[] payload) {
    try {
        MessageProperties properties = new MessageProperties();
        properties.setHeader(RabbitMQConfig.MSG_HEADER_APIKEY, apiKey);
        properties.setHeader(RabbitMQConfig.MSG_HEADER_CHANNEL, channel);
        properties.setHeader(RabbitMQConfig.MSG_HEADER_TIMESTAMP, epochMilli);

        Message message = new Message(payload, properties);

        rabbitTemplate.convertAndSend("data.pub", message);
    } catch (AmqpException ex) {
        LOGGER.error("AmqpException while sending message to RabbitMQ...", ex);
    }
}
 
Example #22
Source File: RabbitSourceTests.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
	Advice[] adviceChain = TestUtils.getPropertyValue(this.container, "adviceChain", Advice[].class);
	assertEquals(1, adviceChain.length);
	RetryTemplate retryTemplate = TestUtils.getPropertyValue(adviceChain[0], "retryOperations",
			RetryTemplate.class);
	assertEquals(5, TestUtils.getPropertyValue(retryTemplate, "retryPolicy.maxAttempts"));
	assertEquals(123L, TestUtils.getPropertyValue(retryTemplate, "backOffPolicy.initialInterval"));
	assertEquals(345L, TestUtils.getPropertyValue(retryTemplate, "backOffPolicy.maxInterval"));
	assertEquals(1.5, TestUtils.getPropertyValue(retryTemplate, "backOffPolicy.multiplier"));
	assertEquals("scsapp-testq", this.container.getQueueNames()[0]);
	assertFalse(TestUtils.getPropertyValue(this.container, "defaultRequeueRejected", Boolean.class));
	assertEquals(2, TestUtils.getPropertyValue(this.container, "concurrentConsumers"));
	assertEquals(3, TestUtils.getPropertyValue(this.container, "maxConcurrentConsumers"));
	assertEquals(AcknowledgeMode.NONE, TestUtils.getPropertyValue(this.container, "acknowledgeMode"));
	assertEquals(10, TestUtils.getPropertyValue(this.container, "prefetchCount"));
	assertEquals(5, TestUtils.getPropertyValue(this.container, "txSize"));

	this.rabbitTemplate.convertAndSend("", "scsapp-testq", "foo", new MessagePostProcessor() {

		@Override
		public org.springframework.amqp.core.Message postProcessMessage(
				org.springframework.amqp.core.Message message) throws AmqpException {
			message.getMessageProperties().getHeaders().put("bar", "baz");
			return message;
		}

	});
	Message<?> out = this.messageCollector.forChannel(this.channels.output()).poll(10,  TimeUnit.SECONDS);
	assertNotNull(out);
	assertEquals("foo", out.getPayload());
	assertEquals("baz", out.getHeaders().get("bar"));
	assertNull(out.getHeaders().get(AmqpHeaders.DELIVERY_MODE));
}
 
Example #23
Source File: CancelOrderSender.java    From mall-learning with Apache License 2.0 5 votes vote down vote up
public void sendMessage(Long orderId,final long delayTimes){
    //给延迟队列发送消息
    amqpTemplate.convertAndSend(QueueEnum.QUEUE_TTL_ORDER_CANCEL.getExchange(), QueueEnum.QUEUE_TTL_ORDER_CANCEL.getRouteKey(), orderId, new MessagePostProcessor() {
        @Override
        public Message postProcessMessage(Message message) throws AmqpException {
            //给消息设置延迟毫秒值
            message.getMessageProperties().setExpiration(String.valueOf(delayTimes));
            return message;
        }
    });
    LOGGER.info("send delay message orderId:{}",orderId);
}
 
Example #24
Source File: CancelOrderSender.java    From Spring-Boot-Book with Apache License 2.0 5 votes vote down vote up
public void sendMsg(String queueName, Integer msg) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    System.out.println("Sender:" + sdf.format(new Date()));
    rabbitTemplate.convertAndSend("delayed_exchange", queueName, msg, new MessagePostProcessor() {
        @Override
        public Message postProcessMessage(Message message) throws AmqpException {
            //限定延迟时间
            int delay_time = 100000;
            message.getMessageProperties().setHeader("x-delay", delay_time);
            return message;
        }
    });
}
 
Example #25
Source File: MQService.java    From WeBASE-Front with Apache License 2.0 5 votes vote down vote up
public void unbindQueueFromExchange(String exchangeName, String queueName, String routingKey){
    log.info("unbindQueueFromExchange exchangeName:{},queueName:{},routingKey:{}",
            exchangeName, queueName, routingKey);
    Binding binding = BindingBuilder
            .bind(new Queue(queueName))
            .to(new DirectExchange(exchangeName))
            .with(routingKey);
    try {
        rabbitAdmin.removeBinding(binding);
    } catch (AmqpException ex) {
        log.error("Exchange or message queue not exists. ex:[]", ex);
        throw new FrontException(ConstantCode.EXCHANGE_OR_QUEUE_NOT_EXIST_ERROR);
    }
}
 
Example #26
Source File: CancelOrderSender.java    From xmall with MIT License 5 votes vote down vote up
public void sendMessage(Long orderId,final long delayTimes){
    //给延迟队列发送消息
    amqpTemplate.convertAndSend(QueueEnum.QUEUE_TTL_ORDER_CANCEL.getExchange(), QueueEnum.QUEUE_TTL_ORDER_CANCEL.getRouteKey(), orderId, new MessagePostProcessor() {
        @Override
        public Message postProcessMessage(Message message) throws AmqpException {
            //给消息设置延迟毫秒值
            message.getMessageProperties().setExpiration(String.valueOf(delayTimes));
            return message;
        }
    });
    LOGGER.info("send orderId:{}",orderId);
}
 
Example #27
Source File: CancelOrderSender.java    From mall-tiny with Apache License 2.0 5 votes vote down vote up
public void sendMessage(Long orderId,final long delayTimes){
    //给延迟队列发送消息
    amqpTemplate.convertAndSend(QueueEnum.QUEUE_TTL_ORDER_CANCEL.getExchange(), QueueEnum.QUEUE_TTL_ORDER_CANCEL.getRouteKey(), orderId, new MessagePostProcessor() {
        @Override
        public Message postProcessMessage(Message message) throws AmqpException {
            //给消息设置延迟毫秒值
            message.getMessageProperties().setExpiration(String.valueOf(delayTimes));
            return message;
        }
    });
    LOGGER.info("send delay message orderId:{}",orderId);
}
 
Example #28
Source File: CancelOrderSender.java    From mall-learning with Apache License 2.0 5 votes vote down vote up
public void sendMessage(Long orderId,final long delayTimes){
    //给延迟队列发送消息
    amqpTemplate.convertAndSend(QueueEnum.QUEUE_ORDER_PLUGIN_CANCEL.getExchange(), QueueEnum.QUEUE_ORDER_PLUGIN_CANCEL.getRouteKey(), orderId, new MessagePostProcessor() {
        @Override
        public Message postProcessMessage(Message message) throws AmqpException {
            //给消息设置延迟毫秒值
            message.getMessageProperties().setHeader("x-delay",delayTimes);
            return message;
        }
    });
    LOGGER.info("send delay message orderId:{}",orderId);
}
 
Example #29
Source File: CancelOrderSender.java    From mall-learning with Apache License 2.0 5 votes vote down vote up
public void sendMessage(Long orderId,final long delayTimes){
    //给延迟队列发送消息
    amqpTemplate.convertAndSend(QueueEnum.QUEUE_TTL_ORDER_CANCEL.getExchange(), QueueEnum.QUEUE_TTL_ORDER_CANCEL.getRouteKey(), orderId, new MessagePostProcessor() {
        @Override
        public Message postProcessMessage(Message message) throws AmqpException {
            //给消息设置延迟毫秒值
            message.getMessageProperties().setExpiration(String.valueOf(delayTimes));
            return message;
        }
    });
    LOGGER.info("send delay message orderId:{}",orderId);
}
 
Example #30
Source File: CancelOrderSender.java    From mall-learning with Apache License 2.0 5 votes vote down vote up
public void sendMessage(Long orderId,final long delayTimes){
    //给延迟队列发送消息
    amqpTemplate.convertAndSend(QueueEnum.QUEUE_TTL_ORDER_CANCEL.getExchange(), QueueEnum.QUEUE_TTL_ORDER_CANCEL.getRouteKey(), orderId, new MessagePostProcessor() {
        @Override
        public Message postProcessMessage(Message message) throws AmqpException {
            //给消息设置延迟毫秒值
            message.getMessageProperties().setExpiration(String.valueOf(delayTimes));
            return message;
        }
    });
    LOGGER.info("send delay message orderId:{}",orderId);
}