Search in sources :

Example 21 with MessageDestination

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

the class MessageConverter_1_0_to_v0_8 method createMessagePublishInfo.

private MessagePublishInfo createMessagePublishInfo(final MessageMetaData_1_0.MessageHeader_1_0 header, final NamedAddressSpace addressSpace) {
    final String to = header.getTo();
    final String subject = header.getSubject() == null ? "" : header.getSubject();
    final String exchangeName;
    final String routingKey;
    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 = "".equals(destinationAddress.getRoutingKey()) ? subject : destinationAddress.getRoutingKey();
        } else {
            exchangeName = "";
            routingKey = to;
        }
    } else {
        exchangeName = "";
        routingKey = subject;
    }
    return new MessagePublishInfo(convertToShortStringForProperty("to", exchangeName), false, false, convertToShortStringForProperty("to' or 'subject", routingKey));
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo) MessageDestination(org.apache.qpid.server.message.MessageDestination) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) Queue(org.apache.qpid.server.model.Queue) DestinationAddress(org.apache.qpid.server.model.DestinationAddress)

Example 22 with MessageDestination

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

the class AMQChannel method deadLetter.

private void deadLetter(long deliveryTag) {
    final UnacknowledgedMessageMap unackedMap = getUnacknowledgedMessageMap();
    final MessageConsumerAssociation association = unackedMap.remove(deliveryTag, true);
    if (association == null) {
        LOGGER.warn("No message found, unable to DLQ delivery tag: " + deliveryTag);
    } else {
        final MessageInstance messageInstance = association.getMessageInstance();
        final ServerMessage msg = messageInstance.getMessage();
        int requeues = 0;
        if (messageInstance.makeAcquisitionUnstealable(association.getConsumer())) {
            requeues = messageInstance.routeToAlternate(new Action<MessageInstance>() {

                @Override
                public void performAction(final MessageInstance requeueEntry) {
                    messageWithSubject(ChannelMessages.DEADLETTERMSG(msg.getMessageNumber(), requeueEntry.getOwningResource().getName()));
                }
            }, null);
        }
        if (requeues == 0) {
            final TransactionLogResource owningResource = messageInstance.getOwningResource();
            if (owningResource instanceof Queue) {
                final Queue<?> queue = (Queue<?>) owningResource;
                final MessageDestination alternateBindingDestination = queue.getAlternateBindingDestination();
                if (alternateBindingDestination == null) {
                    messageWithSubject(ChannelMessages.DISCARDMSG_NOALTEXCH(msg.getMessageNumber(), queue.getName(), msg.getInitialRoutingAddress()));
                } else {
                    messageWithSubject(ChannelMessages.DISCARDMSG_NOROUTE(msg.getMessageNumber(), alternateBindingDestination.getName()));
                }
            }
        }
    }
}
Also used : MessageInstance(org.apache.qpid.server.message.MessageInstance) PrivilegedAction(java.security.PrivilegedAction) Action(org.apache.qpid.server.util.Action) MessageDestination(org.apache.qpid.server.message.MessageDestination) ServerMessage(org.apache.qpid.server.message.ServerMessage) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Queue(org.apache.qpid.server.model.Queue)

Example 23 with MessageDestination

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

the class AMQChannel method receiveBasicPublish.

@Override
public void receiveBasicPublish(final AMQShortString exchangeName, final AMQShortString routingKey, final boolean mandatory, final boolean immediate) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("RECV[" + _channelId + "] BasicPublish[" + " exchange: " + exchangeName + " routingKey: " + routingKey + " mandatory: " + mandatory + " immediate: " + immediate + " ]");
    }
    NamedAddressSpace vHost = _connection.getAddressSpace();
    if (blockingTimeoutExceeded()) {
        message(ChannelMessages.FLOW_CONTROL_IGNORED());
        closeChannel(ErrorCodes.MESSAGE_TOO_LARGE, "Channel flow control was requested, but not enforced by sender");
    } else {
        MessageDestination destination;
        if (isDefaultExchange(exchangeName)) {
            destination = vHost.getDefaultDestination();
        } else {
            destination = vHost.getAttainedMessageDestination(exchangeName.toString());
        }
        // if the exchange does not exist we raise a channel exception
        if (destination == null) {
            closeChannel(ErrorCodes.NOT_FOUND, "Unknown exchange name: '" + exchangeName + "'");
        } else {
            MessagePublishInfo info = new MessagePublishInfo(exchangeName, immediate, mandatory, routingKey);
            try {
                setPublishFrame(info, destination);
            } catch (AccessControlException e) {
                _connection.sendConnectionClose(ErrorCodes.ACCESS_REFUSED, e.getMessage(), getChannelId());
            }
        }
    }
}
Also used : MessageDestination(org.apache.qpid.server.message.MessageDestination) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) AccessControlException(java.security.AccessControlException)

