use of org.apache.qpid.server.message.MessageDestination in project qpid-broker-j by apache.
the class AbstractExchange method bind.
@Override
public boolean bind(final String destination, String bindingKey, Map<String, Object> arguments, boolean replaceExistingArguments) {
MessageDestination messageDestination = getAttainedMessageDestination(destination);
if (messageDestination == null) {
throw new IllegalArgumentException(String.format("Destination '%s' is not found.", destination));
}
if (bindingKey == null) {
bindingKey = "";
}
if (arguments == null) {
arguments = Collections.emptyMap();
}
Binding newBinding = new BindingImpl(bindingKey, destination, arguments);
boolean modified = false;
for (Binding b : _bindings) {
if (b.getBindingKey().equals(bindingKey) && b.getDestination().equals(messageDestination.getName())) {
if (replaceExistingArguments) {
_bindings.remove(b);
modified = true;
break;
} else {
return false;
}
}
}
_bindings.add(newBinding);
if (isDurable() && messageDestination.isDurable()) {
final Collection<Binding> durableBindings = getDurableBindings();
attributeSet(DURABLE_BINDINGS, durableBindings, durableBindings);
}
final BindingIdentifier bindingIdentifier = new BindingIdentifier(bindingKey, messageDestination);
if (modified) {
onBindingUpdated(bindingIdentifier, arguments);
} else {
final Map<String, Object> bindArguments = BIND_ARGUMENTS_CREATOR.createMap(bindingKey, destination, arguments);
getEventLogger().message(_logSubject, BindingMessages.CREATED(String.valueOf(bindArguments)));
onBind(bindingIdentifier, arguments);
messageDestination.linkAdded(this, newBinding);
}
return true;
}
use of org.apache.qpid.server.message.MessageDestination in project qpid-broker-j by apache.
the class FanoutExchangeImpl method doRoute.
@Override
protected <M extends ServerMessage<? extends StorableMessageMetaData>> void doRoute(final M message, final String routingAddress, final InstanceProperties instanceProperties, final RoutingResult<M> result) {
BindingSet bindingSet = _bindingSet;
if (!bindingSet._unfilteredDestinations.isEmpty()) {
for (MessageDestination destination : bindingSet._unfilteredDestinations.keySet()) {
Set<String> replacementRoutingKeys = new HashSet<>(bindingSet._unfilteredDestinations.get(destination).values());
replacementRoutingKeys.forEach(replacementRoutingKey -> result.add(destination.route(message, replacementRoutingKey == null ? routingAddress : replacementRoutingKey, instanceProperties)));
}
}
final Map<MessageDestination, Map<BindingIdentifier, FilterManagerReplacementRoutingKeyTuple>> filteredDestinations = bindingSet._filteredDestinations;
if (!filteredDestinations.isEmpty()) {
for (Map.Entry<MessageDestination, Map<BindingIdentifier, FilterManagerReplacementRoutingKeyTuple>> entry : filteredDestinations.entrySet()) {
MessageDestination destination = entry.getKey();
final Map<BindingIdentifier, FilterManagerReplacementRoutingKeyTuple> bindingMessageFilterMap = entry.getValue();
for (FilterManagerReplacementRoutingKeyTuple tuple : bindingMessageFilterMap.values()) {
FilterManager filter = tuple.getFilterManager();
if (filter.allAllow(Filterable.Factory.newInstance(message, instanceProperties))) {
String routingKey = tuple.getReplacementRoutingKey() == null ? routingAddress : tuple.getReplacementRoutingKey();
result.add(destination.route(message, routingKey, instanceProperties));
}
}
}
}
}
use of org.apache.qpid.server.message.MessageDestination in project qpid-broker-j by apache.
the class HeadersExchangeImpl method doRoute.
@Override
public <M extends ServerMessage<? extends StorableMessageMetaData>> void doRoute(M payload, String routingKey, final InstanceProperties instanceProperties, RoutingResult<M> routingResult) {
LOGGER.debug("Exchange {}: routing message with headers {}", getName(), payload.getMessageHeader());
for (HeadersBinding hb : _bindingHeaderMatchers) {
if (hb.matches(Filterable.Factory.newInstance(payload, instanceProperties))) {
MessageDestination destination = hb.getBinding().getDestination();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Exchange '{}' delivering message with headers '{}' to '{}'", getName(), payload.getMessageHeader(), destination.getName());
}
String actualRoutingKey = hb.getReplacementRoutingKey() == null ? routingKey : hb.getReplacementRoutingKey();
routingResult.add(destination.route(payload, actualRoutingKey, instanceProperties));
}
}
}
use of org.apache.qpid.server.message.MessageDestination in project qpid-broker-j by apache.
the class TopicExchangeImpl method getMatchedDestinations.
private Map<MessageDestination, Set<String>> getMatchedDestinations(Filterable message, String routingKey) {
Collection<TopicMatcherResult> results = _parser.parse(routingKey);
if (!results.isEmpty()) {
Map<MessageDestination, Set<String>> matchedDestinations = new HashMap<>();
for (TopicMatcherResult result : results) {
TopicExchangeResult topicExchangeResult = (TopicExchangeResult) result;
Map<MessageDestination, String> destinations = topicExchangeResult.processMessage(message);
if (!destinations.isEmpty()) {
destinations.forEach((destination, replacementKey) -> {
Set<String> currentKeys = matchedDestinations.get(destination);
if (currentKeys == null) {
matchedDestinations.put(destination, Collections.singleton(replacementKey));
} else if (!currentKeys.contains(replacementKey)) {
Set<String> newKeys = new HashSet<>(currentKeys);
newKeys.add(replacementKey);
matchedDestinations.put(destination, newKeys);
}
});
}
}
return matchedDestinations;
}
return Collections.emptyMap();
}
use of org.apache.qpid.server.message.MessageDestination in project qpid-broker-j by apache.
the class TopicExchangeImpl method doRoute.
@Override
public <M extends ServerMessage<? extends StorableMessageMetaData>> void doRoute(M payload, String routingAddress, InstanceProperties instanceProperties, RoutingResult<M> result) {
final String routingKey = routingAddress == null ? "" : routingAddress;
final Map<MessageDestination, Set<String>> matchedDestinations = getMatchedDestinations(Filterable.Factory.newInstance(payload, instanceProperties), routingKey);
for (Map.Entry<MessageDestination, Set<String>> entry : matchedDestinations.entrySet()) {
MessageDestination destination = entry.getKey();
Set<String> replacementKeys = entry.getValue();
replacementKeys.forEach(replacementKey -> result.add(destination.route(payload, replacementKey == null ? routingAddress : replacementKey, instanceProperties)));
}
}
Aggregations