String replyToProperty = message.getMessageProperties().getReplyTo(); if (replyToProperty != null) { replyTo = new Address(replyToProperty); AmqpInboundGateway.this.amqpTemplate.convertAndSend(replyTo.getExchangeName(), replyTo.getRoutingKey(), reply.getPayload(), messagePostProcessor);
public void setReplyToAddress(Address replyTo) { this.replyTo = (replyTo != null) ? replyTo.toString() : null; }
protected void doPublish(Channel channel, Address replyTo, Message message) throws IOException { channel.basicPublish(replyTo.getExchangeName(), replyTo.getRoutingKey(), this.mandatoryPublish, this.messagePropertiesConverter.fromMessageProperties(message.getMessageProperties(), this.encoding), message.getBody()); }
@Test public void parseUnstructuredWithRoutingKeyOnly() { Address address = new Address("my-routing-key"); assertEquals("my-routing-key", address.getRoutingKey()); assertEquals("/my-routing-key", address.toString()); address = new Address("/foo"); assertEquals("foo", address.getRoutingKey()); assertEquals("/foo", address.toString()); address = new Address("bar/baz"); assertEquals("bar", address.getExchangeName()); assertEquals("baz", address.getRoutingKey()); assertEquals("bar/baz", address.toString()); }
/** * The {@code defaultReplyTo} address with the form * <pre class="code"> * (exchange)/(routingKey) * </pre> * or * <pre class="code"> * (queueName) * </pre> * if the request message doesn't have a {@code replyTo} property. * The second form uses the default exchange ("") and the queue name as * the routing key. * @param defaultReplyTo the default {@code replyTo} address to use. * @since 4.2 * @see Address */ public void setDefaultReplyTo(String defaultReplyTo) { this.defaultReplyTo = new Address(defaultReplyTo); }
@Test public void testReplyTo() throws Exception { MessageProperties properties = new MessageProperties(); properties.setReplyTo("foo/bar"); assertEquals("bar", properties.getReplyToAddress().getRoutingKey()); }
protected void doPublish(Channel channel, Address replyTo, Message message) throws IOException { channel.basicPublish(replyTo.getExchangeName(), replyTo.getRoutingKey(), this.mandatoryPublish, this.messagePropertiesConverter.fromMessageProperties(message.getMessageProperties(), this.encoding), message.getBody()); }
@Test public void testEmpty() { Address address = new Address("/"); assertEquals("", address.getExchangeName()); assertEquals("", address.getRoutingKey()); assertEquals("/", address.toString()); }
public Address getReplyToAddress() { return (this.replyTo != null) ? new Address(this.replyTo) : null; }
byte[] bytes = "foo".getBytes(); MessageProperties properties = new MessageProperties(); Address replyTo = new Address("address"); Message message1 = MessageBuilder.withClonedBody(bytes) .andProperties(this.setAll(MessagePropertiesBuilder.fromClonedProperties(properties)) .setReplyToAddress(replyTo) .setReplyToAddressIfAbsent(new Address("addressxxxx")) .build()) .build(); assertNotSame(bytes, message1.getBody()); assertTrue(Arrays.equals(bytes, message1.getBody())); assertEquals(replyTo.toString(), message1.getMessageProperties().getReplyToAddress().toString()); Address foo = new Address("foo"); Message message2 = MessageBuilder.fromClonedMessage(message1) .setReplyToAddress(foo) 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());
@Test public void verifyLifeCycle() { Object gateway = context.getBean("autoStartFalseGateway"); assertEquals(Boolean.FALSE, TestUtils.getPropertyValue(gateway, "autoStartup")); assertEquals(123, TestUtils.getPropertyValue(gateway, "phase")); assertFalse(TestUtils.getPropertyValue(gateway, "messageListenerContainer.missingQueuesFatal", Boolean.class)); Object amqpTemplate = context.getBean("amqpTemplate"); assertSame(amqpTemplate, TestUtils.getPropertyValue(gateway, "amqpTemplate")); Address defaultReplyTo = TestUtils.getPropertyValue(gateway, "defaultReplyTo", Address.class); Address expected = new Address("fooExchange/barRoutingKey"); assertEquals(expected.getExchangeName(), defaultReplyTo.getExchangeName()); assertEquals(expected.getRoutingKey(), defaultReplyTo.getRoutingKey()); assertEquals(expected, defaultReplyTo); }
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 parseWithoutRoutingKey() { Address address = new Address("fanout://my-exchange"); assertEquals("my-exchange", address.getExchangeName()); assertEquals("", address.getRoutingKey()); assertEquals("my-exchange/", address.toString()); }
/** * The {@code defaultReplyTo} address with the form * <pre class="code"> * (exchange)/(routingKey) * </pre> * or * <pre class="code"> * (queueName) * </pre> * if the request message doesn't have a {@code replyTo} property. * The second form uses the default exchange ("") and the queue name as * the routing key. * @param defaultReplyTo the default {@code replyTo} address to use. * @since 4.2 * @see Address */ public void setDefaultReplyTo(String defaultReplyTo) { this.defaultReplyTo = new Address(defaultReplyTo); }
/** * Invoked by the container during startup so it can verify the queue is correctly * configured (if a simple reply queue name is used instead of exchange/routingKey). * @return the queue name, if configured. * @since 1.5 */ @Override @Nullable public Collection<String> expectedQueueNames() { this.isListener = true; Collection<String> replyQueue = null; if (this.replyAddress == null || this.replyAddress.equals(Address.AMQ_RABBITMQ_REPLY_TO)) { throw new IllegalStateException("A listener container must not be provided when using direct reply-to"); } else { Address address = new Address(this.replyAddress); if ("".equals(address.getExchangeName())) { replyQueue = Collections.singletonList(address.getRoutingKey()); } else { if (logger.isInfoEnabled()) { logger.info("Cannot verify reply queue because 'replyAddress' is not a simple queue name: " + this.replyAddress); } } } return replyQueue; }
@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()); }
@Test public void parseWithDefaultExchangeAndRoutingKey() { Address address = new Address("direct:///routing-key"); assertEquals("", address.getExchangeName()); assertEquals("routing-key", address.getRoutingKey()); assertEquals("/routing-key", address.toString()); }
@Override public <R, S> boolean receiveAndReply(final String queueName, ReceiveAndReplyCallback<R, S> callback, final String replyExchange, final String replyRoutingKey) throws AmqpException { return receiveAndReply(queueName, callback, (request, reply) -> new Address(replyExchange, replyRoutingKey)); }
/** * Invoked by the container during startup so it can verify the queue is correctly * configured (if a simple reply queue name is used instead of exchange/routingKey). * @return the queue name, if configured. * @since 1.5 */ @Override @Nullable public Collection<String> expectedQueueNames() { this.isListener = true; Collection<String> replyQueue = null; if (this.replyAddress == null || this.replyAddress.equals(Address.AMQ_RABBITMQ_REPLY_TO)) { throw new IllegalStateException("A listener container must not be provided when using direct reply-to"); } else { Address address = new Address(this.replyAddress); if ("".equals(address.getExchangeName())) { replyQueue = Collections.singletonList(address.getRoutingKey()); } else { if (logger.isInfoEnabled()) { logger.info("Cannot verify reply queue because 'replyAddress' is not a simple queue name: " + this.replyAddress); } } } return replyQueue; }