use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.
the class PropertyConverter_Internal_to_v0_10Test method testReplyToConversionWhenExchangeIsSpecified.
@Test
public void testReplyToConversionWhenExchangeIsSpecified() throws IOException {
final AMQMessageHeader header = mock(AMQMessageHeader.class);
final String replyTo = "myTestExchange";
final Exchange exchange = mock(Exchange.class);
when(exchange.getName()).thenReturn(replyTo);
doReturn(exchange).when(_addressSpace).getAttainedMessageDestination(eq(replyTo), anyBoolean());
when(header.getReplyTo()).thenReturn(replyTo);
InternalMessage originalMessage = createTestMessage(header);
MessageTransferMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
final ReplyTo convertedReplyTo = convertedMessage.getHeader().getMessageProperties().getReplyTo();
assertEquals("Unexpected exchange", replyTo, convertedReplyTo.getExchange());
assertEquals("Unexpected routing key", "", convertedReplyTo.getRoutingKey());
}
use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.
the class PropertyConverter_Internal_to_v0_10Test method testReplyToConversionWhenExchangeAndRoutingKeyAreSpecified.
@Test
public void testReplyToConversionWhenExchangeAndRoutingKeyAreSpecified() throws IOException {
final AMQMessageHeader header = mock(AMQMessageHeader.class);
final String exchangeName = "testExchnageName";
final String routingKey = "testRoutingKey";
final String replyTo = String.format("%s/%s", exchangeName, routingKey);
final Exchange exchange = mock(Exchange.class);
when(exchange.getName()).thenReturn(exchangeName);
doReturn(exchange).when(_addressSpace).getAttainedMessageDestination(eq(exchangeName), anyBoolean());
when(header.getReplyTo()).thenReturn(replyTo);
InternalMessage originalMessage = createTestMessage(header);
MessageTransferMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
final ReplyTo convertedReplyTo = convertedMessage.getHeader().getMessageProperties().getReplyTo();
assertEquals("Unexpected exchange", exchangeName, convertedReplyTo.getExchange());
assertEquals("Unexpected routing key", routingKey, convertedReplyTo.getRoutingKey());
}
use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.
the class TopicExchangeTest method testRouteToQueueViaTwoExchanges.
@Test
public void testRouteToQueueViaTwoExchanges() {
String bindingKey = "key";
Map<String, Object> attributes = new HashMap<>();
attributes.put(Exchange.NAME, getTestName());
attributes.put(Exchange.TYPE, ExchangeDefaults.FANOUT_EXCHANGE_CLASS);
Exchange via = _vhost.createChild(Exchange.class, attributes);
Queue<?> queue = _vhost.createChild(Queue.class, Collections.singletonMap(Queue.NAME, getTestName() + "_queue"));
boolean exchToViaBind = _exchange.bind(via.getName(), bindingKey, Collections.emptyMap(), false);
assertTrue("Exchange to exchange bind operation should be successful", exchToViaBind);
boolean viaToQueueBind = via.bind(queue.getName(), bindingKey, Collections.emptyMap(), false);
assertTrue("Exchange to queue bind operation should be successful", viaToQueueBind);
RoutingResult<ServerMessage<?>> result = _exchange.route(_messageWithNoHeaders, bindingKey, _instanceProperties);
assertTrue("Message unexpectedly not routed to queue", result.hasRoutes());
}
use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.
the class MessageConverter_Internal_to_v0_8 method createMessagePublishInfo.
private MessagePublishInfo createMessagePublishInfo(final InternalMessage serverMsg, final NamedAddressSpace addressSpace) {
String to = serverMsg.getTo();
final String exchangeName;
final String routingKey;
if (to == null || "".equals(to)) {
to = serverMsg.getInitialRoutingAddress();
}
if (to != null && !"".equals(to)) {
DestinationAddress destinationAddress = new DestinationAddress(addressSpace, to);
MessageDestination messageDestination = destinationAddress.getMessageDestination();
if (messageDestination instanceof Queue) {
exchangeName = "";
routingKey = messageDestination.getName();
} else if (messageDestination instanceof Exchange) {
exchangeName = messageDestination.getName();
routingKey = destinationAddress.getRoutingKey();
} else {
exchangeName = "";
routingKey = to;
}
} else {
exchangeName = "";
routingKey = "";
}
return new MessagePublishInfo(convertToShortStringForProperty("to", exchangeName), false, false, convertToShortStringForProperty("to' or 'subject", routingKey));
}
use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.
the class PropertyConverter_1_0_to_0_8Test method testToConversionWhenExchangeIsSpecifiedAndSubjectIsSet.
@Test
public void testToConversionWhenExchangeIsSpecifiedAndSubjectIsSet() {
final String testExchange = "testExchange";
final String testRoutingKey = "testRoutingKey";
Properties properties = new Properties();
properties.setTo(testExchange);
properties.setSubject(testRoutingKey);
Message_1_0 message = createTestMessage(properties);
final Exchange exchange = mock(Exchange.class);
when(exchange.getName()).thenReturn(testExchange);
doReturn(exchange).when(_namedAddressSpace).getAttainedMessageDestination(eq(testExchange), anyBoolean());
final AMQMessage convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
final MessagePublishInfo messagePublishInfo = convertedMessage.getMessagePublishInfo();
assertEquals("Unexpected exchange", testExchange, messagePublishInfo.getExchange().toString());
assertEquals("Unexpected routing key", testRoutingKey, messagePublishInfo.getRoutingKey().toString());
}
Aggregations