Search in sources :

Example 6 with MessageDestination

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

the class AbstractExchange method unbind.

@Override
public boolean unbind(@Param(name = "destination", mandatory = true) final String destination, @Param(name = "bindingKey") String bindingKey) {
    MessageDestination messageDestination = getAttainedMessageDestination(destination);
    if (messageDestination != null) {
        Iterator<Binding> bindingIterator = _bindings.iterator();
        if (bindingKey == null) {
            bindingKey = "";
        }
        while (bindingIterator.hasNext()) {
            Binding binding = bindingIterator.next();
            if (binding.getBindingKey().equals(bindingKey) && binding.getDestination().equals(destination)) {
                _bindings.remove(binding);
                messageDestination.linkRemoved(this, binding);
                onUnbind(new BindingIdentifier(bindingKey, messageDestination));
                if (!autoDeleteIfNecessary()) {
                    if (isDurable() && messageDestination.isDurable()) {
                        final Collection<Binding> durableBindings = getDurableBindings();
                        attributeSet(DURABLE_BINDINGS, durableBindings, durableBindings);
                    }
                }
                final Map<String, Object> bindArguments = UNBIND_ARGUMENTS_CREATOR.createMap(bindingKey, destination);
                getEventLogger().message(_logSubject, BindingMessages.DELETED(String.valueOf(bindArguments)));
                return true;
            }
        }
    }
    return false;
}
Also used : Binding(org.apache.qpid.server.model.Binding) AlternateBinding(org.apache.qpid.server.model.AlternateBinding) MessageDestination(org.apache.qpid.server.message.MessageDestination) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject)

Example 7 with MessageDestination

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

the class DefaultDestination method route.

@Override
public <M extends ServerMessage<? extends StorableMessageMetaData>> RoutingResult<M> route(M message, String routingAddress, InstanceProperties instanceProperties) {
    RoutingResult<M> result = new RoutingResult<>(message);
    DestinationAddress destinationAddress = new DestinationAddress(_virtualHost, routingAddress);
    MessageDestination messageDestination = destinationAddress.getMessageDestination();
    if (messageDestination != null) {
        result.add(messageDestination.route(message, destinationAddress.getRoutingKey(), instanceProperties));
    }
    return result;
}
Also used : RoutingResult(org.apache.qpid.server.message.RoutingResult) MessageDestination(org.apache.qpid.server.message.MessageDestination) DestinationAddress(org.apache.qpid.server.model.DestinationAddress)

Example 8 with MessageDestination

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

the class DirectExchangeImpl method doRoute.

@Override
public <M extends ServerMessage<? extends StorableMessageMetaData>> void doRoute(final M payload, final String routingKey, final InstanceProperties instanceProperties, final RoutingResult<M> result) {
    BindingSet bindings = _bindingsByKey.get(routingKey == null ? "" : routingKey);
    if (bindings != null) {
        final Map<MessageDestination, String> unfilteredDestinations = bindings.getUnfilteredDestinations();
        for (MessageDestination destination : unfilteredDestinations.keySet()) {
            String actualRoutingKey = unfilteredDestinations.get(destination) == null ? routingKey : unfilteredDestinations.get(destination);
            result.add(destination.route(payload, actualRoutingKey, instanceProperties));
        }
        if (bindings.hasFilteredQueues()) {
            Filterable filterable = Filterable.Factory.newInstance(payload, instanceProperties);
            Map<MessageDestination, FilterManagerReplacementRoutingKeyTuple> filteredDestinations = bindings.getFilteredDestinations();
            for (Map.Entry<MessageDestination, FilterManagerReplacementRoutingKeyTuple> entry : filteredDestinations.entrySet()) {
                FilterManagerReplacementRoutingKeyTuple tuple = entry.getValue();
                String actualRoutingKey = tuple.getReplacementRoutingKey() == null ? routingKey : tuple.getReplacementRoutingKey();
                if (tuple.getFilterManager().allAllow(filterable)) {
                    result.add(entry.getKey().route(payload, actualRoutingKey, instanceProperties));
                }
            }
        }
    }
}
Also used : MessageDestination(org.apache.qpid.server.message.MessageDestination) Filterable(org.apache.qpid.server.filter.Filterable) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Example 9 with MessageDestination

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

the class TopicExchangeImpl method bind.

