Search in sources :

Example 31 with Exchange

use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.

the class DirectExchangeTest method testRouteToQueueViaTwoExchanges.

@Test
public void testRouteToQueueViaTwoExchanges() {
    String boundKey = "key";
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(Exchange.NAME, getTestName());
    attributes.put(Exchange.TYPE, ExchangeDefaults.DIRECT_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(), boundKey, Collections.emptyMap(), false);
    assertTrue("Exchange to exchange bind operation should be successful", exchToViaBind);
    boolean viaToQueueBind = via.bind(queue.getName(), boundKey, Collections.emptyMap(), false);
    assertTrue("Exchange to queue bind operation should be successful", viaToQueueBind);
    RoutingResult<ServerMessage<?>> result = _exchange.route(_messageWithNoHeaders, boundKey, _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 32 with Exchange

use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.

the class FanoutExchangeTest method testRouteToQueueViaTwoExchangesWithReplacementRoutingKey.

@Test
public void testRouteToQueueViaTwoExchangesWithReplacementRoutingKey() {
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(Exchange.NAME, getTestName());
    attributes.put(Exchange.TYPE, ExchangeDefaults.DIRECT_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(), "key", Collections.singletonMap(Binding.BINDING_ARGUMENT_REPLACEMENT_ROUTING_KEY, "key1"), false);
    assertTrue("Exchange to exchange bind operation should be successful", exchToViaBind);
    boolean viaToQueueBind = via.bind(queue.getName(), "key1", Collections.emptyMap(), false);
    assertTrue("Exchange to queue bind operation should be successful", viaToQueueBind);
    RoutingResult<ServerMessage<?>> result = _exchange.route(_messageWithNoHeaders, null, _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 33 with Exchange

use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.

the class HeadersExchangeTest method testRouteToQueueViaTwoExchangesWithReplacementRoutingKey.

@Test
public void testRouteToQueueViaTwoExchangesWithReplacementRoutingKey() {
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(Exchange.NAME, getTestName());
    attributes.put(Exchange.TYPE, ExchangeDefaults.DIRECT_EXCHANGE_CLASS);
    Exchange via = _virtualHost.createChild(Exchange.class, attributes);
    Queue<?> queue = _virtualHost.createChild(Queue.class, Collections.singletonMap(Queue.NAME, getTestName() + "_queue"));
    String bindingKey = "key";
    String replacementKey = "key1";
    boolean exchToViaBind = _exchange.bind(via.getName(), bindingKey, Collections.singletonMap(Binding.BINDING_ARGUMENT_REPLACEMENT_ROUTING_KEY, replacementKey), false);
    assertTrue("Exchange to exchange bind operation should be successful", exchToViaBind);
    Map<String, Object> arguments = getArgsMapFromStrings("prop=true", "prop2=true", "X-match=any");
    boolean viaToQueueBind = via.bind(queue.getName(), replacementKey, arguments, false);
    assertTrue("Exchange to queue bind operation should be successful", viaToQueueBind);
    ServerMessage<?> testMessage = createTestMessage(Collections.singletonMap("prop", true));
    RoutingResult<ServerMessage<?>> result = _exchange.route(testMessage, 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 34 with Exchange

use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.

the class HeadersExchangeTest 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 = _virtualHost.createChild(Exchange.class, attributes);
    Queue<?> queue = _virtualHost.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 35 with Exchange

use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.

the class TopicExchangeTest method testHierachicalRouteToQueueViaTwoExchangesWithReplacementRoutingKey.

@Test
public void testHierachicalRouteToQueueViaTwoExchangesWithReplacementRoutingKey() {
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(Exchange.NAME, getTestName());
    attributes.put(Exchange.TYPE, ExchangeDefaults.DIRECT_EXCHANGE_CLASS);
    Exchange via = _vhost.createChild(Exchange.class, attributes);
    Queue<?> queue1 = _vhost.createChild(Queue.class, Collections.singletonMap(Queue.NAME, getTestName() + "_queue1"));
    Queue<?> queue2 = _vhost.createChild(Queue.class, Collections.singletonMap(Queue.NAME, getTestName() + "_queue2"));
    String bindingKey1 = "a.#";
    String bindingKey2 = "a.*";
    String replacementKey1 = "key1";
    String replacementKey2 = "key2";
    assertTrue("Exchange to exchange bind operation should be successful", _exchange.bind(via.getName(), bindingKey1, Collections.singletonMap(Binding.BINDING_ARGUMENT_REPLACEMENT_ROUTING_KEY, replacementKey1), false));
    assertTrue("Exchange to exchange bind operation should be successful", _exchange.bind(via.getName(), bindingKey2, Collections.singletonMap(Binding.BINDING_ARGUMENT_REPLACEMENT_ROUTING_KEY, replacementKey2), false));
    assertTrue("Exchange to queue1 bind operation should be successful", via.bind(queue1.getName(), replacementKey1, Collections.emptyMap(), false));
    assertTrue("Exchange to queue2 bind operation should be successful", via.bind(queue2.getName(), replacementKey2, Collections.emptyMap(), false));
    RoutingResult<ServerMessage<?>> result = _exchange.route(_messageWithNoHeaders, "a.b", _instanceProperties);
    assertEquals("Unexpected number of routes", (long) 2, (long) result.getNumberOfRoutes());
    result = _exchange.route(_messageWithNoHeaders, "a.b.c", _instanceProperties);
    assertEquals("Unexpected number of routes", (long) 1, (long) result.getNumberOfRoutes());
    assertTrue("Message is not routed into 'queue1'", result.getRoutes().contains(queue1));
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) HashMap(java.util.HashMap) ServerMessage(org.apache.qpid.server.message.ServerMessage) 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