org.springframework.amqp.core.MessagePostProcessor Java Examples

The following examples show how to use org.springframework.amqp.core.MessagePostProcessor. 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: RabbitMqTracingAutoConfigurationCustomizationItTest.java    From java-spring-rabbitmq with Apache License 2.0 10 votes vote down vote up
@Test
public void convertAndSend_withRoutingKeyAndMessagePostProcessor_shouldBeTraced() {
  // given
  Message requestMessage = createMessage();
  MessagePostProcessor messagePostProcessor = msg -> msg;

  // when
  rabbitTemplate.convertAndSend(ROUTING_KEY, requestMessage, messagePostProcessor);

  // then
  FinishedSpansHelper spans = awaitFinishedSpans();
  MockSpan sentSpan = spans.getSendSpan();
  MockSpan receiveSpan = spans.getReceiveSpan();

  assertOnSpans(sentSpan, receiveSpan, ROUTING_KEY);
}
 
Example #2
Source File: RabbitMqTracingAutoConfigurationCustomizationItTest.java    From java-spring-rabbitmq with Apache License 2.0 6 votes vote down vote up
@Test
public void convertSendAndReceive_withRoutingKeyMessageAndMessagePostProcessor_shouldBeTraced() {
  // given
  Message requestMessage = createMessage();
  MessagePostProcessor messagePostProcessor = msg -> msg;

  // when
  Object response = rabbitTemplate.convertSendAndReceive(ROUTING_KEY, requestMessage, messagePostProcessor);

  // then
  FinishedSpansHelper spans = awaitFinishedSpans();
  MockSpan sentSpan = spans.getSendSpan();
  MockSpan receiveSpan = spans.getReceiveSpan();

  assertOnSpans(sentSpan, receiveSpan, ROUTING_KEY);
}
 
Example #3
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 #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: RabbitMqTracingAutoConfigurationCustomizationItTest.java    From java-spring-rabbitmq with Apache License 2.0 6 votes vote down vote up
@Test
public void convertSendAndReceive_withMessageAndMessagePostProcessor_shouldBeTraced() {
  // given
  Message requestMessage = createMessage();
  MessagePostProcessor messagePostProcessor = msg -> msg;

  // when
  Object response = rabbitTemplate.convertSendAndReceive(requestMessage, messagePostProcessor);

  // then
  FinishedSpansHelper spans = awaitFinishedSpans();
  MockSpan sentSpan = spans.getSendSpan();
  MockSpan receiveSpan = spans.getReceiveSpan();

  assertOnSpans(sentSpan, receiveSpan, EMPTY_ROUTING_KEY);
}
 
Example #9
Source File: RabbitMqTracingAutoConfigurationCustomizationItTest.java    From java-spring-rabbitmq with Apache License 2.0 6 votes vote down vote up
@Test
public void convertAndSend_withMessagePostProcessor_shouldBeTraced() {
  // given
  Message requestMessage = createMessage();
  MessagePostProcessor messagePostProcessor = msg -> msg;

  // when
  rabbitTemplate.convertAndSend(requestMessage, messagePostProcessor);

  // then
  FinishedSpansHelper spans = awaitFinishedSpans();
  MockSpan sentSpan = spans.getSendSpan();
  MockSpan receiveSpan = spans.getReceiveSpan();

  assertOnSpans(sentSpan, receiveSpan, EMPTY_ROUTING_KEY);
}
 
Example #10
Source File: RabbitMqTracingAutoConfigurationDisabledItTest.java    From java-spring-rabbitmq with Apache License 2.0 5 votes vote down vote up
@Test
public void convertAndSend_withRoutingKeyAndMessagePostProcessor_shouldNotBeTraced() {
  // given
  Message requestMessage = createMessage();
  MessagePostProcessor messagePostProcessor = msg -> msg;

  // when
  rabbitTemplate.convertAndSend(ROUTING_KEY, requestMessage, messagePostProcessor);

  // then
  checkNoSpans();
}
 
