AmqpInboundGateway.this.amqpTemplate.convertAndSend(replyTo.getExchangeName(), replyTo.getRoutingKey(), reply.getPayload(), messagePostProcessor);
@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); }
/** * 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; }
/** * 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; }
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()); }
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()); }
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); }
AmqpInboundGateway.this.amqpTemplate.convertAndSend(replyTo.getExchangeName(), replyTo.getRoutingKey(), reply.getPayload(), messagePostProcessor);
assertThat(new String(replyMessage.get().getBody()), equalTo("processedfoo")); assertThat(replyAddress.get(), notNullValue()); assertThat(replyAddress.get().getExchangeName(), equalTo("foo")); assertThat(replyAddress.get().getRoutingKey(), equalTo("bar")); assertThat(throwable.get(), sameInstance(ex));
@Test public void parse() { String replyToUri = "direct://my-exchange/routing-key"; Address address = new Address(replyToUri); assertEquals("my-exchange", address.getExchangeName()); assertEquals("routing-key", address.getRoutingKey()); }
@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()); }
private <S> void doSendReply(final ReplyToAddressCallback<S> replyToAddressCallback, Channel channel, Message receiveMessage, S reply) throws Exception { // NOSONAR TODO: change to IOException in 2.2. Address replyTo = replyToAddressCallback.getReplyToAddress(receiveMessage, reply); Message replyMessage = convertMessageIfNecessary(reply); MessageProperties receiveMessageProperties = receiveMessage.getMessageProperties(); MessageProperties replyMessageProperties = replyMessage.getMessageProperties(); Object correlation = this.correlationKey == null ? receiveMessageProperties.getCorrelationId() : receiveMessageProperties.getHeaders().get(this.correlationKey); if (this.correlationKey == null || correlation == null) { // using standard correlationId property if (correlation == null) { String messageId = receiveMessageProperties.getMessageId(); if (messageId != null) { correlation = messageId; } } replyMessageProperties.setCorrelationId((String) correlation); } else { replyMessageProperties.setHeader(this.correlationKey, correlation); } // 'doSend()' takes care of 'channel.txCommit()'. doSend(channel, replyTo.getExchangeName(), replyTo.getRoutingKey(), replyMessage, RabbitTemplate.this.returnCallback != null && isMandatoryFor(replyMessage), null); }
private <S> void doSendReply(final ReplyToAddressCallback<S> replyToAddressCallback, Channel channel, Message receiveMessage, S reply) throws Exception { // NOSONAR TODO: change to IOException in 2.2. Address replyTo = replyToAddressCallback.getReplyToAddress(receiveMessage, reply); Message replyMessage = convertMessageIfNecessary(reply); MessageProperties receiveMessageProperties = receiveMessage.getMessageProperties(); MessageProperties replyMessageProperties = replyMessage.getMessageProperties(); Object correlation = this.correlationKey == null ? receiveMessageProperties.getCorrelationId() : receiveMessageProperties.getHeaders().get(this.correlationKey); if (this.correlationKey == null || correlation == null) { // using standard correlationId property if (correlation == null) { String messageId = receiveMessageProperties.getMessageId(); if (messageId != null) { correlation = messageId; } } replyMessageProperties.setCorrelationId((String) correlation); } else { replyMessageProperties.setHeader(this.correlationKey, correlation); } // 'doSend()' takes care of 'channel.txCommit()'. doSend(channel, replyTo.getExchangeName(), replyTo.getRoutingKey(), replyMessage, RabbitTemplate.this.returnCallback != null && isMandatoryFor(replyMessage), null); }
this.logger.debug("Publishing response to exchange = [" + replyTo.getExchangeName() + "], routingKey = [" + replyTo.getRoutingKey() + "]"); if (this.retryTemplate == null) {
this.logger.debug("Publishing response to exchange = [" + replyTo.getExchangeName() + "], routingKey = [" + replyTo.getRoutingKey() + "]"); if (this.retryTemplate == null) {
@Test public void parseWithoutRoutingKey() { Address address = new Address("fanout://my-exchange"); assertEquals("my-exchange", address.getExchangeName()); assertEquals("", address.getRoutingKey()); assertEquals("my-exchange/", address.toString()); }
@Test public void testEmpty() { Address address = new Address("/"); assertEquals("", address.getExchangeName()); assertEquals("", address.getRoutingKey()); assertEquals("/", address.toString()); }
@Test public void parseWithDefaultExchangeAndRoutingKey() { Address address = new Address("direct:///routing-key"); assertEquals("", address.getExchangeName()); assertEquals("routing-key", address.getRoutingKey()); assertEquals("/routing-key", address.toString()); }
endpoint.getAmqpTemplate().send(replyToAddress.getExchangeName(), replyToAddress.getRoutingKey(), replyMessage.toAMQPMessage(msgConverter)); } catch(AmqpConnectException e) { LOG.error("AMQP Connection error, marking this connection as failed");
@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()); }