headers.put(AmqpHeaders.CONTENT_TYPE, contentType); String correlationId = amqpMessageProperties.getCorrelationId(); if (StringUtils.hasText(correlationId)) { headers.put(AmqpHeaders.CORRELATION_ID, correlationId);
/** * {@inheritDoc} */ @Override public Message postProcessMessage(final Message message) throws AmqpException { if (message == null) { return message; } final MessageProperties messageProperties = message.getMessageProperties(); messageProperties.setTimestamp(this.properties.getTimestamp()); final byte[] correlationId = this.properties.getCorrelationId(); messageProperties.setCorrelationId(correlationId); messageProperties.setCorrelationIdString(this.properties.getCorrelationIdString()); messageProperties.setReplyTo(this.properties.getReplyTo()); messageProperties.setExpiration(this.properties.getExpiration()); return message; } }
assertEquals(99L, amqpProperties.getContentLength()); assertEquals("test.contentType", amqpProperties.getContentType()); assertEquals(testCorrelationId, amqpProperties.getCorrelationId()); assertEquals(Integer.valueOf(1234), amqpProperties.getDelay()); assertEquals(MessageDeliveryMode.NON_PERSISTENT, amqpProperties.getDeliveryMode());
public MessageBuilderSupport<T> setCorrelationIdIfAbsent(String correlationId) { if (this.properties.getCorrelationId() == null) { this.properties.setCorrelationId(correlationId); } return this; }
private static boolean isCorrelationIdNotEmpty(final Message message) { return StringUtils.hasLength(message.getMessageProperties().getCorrelationId()); }
protected static boolean isCorrelationIdEmpty(final Message message) { return !StringUtils.hasLength(message.getMessageProperties().getCorrelationId()); }
@Override public void returnedMessage(Message message, int replyCode, String replyText, String exchange, String routingKey) { MessageProperties messageProperties = message.getMessageProperties(); String correlationId = messageProperties.getCorrelationId(); if (StringUtils.hasText(correlationId)) { RabbitFuture<?> future = this.pending.remove(correlationId); if (future != null) { future.setException(new AmqpMessageReturnedException("Message returned", message, replyCode, replyText, exchange, routingKey)); } else { if (this.logger.isWarnEnabled()) { this.logger.warn("No pending reply - perhaps timed out? Message returned: " + message); } } } }
@Override public void returnedMessage(Message message, int replyCode, String replyText, String exchange, String routingKey) { MessageProperties messageProperties = message.getMessageProperties(); String correlationId = messageProperties.getCorrelationId(); if (StringUtils.hasText(correlationId)) { RabbitFuture<?> future = this.pending.remove(correlationId); if (future != null) { future.setException(new AmqpMessageReturnedException("Message returned", message, replyCode, replyText, exchange, routingKey)); } else { if (this.logger.isWarnEnabled()) { this.logger.warn("No pending reply - perhaps timed out? Message returned: " + message); } } } }
private String getOrSetCorrelationIdAndSetReplyTo(Message message) { String correlationId; MessageProperties messageProperties = message.getMessageProperties(); Assert.notNull(messageProperties, "the message properties cannot be null"); String currentCorrelationId = messageProperties.getCorrelationId(); if (!StringUtils.hasText(currentCorrelationId)) { correlationId = UUID.randomUUID().toString(); messageProperties.setCorrelationId(correlationId); Assert.isNull(messageProperties.getReplyTo(), "'replyTo' property must be null"); } else { correlationId = currentCorrelationId; } messageProperties.setReplyTo(this.replyAddress); return correlationId; }
private String getOrSetCorrelationIdAndSetReplyTo(Message message) { String correlationId; MessageProperties messageProperties = message.getMessageProperties(); Assert.notNull(messageProperties, "the message properties cannot be null"); String currentCorrelationId = messageProperties.getCorrelationId(); if (!StringUtils.hasText(currentCorrelationId)) { correlationId = UUID.randomUUID().toString(); messageProperties.setCorrelationId(correlationId); Assert.isNull(messageProperties.getReplyTo(), "'replyTo' property must be null"); } else { correlationId = currentCorrelationId; } messageProperties.setReplyTo(this.replyAddress); return correlationId; }
@Override public Message postProcessMessage(final Message message) { MessageProperties messageProperties = message.getMessageProperties(); String correlationId = messageProperties.getCorrelationId(); if (correlationId == null) { correlationId = (tracer!=null && tracer.currentSpan()!=null)? tracer.currentSpan().context().traceIdString():UUID.randomUUID().toString(); messageProperties.setCorrelationId(correlationId); } messageProperties.getHeaders().put("correlation-id", correlationId); return message; }
@Nullable private Message exchangeMessages(final String exchange, final String routingKey, final Message message, final CorrelationData correlationData, Channel channel, final PendingReply pendingReply, String messageTag) throws Exception { // NOSONAR TODO: change to IOException, InterruptedException in 2.2. Message reply; boolean mandatory = isMandatoryFor(message); if (mandatory && this.returnCallback == null) { message.getMessageProperties().getHeaders().put(RETURN_CORRELATION_KEY, messageTag); } doSend(channel, exchange, routingKey, message, mandatory, correlationData); reply = this.replyTimeout < 0 ? pendingReply.get() : pendingReply.get(this.replyTimeout, TimeUnit.MILLISECONDS); if (this.logger.isDebugEnabled()) { this.logger.debug("Reply: " + reply); } if (reply == null) { replyTimedOut(message.getMessageProperties().getCorrelationId()); } return reply; }
@Nullable private Message exchangeMessages(final String exchange, final String routingKey, final Message message, final CorrelationData correlationData, Channel channel, final PendingReply pendingReply, String messageTag) throws Exception { // NOSONAR TODO: change to IOException, InterruptedException in 2.2. Message reply; boolean mandatory = isMandatoryFor(message); if (mandatory && this.returnCallback == null) { message.getMessageProperties().getHeaders().put(RETURN_CORRELATION_KEY, messageTag); } doSend(channel, exchange, routingKey, message, mandatory, correlationData); reply = this.replyTimeout < 0 ? pendingReply.get() : pendingReply.get(this.replyTimeout, TimeUnit.MILLISECONDS); if (this.logger.isDebugEnabled()) { this.logger.debug("Reply: " + reply); } if (reply == null) { replyTimedOut(message.getMessageProperties().getCorrelationId()); } return reply; }
protected void sendPingReponseToDmfReceiver(final Message ping, final String tenant, final String virtualHost) { final Message message = MessageBuilder.withBody(String.valueOf(System.currentTimeMillis()).getBytes()) .setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN) .setCorrelationId(ping.getMessageProperties().getCorrelationId()) .setHeader(MessageHeaderKey.TYPE, MessageType.PING_RESPONSE).setHeader(MessageHeaderKey.TENANT, tenant) .build(); amqpSenderService.sendMessage(message, IpUtil.createAmqpUri(virtualHost, ping.getMessageProperties().getReplyTo())); }
public static SpringAMQPMessage setBasicPropertiesToHeaders(SpringAMQPMessage msg, Message amqpMessage) { msg.getHeaders().put(MESSAGE_ID, amqpMessage.getMessageProperties().getMessageId()); byte[] correlationId = amqpMessage.getMessageProperties().getCorrelationId(); msg.getHeaders().put(CORRELATION_ID, correlationId == null ? null : new String(correlationId)); msg.getHeaders().put(CONTENT_ENCODING, amqpMessage.getMessageProperties().getContentEncoding()); msg.getHeaders().put(CONTENT_TYPE, amqpMessage.getMessageProperties().getContentType()); msg.getHeaders().put(EXPIRATION, amqpMessage.getMessageProperties().getExpiration()); msg.getHeaders().put(PRIORITY, amqpMessage.getMessageProperties().getPriority()); msg.getHeaders().put(REPLY_TO, amqpMessage.getMessageProperties().getReplyTo()); msg.getHeaders().put(DELIVERY_MODE, MessageDeliveryMode.toInt(amqpMessage.getMessageProperties().getDeliveryMode())); msg.getHeaders().put(TYPE, amqpMessage.getMessageProperties().getType()); return msg; }
public static SpringAMQPMessage setBasicPropertiesToHeaders(SpringAMQPMessage msg, Message amqpMessage) { msg.getHeaders().put(MESSAGE_ID, amqpMessage.getMessageProperties().getMessageId()); byte[] correlationId = amqpMessage.getMessageProperties().getCorrelationId(); msg.getHeaders().put(CORRELATION_ID, correlationId == null ? null : new String(correlationId)); msg.getHeaders().put(CONTENT_ENCODING, amqpMessage.getMessageProperties().getContentEncoding()); msg.getHeaders().put(CONTENT_TYPE, amqpMessage.getMessageProperties().getContentType()); msg.getHeaders().put(EXPIRATION, amqpMessage.getMessageProperties().getExpiration()); msg.getHeaders().put(PRIORITY, amqpMessage.getMessageProperties().getPriority()); msg.getHeaders().put(REPLY_TO, amqpMessage.getMessageProperties().getReplyTo()); msg.getHeaders().put(DELIVERY_MODE, MessageDeliveryMode.toInt(amqpMessage.getMessageProperties().getDeliveryMode())); msg.getHeaders().put(TYPE, amqpMessage.getMessageProperties().getType()); return msg; }
/** * Post-process the given response message before it will be sent. * <p> * The default implementation sets the response's correlation id to the request message's correlation id, if any; * otherwise to the request message id. * @param request the original incoming Rabbit message * @param response the outgoing Rabbit message about to be sent */ protected void postProcessResponse(Message request, Message response) { String correlation = request.getMessageProperties().getCorrelationId(); if (correlation == null) { String messageId = request.getMessageProperties().getMessageId(); if (messageId != null) { correlation = messageId; } } response.getMessageProperties().setCorrelationId(correlation); }
/** * Post-process the given response message before it will be sent. * <p> * The default implementation sets the response's correlation id to the request message's correlation id, if any; * otherwise to the request message id. * @param request the original incoming Rabbit message * @param response the outgoing Rabbit message about to be sent */ protected void postProcessResponse(Message request, Message response) { String correlation = request.getMessageProperties().getCorrelationId(); if (correlation == null) { String messageId = request.getMessageProperties().getMessageId(); if (messageId != null) { correlation = messageId; } } response.getMessageProperties().setCorrelationId(correlation); }
private void send(Object object, Address replyToAddress, Message requestMessage) { Message message = this.messageConverter.toMessage(object, new MessageProperties()); message.getMessageProperties().setCorrelationId(requestMessage.getMessageProperties().getCorrelationId()); getAmqpTemplate().send(replyToAddress.getExchangeName(), replyToAddress.getRoutingKey(), message); }
@Test public void testMessageCustomCorrelation() throws Exception { Message message = getFooMessage(); message.getMessageProperties().setCorrelationId("foo"); ListenableFuture<Message> future = this.asyncTemplate.sendAndReceive(message); Message result = checkMessageResult(future, "FOO"); assertEquals("foo", result.getMessageProperties().getCorrelationId()); }