Example #11
Source File: RabbitMqTracingAutoConfigurationItTest.java    From java-spring-rabbitmq with Apache License 2.0 5 votes vote down vote up
@Test
public void convertSendAndReceive_withMessageAndMessagePostProcessor_shouldBeTraced() {
  // given
  Message requestMessage = createMessage();
  MessagePostProcessor messagePostProcessor = msg -> msg;

  // when
  Object response = rabbitTemplate.convertSendAndReceive(requestMessage, messagePostProcessor);

  // then
  assertConsumerAndProducerSpans(0, EMPTY_ROUTING_KEY);
  assertOnResponse(response);
}
 
Example #12
Source File: RabbitMqTracingAutoConfigurationDisabledItTest.java    From java-spring-rabbitmq with Apache License 2.0 5 votes vote down vote up
@Test
public void convertAndSend_withExchangeRoutingKeyAndMessagePostProcessor_shouldNotBeTraced() {
  // given
  MessagePostProcessor messagePostProcessor = msg -> msg;

  // when
  rabbitTemplate.convertAndSend(EXCHANGE, ROUTING_KEY, MESSAGE, messagePostProcessor);

  // then
  checkNoSpans();
}
 
Example #13
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 #14
Source File: RabbitMqSendTracingAspect.java    From java-spring-rabbitmq with Apache License 2.0 5 votes vote down vote up
/**
 * @see org.springframework.amqp.core.AmqpTemplate#convertSendAndReceive(String, Object, MessagePostProcessor)
 */
@Around(value = "execution(* org.springframework.amqp.core.AmqpTemplate.convertSendAndReceive(..))" +
                " && args(routingKey, message, messagePostProcessor)",
    argNames = "pjp,routingKey,message,messagePostProcessor")
public Object traceRabbitConvertSendAndReceive(ProceedingJoinPoint pjp, String routingKey, Object message,
                                               MessagePostProcessor messagePostProcessor)
    throws Throwable {
  return createTracingHelper()
      .doWithTracingHeadersMessage(exchange, routingKey, message, (convertedMessage) ->
          proceedReplacingMessage(pjp, convertedMessage, 1));
}
 
Example #15
Source File: RabbitMqSendTracingAspect.java    From java-spring-rabbitmq with Apache License 2.0 5 votes vote down vote up
/**
 * @see org.springframework.amqp.core.AmqpTemplate#convertSendAndReceive(String, String, Object, MessagePostProcessor)
 */
@Around(value = "execution(* org.springframework.amqp.core.AmqpTemplate.convertSendAndReceive(..))" +
                " && args(exchange, routingKey, message, messagePostProcessor)",
    argNames = "pjp,exchange,routingKey,message,messagePostProcessor")
public Object traceRabbitConvertSendAndReceive(ProceedingJoinPoint pjp, String exchange, String routingKey,
                                               Object message, MessagePostProcessor messagePostProcessor)
    throws Throwable {
  return createTracingHelper()
      .doWithTracingHeadersMessage(exchange, routingKey, message, (convertedMessage) ->
          proceedReplacingMessage(pjp, convertedMessage, 2));
}
 
Example #16
Source File: RabbitMqSendTracingAspect.java    From java-spring-rabbitmq with Apache License 2.0 5 votes vote down vote up
/**
 * @see RabbitTemplate#convertSendAndReceive(String, String, Object, MessagePostProcessor, CorrelationData)
 */
@Around(value = "execution(* org.springframework.amqp.rabbit.core.RabbitTemplate.convertSendAndReceive(..)) " +
                "&& args(exchange, routingKey, message, messagePostProcessor, correlationData)",
    argNames = "pjp,exchange,routingKey,message,messagePostProcessor,correlationData")
public Object traceRabbitConvertSendAndReceive(
    ProceedingJoinPoint pjp, String exchange, String routingKey, Object message,
    MessagePostProcessor messagePostProcessor, CorrelationData correlationData)
    throws Throwable {
  return createTracingHelper()
      .nullResponseMeansTimeout((RabbitTemplate) pjp.getTarget())
      .doWithTracingHeadersMessage(exchange, routingKey, message, (convertedMessage) ->
          proceedReplacingMessage(pjp, convertedMessage, 2));
}
 
