Search in sources :

Example 6 with Exchange

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());
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) ReplyTo(org.apache.qpid.server.protocol.v0_10.transport.ReplyTo) InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 7 with Exchange

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());
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) ReplyTo(org.apache.qpid.server.protocol.v0_10.transport.ReplyTo) InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 8 with Exchange

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());
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) HashMap(java.util.HashMap) ServerMessage(org.apache.qpid.server.message.ServerMessage) Test(org.junit.Test)

Example 9 with Exchange

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));
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo) MessageDestination(org.apache.qpid.server.message.MessageDestination) Queue(org.apache.qpid.server.model.Queue) DestinationAddress(org.apache.qpid.server.model.DestinationAddress)

Example 10 with Exchange

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());
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties) AMQMessage(org.apache.qpid.server.protocol.v0_8.AMQMessage) Test(org.junit.Test)

Aggregations

Exchange (org.apache.qpid.server.model.Exchange)53 Test (org.junit.Test)29 HashMap (java.util.HashMap)24 ServerMessage (org.apache.qpid.server.message.ServerMessage)15 Queue (org.apache.qpid.server.model.Queue)15 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)14 MessageDestination (org.apache.qpid.server.message.MessageDestination)13 DestinationAddress (org.apache.qpid.server.model.DestinationAddress)8 ReplyTo (org.apache.qpid.server.protocol.v0_10.transport.ReplyTo)8 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)8 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)8 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)8 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)8 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)7 AccessControlException (java.security.AccessControlException)6 LinkedHashMap (java.util.LinkedHashMap)6 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)6 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)6 MessagePublishInfo (org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo)6 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)5