Search in sources :

Example 1 with AmqpError

use of org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError in project qpid-broker-j by apache.

the class NodeReceivingDestination method send.

@Override
public void send(final ServerMessage<?> message, final ServerTransaction txn, final SecurityToken securityToken) throws UnroutableMessageException {
    final String routingAddress = "".equals(_routingAddress) ? getRoutingAddress(message) : _routingAddress;
    _destination.authorisePublish(securityToken, Collections.singletonMap("routingKey", routingAddress));
    final InstanceProperties instanceProperties = new InstanceProperties() {

        @Override
        public Object getProperty(final Property prop) {
            switch(prop) {
                case MANDATORY:
                    return false;
                case REDELIVERED:
                    return false;
                case PERSISTENT:
                    return message.isPersistent();
                case IMMEDIATE:
                    return false;
                case EXPIRATION:
                    return message.getExpiration();
            }
            return null;
        }
    };
    RoutingResult result = _destination.route(message, routingAddress, instanceProperties);
    final int enqueues = result.send(txn, null);
    if (enqueues == 0) {
        if (!_discardUnroutable) {
            final String errorMessage;
            final AmqpError errorCode;
            if (result.isRejected()) {
                if (result.containsReject(RejectType.LIMIT_EXCEEDED)) {
                    errorCode = AmqpError.RESOURCE_LIMIT_EXCEEDED;
                } else if (result.containsReject(RejectType.PRECONDITION_FAILED)) {
                    errorCode = AmqpError.PRECONDITION_FAILED;
                } else {
                    errorCode = AmqpError.ILLEGAL_STATE;
                }
                errorMessage = result.getRejectReason();
            } else {
                errorCode = AmqpError.NOT_FOUND;
                errorMessage = String.format("Unknown destination '%s'", routingAddress);
            }
            throw new UnroutableMessageException(errorCode, errorMessage);
        } else {
            _eventLogger.message(ExchangeMessages.DISCARDMSG(_destination.getName(), routingAddress));
        }
    }
}
Also used : RoutingResult(org.apache.qpid.server.message.RoutingResult) InstanceProperties(org.apache.qpid.server.message.InstanceProperties) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)

Aggregations

InstanceProperties (org.apache.qpid.server.message.InstanceProperties)1 RoutingResult (org.apache.qpid.server.message.RoutingResult)1 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)1