private synchronized void bind(final BindingIdentifier binding, Map<String, Object> arguments) throws AMQInvalidArgumentException {
    final String bindingKey = binding.getBindingKey();
    MessageDestination messageDestination = binding.getDestination();
    LOGGER.debug("Registering messageDestination {} with routing key {}", messageDestination.getName(), bindingKey);
    String routingKey = TopicNormalizer.normalize(bindingKey);
    TopicExchangeResult result = _topicExchangeResults.get(routingKey);
    if (_bindings.containsKey(binding)) {
        updateTopicExchangeResult(result, binding, arguments);
    } else {
        if (result == null) {
            result = new TopicExchangeResult();
            if (FilterSupport.argumentsContainFilter(arguments)) {
                result.addFilteredDestination(messageDestination, FilterSupport.createMessageFilter(arguments, messageDestination));
            } else {
                result.addUnfilteredDestination(messageDestination);
            }
            _parser.addBinding(routingKey, result);
            _topicExchangeResults.put(routingKey, result);
        } else {
            if (FilterSupport.argumentsContainFilter(arguments)) {
                result.addFilteredDestination(messageDestination, FilterSupport.createMessageFilter(arguments, messageDestination));
            } else {
                result.addUnfilteredDestination(messageDestination);
            }
        }
        _bindings.put(binding, arguments);
        result.addBinding(binding, arguments);
    }
}
Also used : MessageDestination(org.apache.qpid.server.message.MessageDestination) TopicExchangeResult(org.apache.qpid.server.exchange.topic.TopicExchangeResult)

Example 10 with MessageDestination

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

the class AMQChannel method deliverCurrentMessageIfComplete.