Example 24 with MessageDestination

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

the class MessageConverter_Internal_to_v0_8 method getReplyTo.

private String getReplyTo(final InternalMessage serverMsg, final NamedAddressSpace addressSpace) {
    String replyTo = serverMsg.getMessageHeader().getReplyTo();
    if (replyTo != null) {
        DestinationAddress destinationAddress = new DestinationAddress(addressSpace, replyTo);
        MessageDestination messageDestination = destinationAddress.getMessageDestination();
        final String replyToBindingUrl;
        if (messageDestination instanceof Exchange) {
            Exchange<?> exchange = (Exchange<?>) messageDestination;
            final String routingKeyOption = "".equals(destinationAddress.getRoutingKey()) ? "" : String.format("?routingkey='%s'", destinationAddress.getRoutingKey());
            replyToBindingUrl = String.format("%s://%s//%s", exchange.getType(), exchange.getName(), routingKeyOption);
        } else if (messageDestination instanceof Queue) {
            replyToBindingUrl = String.format("%s:////%s", ExchangeDefaults.DIRECT_EXCHANGE_CLASS, messageDestination.getName());
        } else {
            replyToBindingUrl = String.format("%s:////?routingkey='%s'", ExchangeDefaults.DIRECT_EXCHANGE_CLASS, destinationAddress.getRoutingKey());
        }
        return replyToBindingUrl;
    }
    return null;
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) MessageDestination(org.apache.qpid.server.message.MessageDestination) Queue(org.apache.qpid.server.model.Queue) DestinationAddress(org.apache.qpid.server.model.DestinationAddress)

Example 25 with MessageDestination

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

the class Session_1_0 method getReceivingDestination.

public ReceivingDestination getReceivingDestination(final Link_1_0<?, ?> link, final Target target) throws AmqpErrorException {
    final ReceivingDestination destination;
    if (target != null) {
        if (Boolean.TRUE.equals(target.getDynamic())) {
            MessageDestination tempDestination = createDynamicDestination(link, target.getDynamicNodeProperties(), target.getCapabilities());
            if (tempDestination != null) {
                target.setAddress(_primaryDomain + tempDestination.getName());
            } else {
                throw new AmqpErrorException(AmqpError.INTERNAL_ERROR, "Cannot create dynamic destination");
            }
        }
        String addr = target.getAddress();
        if (addr == null || "".equals(addr.trim())) {
            destination = new AnonymousRelayDestination(getAddressSpace(), target, _connection.getEventLogger());
        } else {
            DestinationAddress destinationAddress = new DestinationAddress(getAddressSpace(), addr);
            MessageDestination messageDestination = destinationAddress.getMessageDestination();
            if (messageDestination != null) {
                destination = new NodeReceivingDestination(destinationAddress, target.getDurable(), target.getExpiryPolicy(), target.getCapabilities(), _connection.getEventLogger());
            } else {
                destination = null;
            }
        }
    } else {
        destination = null;
    }
    if (destination == null) {
        throw new AmqpErrorException(AmqpError.NOT_FOUND, String.format("Could not find destination for target '%s'", target));
    }
    return destination;
}
Also used : MessageDestination(org.apache.qpid.server.message.MessageDestination) AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) DestinationAddress(org.apache.qpid.server.model.DestinationAddress)

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