headers.put(AmqpHeaders.REDELIVERED, redelivered); String replyTo = amqpMessageProperties.getReplyTo(); if (replyTo != null) { headers.put(AmqpHeaders.REPLY_TO, replyTo);
@Test public void testReplyToNullByDefault() throws Exception { MessageProperties properties = new MessageProperties(); assertEquals(null, properties.getReplyTo()); assertEquals(null, properties.getReplyToAddress()); }
if (reply != null) { Address replyTo; String replyToProperty = message.getMessageProperties().getReplyTo(); if (replyToProperty != null) { replyTo = new Address(replyToProperty);
assertEquals("test.receivedExchange", amqpProperties.getReceivedExchange()); assertEquals("test.receivedRoutingKey", amqpProperties.getReceivedRoutingKey()); assertEquals("test.replyTo", amqpProperties.getReplyTo()); assertEquals(testTimestamp, amqpProperties.getTimestamp()); assertEquals("test.type", amqpProperties.getType());
public MessageBuilderSupport<T> setReplyToIfAbsent(String replyTo) { if (this.properties.getReplyTo() == null) { this.properties.setReplyTo(replyTo); } return this; }
public MessageBuilderSupport<T> copyProperties(MessageProperties properties) { BeanUtils.copyProperties(properties, this.properties); // Special handling of replyTo needed because the format depends on how it was set this.properties.setReplyTo(properties.getReplyTo()); this.properties.getHeaders().putAll(properties.getHeaders()); return this; }
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; }
@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); } }
@SuppressWarnings("unused") public Message handleMessage(Message message) { replyToWas.set(message.getMessageProperties().getReplyTo()); return new Message(new String(message.getBody()).toUpperCase().getBytes(), message.getMessageProperties()); } });
/** * Method to create a new target or to find the target if it already exists. * * @param targetID * the ID of the target/thing * @param ip * the ip of the target/thing */ private void registerTarget(final Message message, final String virtualHost) { final String thingId = getStringHeaderKey(message, MessageHeaderKey.THING_ID, "ThingId is null"); final String replyTo = message.getMessageProperties().getReplyTo(); if (StringUtils.isEmpty(replyTo)) { logAndThrowMessageError(message, "No ReplyTo was set for the createThing message."); } final URI amqpUri = IpUtil.createAmqpUri(virtualHost, replyTo); final Target target = controllerManagement.findOrRegisterTargetIfItDoesNotexist(thingId, amqpUri); LOG.debug("Target {} reported online state.", thingId); lookIfUpdateAvailable(target); }
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; }
@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)); } }
private void saveAndSetProperties(final Message message, final PendingReply pendingReply, String messageTag) { String savedReplyTo = message.getMessageProperties().getReplyTo(); pendingReply.setSavedReplyTo(savedReplyTo); if (StringUtils.hasLength(savedReplyTo) && logger.isDebugEnabled()) {
/** * {@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; } }
/** * {@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; } }
@Test public void testAtomicSendAndReceiveWithConversionUsingRoutingKey() throws Exception { ExecutorService executor = Executors.newFixedThreadPool(1); // Set up a consumer to respond to our producer Future<String> received = executor.submit(() -> { Message message = null; for (int i = 0; i < 10; i++) { message = template.receive(ROUTE); if (message != null) { break; } Thread.sleep(100L); } assertNotNull("No message received", message); template.send(message.getMessageProperties().getReplyTo(), message); return (String) template.getMessageConverter().fromMessage(message); }); RabbitTemplate template = createSendAndReceiveRabbitTemplate(this.connectionFactory); String result = (String) template.convertSendAndReceive(ROUTE, "message"); assertEquals("message", received.get(1000, TimeUnit.MILLISECONDS)); assertEquals("message", result); // Message was consumed so nothing left on queue result = (String) template.receiveAndConvert(ROUTE); assertEquals(null, result); template.stop(); }
@Test public void buildMessageWithStandardMessage() throws Exception { Message<String> result = MessageBuilder.withPayload("Response") .setHeader("foo", "bar") .setHeader(AmqpHeaders.TYPE, "msg_type") .setHeader(AmqpHeaders.REPLY_TO, "reply") .build(); Channel session = mock(Channel.class); MessagingMessageListenerAdapter listener = getSimpleInstance("echo", Message.class); org.springframework.amqp.core.Message replyMessage = listener.buildMessage(session, result, null); assertNotNull("reply should never be null", replyMessage); assertEquals("Response", new String(replyMessage.getBody())); assertEquals("type header not copied", "msg_type", replyMessage.getMessageProperties().getType()); assertEquals("replyTo header not copied", "reply", replyMessage.getMessageProperties().getReplyTo()); assertEquals("custom header not copied", "bar", replyMessage.getMessageProperties().getHeaders().get("foo")); }