private void deliverCurrentMessageIfComplete() {
    // check and deliver if header says body length is zero
    if (_currentMessage.allContentReceived()) {
        MessagePublishInfo info = _currentMessage.getMessagePublishInfo();
        String routingKey = AMQShortString.toString(info.getRoutingKey());
        String exchangeName = AMQShortString.toString(info.getExchange());
        try {
            final MessageDestination destination = _currentMessage.getDestination();
            ContentHeaderBody contentHeader = _currentMessage.getContentHeader();
            _connection.checkAuthorizedMessagePrincipal(AMQShortString.toString(contentHeader.getProperties().getUserId()));
            _publishAuthCache.authorisePublish(destination, routingKey, info.isImmediate(), _connection.getLastReadTime());
            if (_confirmOnPublish) {
                _confirmedMessageCounter++;
            }
            long bodySize = _currentMessage.getSize();
            long timestamp = contentHeader.getProperties().getTimestamp();
            try {
                final MessagePublishInfo messagePublishInfo = _currentMessage.getMessagePublishInfo();
                final MessageMetaData messageMetaData = new MessageMetaData(messagePublishInfo, contentHeader, getConnection().getLastReadTime());
                final MessageHandle<MessageMetaData> handle = _messageStore.addMessage(messageMetaData);
                int bodyCount = _currentMessage.getBodyCount();
                if (bodyCount > 0) {
                    for (int i = 0; i < bodyCount; i++) {
                        ContentBody contentChunk = _currentMessage.getContentChunk(i);
                        handle.addContent(contentChunk.getPayload());
                        contentChunk.dispose();
                    }
                }
                final StoredMessage<MessageMetaData> storedMessage = handle.allContentAdded();
                final AMQMessage amqMessage = new AMQMessage(storedMessage, _connection.getReference());
                try (MessageReference reference = amqMessage.newReference()) {
                    _currentMessage = null;
                    final boolean immediate = messagePublishInfo.isImmediate();
                    final InstanceProperties instanceProperties = new InstanceProperties() {

                        @Override
                        public Object getProperty(final Property prop) {
                            switch(prop) {
                                case EXPIRATION:
                                    return amqMessage.getExpiration();
                                case IMMEDIATE:
                                    return immediate;
                                case PERSISTENT:
                                    return amqMessage.isPersistent();
                                case MANDATORY:
                                    return messagePublishInfo.isMandatory();
                                case REDELIVERED:
                                    return false;
                            }
                            return null;
                        }
                    };
                    final RoutingResult<AMQMessage> result = destination.route(amqMessage, amqMessage.getInitialRoutingAddress(), instanceProperties);
                    int enqueues = result.send(_transaction, immediate ? _immediateAction : null);
                    if (enqueues == 0) {
                        boolean mandatory = amqMessage.isMandatory();
                        boolean closeOnNoRoute = _connection.isCloseWhenNoRoute();
                        if (LOGGER.isDebugEnabled()) {
                            LOGGER.debug("Unroutable message exchange='{}', routing key='{}', mandatory={}," + " transactionalSession={}, closeOnNoRoute={}, confirmOnPublish={}", exchangeName, routingKey, mandatory, isTransactional(), closeOnNoRoute, _confirmOnPublish);
                        }
                        int errorCode = ErrorCodes.NO_ROUTE;
                        String errorMessage = String.format("No route for message with exchange '%s' and routing key '%s'", exchangeName, routingKey);
                        if (result.containsReject(RejectType.LIMIT_EXCEEDED)) {
                            errorCode = ErrorCodes.RESOURCE_ERROR;
                            errorMessage = errorMessage + ":" + result.getRejectReason();
                        }
                        if (mandatory && isTransactional() && !_confirmOnPublish && _connection.isCloseWhenNoRoute()) {
                            _connection.sendConnectionClose(errorCode, errorMessage, _channelId);
                        } else {
                            if (mandatory || amqMessage.isImmediate()) {
                                if (_confirmOnPublish) {
                                    _connection.writeFrame(new AMQFrame(_channelId, new BasicNackBody(_confirmedMessageCounter, false, false)));
                                }
                                _transaction.addPostTransactionAction(new WriteReturnAction(errorCode, errorMessage, amqMessage));
                            } else {
                                if (_confirmOnPublish) {
                                    _connection.writeFrame(new AMQFrame(_channelId, new BasicAckBody(_confirmedMessageCounter, false)));
                                }
                                message(ExchangeMessages.DISCARDMSG(exchangeName, routingKey));
                            }
                        }
                    } else {
                        if (_confirmOnPublish) {
                            recordFuture(Futures.immediateFuture(null), new ServerTransaction.Action() {

                                private final long _deliveryTag = _confirmedMessageCounter;

                                @Override
                                public void postCommit() {
                                    BasicAckBody body = _connection.getMethodRegistry().createBasicAckBody(_deliveryTag, false);
                                    _connection.writeFrame(body.generateFrame(_channelId));
                                }

                                @Override
                                public void onRollback() {
                                    final BasicNackBody body = new BasicNackBody(_deliveryTag, false, false);
                                    _connection.writeFrame(new AMQFrame(_channelId, body));
                                }
                            });
                        }
                    }
                }
            } finally {
                _connection.registerMessageReceived(bodySize);
                if (isTransactional()) {
                    _connection.registerTransactedMessageReceived();
                }
                _currentMessage = null;
            }
        } catch (AccessControlException e) {
            _connection.sendConnectionClose(ErrorCodes.ACCESS_REFUSED, e.getMessage(), getChannelId());
        }
    }
}
Also used : MessageDestination(org.apache.qpid.server.message.MessageDestination) InstanceProperties(org.apache.qpid.server.message.InstanceProperties) AccessControlException(java.security.AccessControlException) MessageReference(org.apache.qpid.server.message.MessageReference) ServerTransaction(org.apache.qpid.server.txn.ServerTransaction)

Aggregations

MessageDestination (org.apache.qpid.server.message.MessageDestination)40 DestinationAddress (org.apache.qpid.server.model.DestinationAddress)11 Queue (org.apache.qpid.server.model.Queue)11 Exchange (org.apache.qpid.server.model.Exchange)10 HashMap (java.util.HashMap)6 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)6 Map (java.util.Map)5 AlternateBinding (org.apache.qpid.server.model.AlternateBinding)5 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)5 AccessControlException (java.security.AccessControlException)4 HashSet (java.util.HashSet)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 RoutingResult (org.apache.qpid.server.message.RoutingResult)4 Binding (org.apache.qpid.server.model.Binding)4 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)4 Set (java.util.Set)3 TopicExchangeResult (org.apache.qpid.server.exchange.topic.TopicExchangeResult)3 InstanceProperties (org.apache.qpid.server.message.InstanceProperties)3 ReplyTo (org.apache.qpid.server.protocol.v0_10.transport.ReplyTo)3 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)3