Search in sources :

Example 66 with ServerMessage

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

the class TopicExchangeTest method testRouteToQueueViaTwoExchangesWithReplacementRoutingKeyAndFiltering.

public void testRouteToQueueViaTwoExchangesWithReplacementRoutingKeyAndFiltering() {
    String bindingKey = "key1";
    String replacementKey = "key2";
    Map<String, Object> viaExchangeArguments = new HashMap<>();
    viaExchangeArguments.put(Exchange.NAME, getTestName() + "_via_exch");
    viaExchangeArguments.put(Exchange.TYPE, ExchangeDefaults.TOPIC_EXCHANGE_CLASS);
    Exchange via = _vhost.createChild(Exchange.class, viaExchangeArguments);
    Queue<?> queue = _vhost.createChild(Queue.class, Collections.singletonMap(Queue.NAME, getTestName() + "_queue"));
    Map<String, Object> exchToViaBindArguments = new HashMap<>();
    exchToViaBindArguments.put(Binding.BINDING_ARGUMENT_REPLACEMENT_ROUTING_KEY, replacementKey);
    exchToViaBindArguments.put(JMS_SELECTOR.toString(), "prop = True");
    boolean exchToViaBind = _exchange.bind(via.getName(), bindingKey, exchToViaBindArguments, 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(createTestMessage(Collections.singletonMap("prop", true)), bindingKey, _instanceProperties);
    assertTrue("Message unexpectedly not routed to queue", result.hasRoutes());
    result = _exchange.route(createTestMessage(Collections.singletonMap("prop", false)), bindingKey, _instanceProperties);
    assertFalse("Message unexpectedly 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 67 with ServerMessage

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

the class TopicExchangeTest method testRouteToQueueWithSelector.

public void testRouteToQueueWithSelector() {
    String bindingKey = "mybinding";
    Queue<?> queue = _vhost.createChild(Queue.class, Collections.singletonMap(Queue.NAME, getTestName() + "_queue"));
    InstanceProperties instanceProperties = mock(InstanceProperties.class);
    ServerMessage<?> matchingMessage = createTestMessage(Collections.singletonMap("prop", true));
    ServerMessage<?> unmatchingMessage = createTestMessage(Collections.singletonMap("prop", false));
    boolean bind = _exchange.bind(queue.getName(), bindingKey, Collections.singletonMap(JMS_SELECTOR.toString(), "prop = True"), false);
    assertTrue("Bind operation should be successful", bind);
    RoutingResult<ServerMessage<?>> result = _exchange.route(matchingMessage, "mybinding", instanceProperties);
    assertTrue("Message with matching selector not routed to queue", result.hasRoutes());
    result = _exchange.route(unmatchingMessage, "mybinding", instanceProperties);
    assertFalse("Message without matching selector unexpectedly routed to queue", result.hasRoutes());
    boolean unbind = _exchange.unbind(queue.getName(), bindingKey);
    assertTrue("Unbind operation should be successful", unbind);
    result = _exchange.route(matchingMessage, "mybinding", instanceProperties);
    assertFalse("Message with matching selector unexpectedly routed to queue after unbind", result.hasRoutes());
}
Also used : InstanceProperties(org.apache.qpid.server.message.InstanceProperties) ServerMessage(org.apache.qpid.server.message.ServerMessage)

Example 68 with ServerMessage

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

the class TopicExchangeTest method testUpdateBindingChangeReplacementKey.

public void testUpdateBindingChangeReplacementKey() throws Exception {
    String bindingKey = "mybinding";
    String replacementKey = "key1";
    String replacementKey2 = "key2";
    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(), bindingKey, Collections.emptyMap(), 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);
    assertFalse("Message unexpectedly routed to queue", result.hasRoutes());
    _exchange.bind(via.getName(), bindingKey, Collections.singletonMap(Binding.BINDING_ARGUMENT_REPLACEMENT_ROUTING_KEY, replacementKey), true);
    result = _exchange.route(_messageWithNoHeaders, bindingKey, _instanceProperties);
    assertTrue("Message was not routed", result.hasRoutes());
    assertTrue("Message was not routed to queue", result.getRoutes().contains(queue));
    Queue<?> queue2 = _vhost.createChild(Queue.class, Collections.singletonMap(Queue.NAME, getTestName() + "_queue2"));
    assertTrue("Binding of queue2 failed", via.bind(queue2.getName(), replacementKey2, Collections.emptyMap(), false));
    _exchange.bind(via.getName(), bindingKey, Collections.singletonMap(Binding.BINDING_ARGUMENT_REPLACEMENT_ROUTING_KEY, replacementKey2), true);
    result = _exchange.route(_messageWithNoHeaders, bindingKey, _instanceProperties);
    assertTrue("Message was not routed", result.hasRoutes());
    assertTrue("Message was not routed to queue2", result.getRoutes().contains(queue2));
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) HashMap(java.util.HashMap) ServerMessage(org.apache.qpid.server.message.ServerMessage)

Example 69 with ServerMessage

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

the class TopicExchangeTest method testUpdateBindingAddingSelector.

public void testUpdateBindingAddingSelector() throws Exception {
    String bindingKey = "mybinding";
    Queue<?> queue = _vhost.createChild(Queue.class, Collections.singletonMap(Queue.NAME, getTestName() + "_queue"));
    InstanceProperties instanceProperties = mock(InstanceProperties.class);
    ServerMessage<?> message = createTestMessage(Collections.singletonMap("prop", false));
    boolean bind = _exchange.bind(queue.getName(), bindingKey, Collections.emptyMap(), false);
    assertTrue("Bind operation should be successful", bind);
    RoutingResult<ServerMessage<?>> result = _exchange.route(message, bindingKey, instanceProperties);
    assertTrue("Message not routed to queue", result.hasRoutes());
    _exchange.replaceBinding(bindingKey, queue, Collections.singletonMap(JMS_SELECTOR.toString(), "prop = false"));
    result = _exchange.route(message, bindingKey, instanceProperties);
    assertTrue("Message that matches selector not routed to queue after rebind", result.hasRoutes());
    result = _exchange.route(message = createTestMessage(Collections.singletonMap("prop", true)), bindingKey, instanceProperties);
    assertFalse("Message that does not match selector routed to queue after rebind", result.hasRoutes());
}
Also used : InstanceProperties(org.apache.qpid.server.message.InstanceProperties) ServerMessage(org.apache.qpid.server.message.ServerMessage)

Example 70 with ServerMessage

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

the class LocalTransactionTest method createTestQueueEntries.

private Collection<MessageInstance> createTestQueueEntries(boolean[] queueDurableFlags, boolean[] messagePersistentFlags) {
    Collection<MessageInstance> queueEntries = new ArrayList<MessageInstance>();
    assertTrue("Boolean arrays must be the same length", queueDurableFlags.length == messagePersistentFlags.length);
    for (int i = 0; i < queueDurableFlags.length; i++) {
        final TransactionLogResource queue = createQueue(queueDurableFlags[i]);
        final ServerMessage message = createTestMessage(messagePersistentFlags[i]);
        final boolean hasRecord = queueDurableFlags[i] && messagePersistentFlags[i];
        queueEntries.add(new MockMessageInstance() {

            @Override
            public ServerMessage getMessage() {
                return message;
            }

            @Override
            public TransactionLogResource getOwningResource() {
                return queue;
            }

            @Override
            public MessageEnqueueRecord getEnqueueRecord() {
                return hasRecord ? mock(MessageEnqueueRecord.class) : null;
            }
        });
    }
    return queueEntries;
}
Also used : MockMessageInstance(org.apache.qpid.server.queue.MockMessageInstance) MessageInstance(org.apache.qpid.server.message.MessageInstance) MockMessageInstance(org.apache.qpid.server.queue.MockMessageInstance) ArrayList(java.util.ArrayList) ServerMessage(org.apache.qpid.server.message.ServerMessage) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource)

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