use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.
the class TopicExchangeTest 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"));
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());
}
use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.
the class TopicExchangeTest method testRouteToQueueViaTwoExchangesWithReplacementRoutingKeyAndFiltering.
@Test
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());
}
use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.
the class TopicExchangeTest method testUpdateBindingChangeReplacementKey.
@Test
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));
}
use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.
the class MessageConverter_Internal_to_v0_10 method getReplyTo.
private ReplyTo getReplyTo(final NamedAddressSpace addressSpace, final String origReplyTo) {
DestinationAddress destinationAddress = new DestinationAddress(addressSpace, origReplyTo);
MessageDestination messageDestination = destinationAddress.getMessageDestination();
final String exchange = ensureStr8("reply-to[\"exchange\"]", messageDestination instanceof Exchange ? messageDestination.getName() : "");
final String routingKey = ensureStr8("reply-to[\"routing-key\"]", messageDestination instanceof Queue ? messageDestination.getName() : destinationAddress.getRoutingKey());
return new ReplyTo(exchange, routingKey);
}
use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.
the class MessageConverter_Internal_to_v0_10 method convertToAndInitialRoutingKey.
private void convertToAndInitialRoutingKey(final InternalMessage serverMsg, final DeliveryProperties deliveryProps, final NamedAddressSpace addressSpace) {
String to = serverMsg.getTo();
final String exchangeName;
final String routingKey;
if (to == null || "".equals(to)) {
to = serverMsg.getInitialRoutingAddress();
}
if (to != null && !"".equals(to)) {
DestinationAddress destinationAddress = new DestinationAddress(addressSpace, to);
MessageDestination messageDestination = destinationAddress.getMessageDestination();
if (messageDestination instanceof Queue) {
exchangeName = "";
routingKey = messageDestination.getName();
} else if (messageDestination instanceof Exchange) {
exchangeName = messageDestination.getName();
routingKey = destinationAddress.getRoutingKey();
} else {
exchangeName = "";
routingKey = to;
}
} else {
exchangeName = "";
routingKey = "";
}
deliveryProps.setRoutingKey(ensureStr8("to' or 'initialRoutingAddress", routingKey));
deliveryProps.setExchange(ensureStr8("to' or 'initialRoutingAddress", exchangeName));
}
Aggregations