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());
}
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);
}
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());
}
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());
}
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());
}
Aggregations