Example #17
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 #18
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 #19
Source File: CustomSender.java    From Spring-Boot-Book with Apache License 2.0 5 votes vote down vote up
public void sendMsg(String queueName, String 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 {
            //
            message.getMessageProperties().setHeader("x-delay", 5000);
            return message;
        }
    });
}
 
Example #20
Source File: RabbitMqSendTracingAspect.java    From java-spring-rabbitmq with Apache License 2.0 5 votes vote down vote up
/**
 * @see org.springframework.amqp.core.AmqpTemplate#convertSendAndReceive(Object, MessagePostProcessor)
 */
@Around(value = "execution(* org.springframework.amqp.core.AmqpTemplate.convertSendAndReceive(..))" +
                " && args(message, messagePostProcessor)", argNames = "pjp,message,messagePostProcessor")
public Object traceRabbitConvertSendAndReceive(ProceedingJoinPoint pjp, Object message,
                                               MessagePostProcessor messagePostProcessor)
    throws Throwable {
  return createTracingHelper()
      .doWithTracingHeadersMessage(exchange, routingKey, message, (convertedMessage) ->
          proceedReplacingMessage(pjp, convertedMessage, 0));
}
 
Example #21
Source File: RabbitMqTracingAutoConfigurationDisabledItTest.java    From java-spring-rabbitmq with Apache License 2.0 5 votes vote down vote up
@Test
public void convertAndSend_withMessagePostProcessor_shouldNotBeTraced() {
  // given
  Message requestMessage = createMessage();
  MessagePostProcessor messagePostProcessor = msg -> msg;

  // when
  rabbitTemplate.convertAndSend(requestMessage, messagePostProcessor);

  // then
  checkNoSpans();
}
 
Example #22
Source File: RabbitMqTracingAutoConfigurationItTest.java    From java-spring-rabbitmq with Apache License 2.0 5 votes vote down vote up
@Test
public void convertSendAndReceive_withExchangeRoutingKeyMessageMessagePostProcessorAndCorrelationData_shouldBeTraced() {
  // given
  MessagePostProcessor messagePostProcessor = msg -> msg;

  // when
  Object response = rabbitTemplate.convertSendAndReceive(EXCHANGE, ROUTING_KEY, MESSAGE, messagePostProcessor, null);

  // then
  assertConsumerAndProducerSpans(0, ROUTING_KEY);
  assertOnResponse(response);
}
 
Example #23
Source File: RabbitMqTracingAutoConfigurationItTest.java    From java-spring-rabbitmq with Apache License 2.0 5 votes vote down vote up
@Test
public void convertSendAndReceive_withExchangeRoutingKeyMessageMessagePostProcessor_shouldBeTraced() {
  // given
  MessagePostProcessor messagePostProcessor = msg -> msg;

  // when
  Object response = rabbitTemplate.convertSendAndReceive(EXCHANGE, ROUTING_KEY, MESSAGE, messagePostProcessor);

  // then
  assertConsumerAndProducerSpans(0, ROUTING_KEY);
  assertOnResponse(response);
}
 
Example #24
Source File: RabbitMqTracingAutoConfigurationItTest.java    From java-spring-rabbitmq with Apache License 2.0 5 votes vote down vote up
@Test
public void convertSendAndReceive_withRoutingKeyMessageAndMessagePostProcessor_shouldBeTraced() {
  // given
  Message requestMessage = createMessage();
  MessagePostProcessor messagePostProcessor = msg -> msg;

  // when
  Object response = rabbitTemplate.convertSendAndReceive(ROUTING_KEY, requestMessage, messagePostProcessor);

  // then
  assertConsumerAndProducerSpans(0, ROUTING_KEY);
  assertOnResponse(response);
}
 
