public MessageBuilderSupport<T> setReplyToAddressIfAbsent(Address replyTo) { if (this.properties.getReplyToAddress() == null) { this.properties.setReplyToAddress(replyTo); } return this; }
/** * Determine a reply-to Address for the given message. * <p> * The default implementation first checks the Rabbit Reply-To Address of the supplied request; if that is not * <code>null</code> it is returned; if it is <code>null</code>, then the configured default Exchange and * routing key are used to construct a reply-to Address. If the exchange property is also <code>null</code>, * then an {@link AmqpException} is thrown. * @param request the original incoming Rabbit message * @return the reply-to Address (never <code>null</code>) * @throws AmqpException if no {@link Address} can be determined * @see org.springframework.amqp.core.Message#getMessageProperties() * @see org.springframework.amqp.core.MessageProperties#getReplyTo() */ private Address getReplyToAddress(Message request) throws AmqpException { Address replyTo = request.getMessageProperties().getReplyToAddress(); if (replyTo == null) { if (this.exchange == null) { throw new AmqpException( "Cannot determine ReplyTo message property value: " + "Request message does not contain reply-to property, and no default Exchange was set."); } replyTo = new Address(this.exchange, this.routingKey); } return replyTo; }
/** * Determine a reply-to Address for the given message. * <p> * The default implementation first checks the Rabbit Reply-To Address of the supplied request; if that is not * <code>null</code> it is returned; if it is <code>null</code>, then the configured default Exchange and * routing key are used to construct a reply-to Address. If the exchange property is also <code>null</code>, * then an {@link AmqpException} is thrown. * @param request the original incoming Rabbit message * @return the reply-to Address (never <code>null</code>) * @throws AmqpException if no {@link Address} can be determined * @see org.springframework.amqp.core.Message#getMessageProperties() * @see org.springframework.amqp.core.MessageProperties#getReplyTo() */ private Address getReplyToAddress(Message request) throws AmqpException { Address replyTo = request.getMessageProperties().getReplyToAddress(); if (replyTo == null) { if (this.exchange == null) { throw new AmqpException( "Cannot determine ReplyTo message property value: " + "Request message does not contain reply-to property, and no default Exchange was set."); } replyTo = new Address(this.exchange, this.routingKey); } return replyTo; }
@Override public void onMessage(Message message) { Address replyToAddress = message.getMessageProperties().getReplyToAddress(); if (replyToAddress == null) { throw new AmqpRejectAndDontRequeueException("No replyToAddress in inbound AMQP Message"); } Object invocationRaw = this.messageConverter.fromMessage(message); RemoteInvocationResult remoteInvocationResult; if (!(invocationRaw instanceof RemoteInvocation)) { remoteInvocationResult = new RemoteInvocationResult( new IllegalArgumentException("The message does not contain a RemoteInvocation payload")); } else { RemoteInvocation invocation = (RemoteInvocation) invocationRaw; remoteInvocationResult = invokeAndCreateResult(invocation, getService()); } send(remoteInvocationResult, replyToAddress, message); }
@Test public void testReplyTo() throws Exception { MessageProperties properties = new MessageProperties(); properties.setReplyTo("foo/bar"); assertEquals("bar", properties.getReplyToAddress().getRoutingKey()); }
@Test public void testReplyToNullByDefault() throws Exception { MessageProperties properties = new MessageProperties(); assertEquals(null, properties.getReplyTo()); assertEquals(null, properties.getReplyToAddress()); }
@Test public void testDirectReplyTo() { String replyTo = Address.AMQ_RABBITMQ_REPLY_TO + ".ab/cd/ef"; MessageProperties props = new MessageProperties(); props.setReplyTo(replyTo); Message message = new Message("foo".getBytes(), props); Address address = message.getMessageProperties().getReplyToAddress(); assertEquals("", address.getExchangeName()); assertEquals(replyTo, address.getRoutingKey()); address = props.getReplyToAddress(); assertEquals("", address.getExchangeName()); assertEquals(replyTo, address.getRoutingKey()); }
Address replyTo = request.getMessageProperties().getReplyToAddress(); if (replyTo == null) { if (this.responseAddress == null && this.responseExchange != null) {
Address replyTo = request.getMessageProperties().getReplyToAddress(); if (replyTo == null) { if (this.responseAddress == null && this.responseExchange != null) {
Address replyToAddress = amqpMessage.getMessageProperties().getReplyToAddress(); if(replyToAddress != null && endpoint.isAutoReply()) { org.apache.camel.Message outMessage = exchange.getOut();
Address replyToAddress = amqpMessage.getMessageProperties().getReplyToAddress(); if(replyToAddress != null && endpoint.isAutoReply()) { org.apache.camel.Message outMessage = exchange.getOut();
assertNotSame(bytes, message1.getBody()); assertTrue(Arrays.equals(bytes, message1.getBody())); assertEquals(replyTo.toString(), message1.getMessageProperties().getReplyToAddress().toString()); assertEquals(message1.getMessageProperties(), MessageBuilder.fromMessage(message2) .setReplyToAddress(replyTo).build().getMessageProperties()); assertEquals(foo.toString(), message2.getMessageProperties().getReplyToAddress().toString()); assertEquals(replyTo.toString(), message3.getMessageProperties().getReplyToAddress().toString()); .setReplyToAddressIfAbsent(foo) .build(); assertEquals(foo.toString(), message4.getMessageProperties().getReplyToAddress().toString());