Search in sources :

Example 6 with ServerMessage

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

the class TopicExchangeTest 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 = _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)

Example 7 with ServerMessage

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

the class SynchronousMessageStoreRecoverer method recover.

@Override
public ListenableFuture<Void> recover(QueueManagingVirtualHost<?> virtualHost) {
    EventLogger eventLogger = virtualHost.getEventLogger();
    MessageStore store = virtualHost.getMessageStore();
    MessageStore.MessageStoreReader storeReader = store.newMessageStoreReader();
    MessageStoreLogSubject logSubject = new MessageStoreLogSubject(virtualHost.getName(), store.getClass().getSimpleName());
    Map<Queue<?>, Integer> queueRecoveries = new TreeMap<>();
    Map<Long, ServerMessage<?>> recoveredMessages = new HashMap<>();
    Map<Long, StoredMessage<?>> unusedMessages = new TreeMap<>();
    Map<UUID, Integer> unknownQueuesWithMessages = new HashMap<>();
    Map<Queue<?>, Integer> queuesWithUnknownMessages = new HashMap<>();
    eventLogger.message(logSubject, MessageStoreMessages.RECOVERY_START());
    storeReader.visitMessages(new MessageVisitor(recoveredMessages, unusedMessages));
    eventLogger.message(logSubject, TransactionLogMessages.RECOVERY_START(null, false));
    try {
        storeReader.visitMessageInstances(new MessageInstanceVisitor(virtualHost, store, queueRecoveries, recoveredMessages, unusedMessages, unknownQueuesWithMessages, queuesWithUnknownMessages));
    } finally {
        if (!unknownQueuesWithMessages.isEmpty()) {
            unknownQueuesWithMessages.forEach((queueId, count) -> {
                LOGGER.info("Discarded {} entry(s) associated with queue id '{}' as a queue with this " + "id does not appear in the configuration.", count, queueId);
            });
        }
        if (!queuesWithUnknownMessages.isEmpty()) {
            queuesWithUnknownMessages.forEach((queue, count) -> {
                LOGGER.info("Discarded {} entry(s) associated with queue '{}' as the referenced message " + "does not exist.", count, queue.getName());
            });
        }
    }
    for (Map.Entry<Queue<?>, Integer> entry : queueRecoveries.entrySet()) {
        Queue<?> queue = entry.getKey();
        Integer deliveredCount = entry.getValue();
        eventLogger.message(logSubject, TransactionLogMessages.RECOVERED(deliveredCount, queue.getName()));
        eventLogger.message(logSubject, TransactionLogMessages.RECOVERY_COMPLETE(queue.getName(), true));
        queue.completeRecovery();
    }
    for (Queue<?> q : virtualHost.getChildren(Queue.class)) {
        if (!queueRecoveries.containsKey(q)) {
            q.completeRecovery();
        }
    }
    storeReader.visitDistributedTransactions(new DistributedTransactionVisitor(virtualHost, eventLogger, logSubject, recoveredMessages, unusedMessages));
    for (StoredMessage<?> m : unusedMessages.values()) {
        LOGGER.debug("Message id '{}' is orphaned, removing", m.getMessageNumber());
        m.remove();
    }
    if (unusedMessages.size() > 0) {
        LOGGER.info("Discarded {} orphaned message(s).", unusedMessages.size());
    }
    eventLogger.message(logSubject, TransactionLogMessages.RECOVERY_COMPLETE(null, false));
    eventLogger.message(logSubject, MessageStoreMessages.RECOVERED(recoveredMessages.size() - unusedMessages.size()));
    eventLogger.message(logSubject, MessageStoreMessages.RECOVERY_COMPLETE());
    return Futures.immediateFuture(null);
}
Also used : MessageStore(org.apache.qpid.server.store.MessageStore) EventLogger(org.apache.qpid.server.logging.EventLogger) HashMap(java.util.HashMap) ServerMessage(org.apache.qpid.server.message.ServerMessage) TreeMap(java.util.TreeMap) StoredMessage(org.apache.qpid.server.store.StoredMessage) MessageStoreLogSubject(org.apache.qpid.server.logging.subjects.MessageStoreLogSubject) UUID(java.util.UUID) Queue(org.apache.qpid.server.model.Queue) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 8 with ServerMessage

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

the class DirectExchangeTest method testRouteToQueueWithSelector.

public void testRouteToQueueWithSelector() {
    String boundKey = "key";
    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(), boundKey, Collections.singletonMap(JMS_SELECTOR.toString(), "prop = True"), false);
    assertTrue("Bind operation should be successful", bind);
    RoutingResult<ServerMessage<?>> result = _exchange.route(matchingMessage, boundKey, instanceProperties);
    assertTrue("Message with matching selector not routed to queue", result.hasRoutes());
    result = _exchange.route(unmatchingMessage, boundKey, instanceProperties);
    assertFalse("Message with matching selector unexpectedly routed to queue", result.hasRoutes());
    boolean unbind = _exchange.unbind(queue.getName(), boundKey);
    assertTrue("Unbind operation should be successful", unbind);
    result = _exchange.route(matchingMessage, boundKey, 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 9 with ServerMessage

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

the class FanoutExchangeTest method testRouteToQueueViaTwoExchangesWithReplacementRoutingKeyAndFiltering.

public void testRouteToQueueViaTwoExchangesWithReplacementRoutingKeyAndFiltering() {
    Map<String, Object> viaExchangeArguments = new HashMap<>();
    viaExchangeArguments.put(Exchange.NAME, getTestName() + "_via_exch");
    viaExchangeArguments.put(Exchange.TYPE, ExchangeDefaults.DIRECT_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, "key2");
    exchToViaBindArguments.put(JMS_SELECTOR.toString(), "prop = True");
    boolean exchToViaBind = _exchange.bind(via.getName(), "key1", exchToViaBindArguments, false);
    assertTrue("Exchange to exchange bind operation should be successful", exchToViaBind);
    boolean viaToQueueBind = via.bind(queue.getName(), "key2", Collections.emptyMap(), false);
    assertTrue("Exchange to queue bind operation should be successful", viaToQueueBind);
    RoutingResult<ServerMessage<?>> result = _exchange.route(createTestMessage(Collections.singletonMap("prop", true)), "key1", _instanceProperties);
    assertTrue("Message unexpectedly not routed to queue", result.hasRoutes());
    result = _exchange.route(createTestMessage(Collections.singletonMap("prop", false)), "key1", _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 10 with ServerMessage

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

the class FanoutExchangeTest 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, null, instanceProperties);
    assertTrue("Message with matching selector not routed to queue", result.hasRoutes());
    result = _exchange.route(unmatchingMessage, null, 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, null, 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)

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