Example #25
Source File: RabbitMqTracingAutoConfigurationDisabledItTest.java    From java-spring-rabbitmq with Apache License 2.0 5 votes vote down vote up
@Test
public void convertSendAndReceive_withExchangeRoutingKeyMessageMessagePostProcessorAndCorrelationData_shouldNotBeTraced() {
  // given
  MessagePostProcessor messagePostProcessor = msg -> msg;

  // when
  rabbitTemplate.convertSendAndReceive(EXCHANGE, ROUTING_KEY, MESSAGE, messagePostProcessor, null);

  // then
  checkNoSpans();
}
 
Example #26
Source File: RabbitMqTracingAutoConfigurationItTest.java    From java-spring-rabbitmq with Apache License 2.0 5 votes vote down vote up
@Test
public void convertAndSend_withExchangeRoutingKeyAndMessagePostProcessor_shouldBeTraced() {
  // given
  MessagePostProcessor messagePostProcessor = msg -> msg;

  // when
  rabbitTemplate.convertAndSend(EXCHANGE, ROUTING_KEY, MESSAGE, messagePostProcessor);

  // then
  assertConsumerAndProducerSpans(0, ROUTING_KEY);
}
 
Example #27
Source File: RabbitMqTracingAutoConfigurationItTest.java    From java-spring-rabbitmq with Apache License 2.0 5 votes vote down vote up
@Test
public void convertAndSend_withRoutingKeyAndMessagePostProcessor_shouldBeTraced() {
  // given
  Message requestMessage = createMessage();
  MessagePostProcessor messagePostProcessor = msg -> msg;

  // when
  rabbitTemplate.convertAndSend(ROUTING_KEY, requestMessage, messagePostProcessor);

  // then
  assertConsumerAndProducerSpans(0, ROUTING_KEY);
}
 
Example #28
Source File: RabbitMqTracingAutoConfigurationItTest.java    From java-spring-rabbitmq with Apache License 2.0 5 votes vote down vote up
@Test
public void convertAndSend_withMessagePostProcessor_shouldBeTraced() {
  // given
  Message requestMessage = createMessage();
  MessagePostProcessor messagePostProcessor = msg -> msg;

  // when
  rabbitTemplate.convertAndSend(requestMessage, messagePostProcessor);

  // then
  assertConsumerAndProducerSpans(0, EMPTY_ROUTING_KEY);
}
 
Example #29
Source File: RabbitMqTracingAutoConfigurationWithoutRabbitTemplateItTest.java    From java-spring-rabbitmq with Apache License 2.0 5 votes vote down vote up
@Test
public void convertSendAndReceive_withExchangeAndRoutingKey_shouldBeTraced() {
  // given
  MessagePostProcessor messagePostProcessor = msg -> msg;
  RabbitTemplate rabbitTemplate = getRabbitTemplate();

  // when
  Object response = rabbitTemplate
      .convertSendAndReceive(EXCHANGE, ROUTING_KEY, MESSAGE, messagePostProcessor, null);

  // then
  assertConsumerAndProducerSpans(0, ROUTING_KEY);
  assertThat(response.toString(), equalTo(TestMessageListener.REPLY_MSG_PREFIX + MESSAGE));
}
 
Example #30
Source File: RabbitMqTracingAutoConfigurationCustomizationItTest.java    From java-spring-rabbitmq with Apache License 2.0 5 votes vote down vote up
@Test
public void convertSendAndReceive_withExchangeRoutingKeyMessageMessagePostProcessorAndCorrelationData_shouldBeTraced() {
  // given
  MessagePostProcessor messagePostProcessor = msg -> msg;

  // when
  Object response = rabbitTemplate.convertSendAndReceive(EXCHANGE, ROUTING_KEY, MESSAGE, messagePostProcessor, null);

  // then
  FinishedSpansHelper spans = awaitFinishedSpans();
  MockSpan sentSpan = spans.getSendSpan();
  MockSpan receiveSpan = spans.getReceiveSpan();

  assertOnSpans(sentSpan, receiveSpan, ROUTING_KEY);
}