Search in sources :

Example 61 with ServerMessage

use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.

the class FanoutExchangeTest method testRouteToQueueViaTwoExchangesWithReplacementRoutingKey.

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)

Example 62 with ServerMessage

use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.

the class HeadersExchangeTest method testRouteToQueueViaTwoExchanges.

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)

Example 63 with ServerMessage

use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.

the class HeadersExchangeTest method testRouteToQueueViaTwoExchangesWithReplacementRoutingKey.

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)

Example 64 with ServerMessage

use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.

the class TopicExchangeTest method testHierachicalRouteToQueueViaTwoExchangesWithReplacementRoutingKey.

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", 2, result.getNumberOfRoutes());
    result = _exchange.route(_messageWithNoHeaders, "a.b.c", _instanceProperties);
    assertEquals("Unexpected number of routes", 1, 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)

Example 65 with ServerMessage

use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.

the class TopicExchangeTest method testRouteToQueueViaTwoExchangesWithReplacementRoutingKey.

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"));
    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);
    boolean viaToQueueBind = via.bind(queue.getName(), replacementKey, 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());
    result = _exchange.route(_messageWithNoHeaders, replacementKey, _instanceProperties);
    assertFalse("Message unexpectedly was 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)

Aggregations

ServerMessage (org.apache.qpid.server.message.ServerMessage)103 HashMap (java.util.HashMap)26 AMQMessageHeader (org.apache.qpid.server.message.AMQMessageHeader)16 TransactionLogResource (org.apache.qpid.server.store.TransactionLogResource)16 Exchange (org.apache.qpid.server.model.Exchange)14 MessageReference (org.apache.qpid.server.message.MessageReference)13 ArrayList (java.util.ArrayList)9 MessageInstance (org.apache.qpid.server.message.MessageInstance)8 InstanceProperties (org.apache.qpid.server.message.InstanceProperties)7 Queue (org.apache.qpid.server.model.Queue)7 StoredMessage (org.apache.qpid.server.store.StoredMessage)6 MessageEnqueueRecord (org.apache.qpid.server.store.MessageEnqueueRecord)4 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)3 TestConsumerTarget (org.apache.qpid.server.consumer.TestConsumerTarget)3 MessageDeletedException (org.apache.qpid.server.message.MessageDeletedException)3 PrivilegedAction (java.security.PrivilegedAction)2 UUID (java.util.UUID)2 MessageDestination (org.apache.qpid.server.message.MessageDestination)2 MessageInstanceConsumer (org.apache.qpid.server.message.MessageInstanceConsumer)2 RoutingResult (org.apache.qpid.server.message.RoutingResult)2