Search in sources :

Example 36 with Queue

use of org.apache.qpid.server.model.Queue in project qpid-broker-j by apache.

the class MessageConverter_1_0_to_v0_8 method getReplyTo.

private AMQShortString getReplyTo(final Message_1_0 serverMsg, final NamedAddressSpace addressSpace) {
    final 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());
        }
        try {
            return AMQShortString.valueOf(replyToBindingUrl);
        } catch (IllegalArgumentException e) {
            throw new MessageConversionException("Could not convert message from 1.0 to 0-8 because conversion of 'reply-to' failed.", e);
        }
    }
    return null;
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) MessageDestination(org.apache.qpid.server.message.MessageDestination) MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) Queue(org.apache.qpid.server.model.Queue) DestinationAddress(org.apache.qpid.server.model.DestinationAddress)

Example 37 with Queue

use of org.apache.qpid.server.model.Queue 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 38 with Queue

use of org.apache.qpid.server.model.Queue in project qpid-broker-j by apache.

the class PropertyConverter_Internal_to_v0_10Test method testReplyToConversionWhenQueueIsSpecified.

public void testReplyToConversionWhenQueueIsSpecified() throws IOException {
    final AMQMessageHeader header = mock(AMQMessageHeader.class);
    final String replyTo = "myTestQueue";
    final Queue queue = mock(Queue.class);
    when(queue.getName()).thenReturn(replyTo);
    when(_addressSpace.getAttainedMessageDestination(replyTo)).thenReturn(queue);
    when(header.getReplyTo()).thenReturn(replyTo);
    InternalMessage originalMessage = createTestMessage(header);
    MessageTransferMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
    final ReplyTo convertedReplyTo = convertedMessage.getHeader().getMessageProperties().getReplyTo();
    assertEquals("Unexpected exchange", "", convertedReplyTo.getExchange());
    assertEquals("Unexpected routing key", replyTo, convertedReplyTo.getRoutingKey());
}
Also used : ReplyTo(org.apache.qpid.server.protocol.v0_10.transport.ReplyTo) InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader) Matchers.anyString(org.mockito.Matchers.anyString) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) Queue(org.apache.qpid.server.model.Queue)

Example 39 with Queue

use of org.apache.qpid.server.model.Queue 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 40 with Queue

use of org.apache.qpid.server.model.Queue in project qpid-broker-j by apache.

the class AMQChannel method receiveQueueDeclare.

@Override
public void receiveQueueDeclare(final AMQShortString queueStr, final boolean passive, final boolean durable, final boolean exclusive, final boolean autoDelete, final boolean nowait, final FieldTable arguments) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("RECV[" + _channelId + "] QueueDeclare[" + " queue: " + queueStr + " passive: " + passive + " durable: " + durable + " exclusive: " + exclusive + " autoDelete: " + autoDelete + " nowait: " + nowait + " arguments: " + arguments + " ]");
    }
    NamedAddressSpace virtualHost = _connection.getAddressSpace();
    final AMQShortString queueName;
    // if we aren't given a queue name, we create one which we return to the client
    if ((queueStr == null) || (queueStr.length() == 0)) {
        queueName = new AMQShortString("tmp_" + UUID.randomUUID());
    } else {
        queueName = queueStr;
    }
    Queue<?> queue;
    if (passive) {
        queue = getQueue(queueName.toString());
        if (queue == null) {
            closeChannel(ErrorCodes.NOT_FOUND, "Queue: '" + queueName + "' not found on VirtualHost '" + virtualHost.getName() + "'.");
        } else {
            if (!queue.verifySessionAccess(this)) {
                _connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "Queue '" + queue.getName() + "' is exclusive, but not created on this Connection.", getChannelId());
            } else {
                // set this as the default queue on the channel:
                setDefaultQueue(queue);
                if (!nowait) {
                    sync();
                    MethodRegistry methodRegistry = _connection.getMethodRegistry();
                    QueueDeclareOkBody responseBody = methodRegistry.createQueueDeclareOkBody(queueName, queue.getQueueDepthMessages(), queue.getConsumerCount());
                    _connection.writeFrame(responseBody.generateFrame(getChannelId()));
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("Queue " + queueName + " declared successfully");
                    }
                }
            }
        }
    } else {
        try {
            final String queueNameString = AMQShortString.toString(queueName);
            Map<String, Object> wireArguments = FieldTable.convertToMap(arguments);
            Object alternateExchange = wireArguments.get(ALTERNATE_EXCHANGE);
            if (alternateExchange != null) {
                String alternateExchangeName = String.valueOf(alternateExchange);
                validateAlternateExchangeIsNotQueue(virtualHost, alternateExchangeName);
            }
            Map<String, Object> attributes = QueueArgumentsConverter.convertWireArgsToModel(queueNameString, wireArguments);
            attributes.put(Queue.NAME, queueNameString);
            attributes.put(Queue.DURABLE, durable);
            LifetimePolicy lifetimePolicy;
            ExclusivityPolicy exclusivityPolicy;
            if (exclusive) {
                lifetimePolicy = autoDelete ? LifetimePolicy.DELETE_ON_NO_OUTBOUND_LINKS : durable ? LifetimePolicy.PERMANENT : LifetimePolicy.DELETE_ON_CONNECTION_CLOSE;
                exclusivityPolicy = durable ? ExclusivityPolicy.CONTAINER : ExclusivityPolicy.CONNECTION;
            } else {
                lifetimePolicy = autoDelete ? LifetimePolicy.DELETE_ON_NO_OUTBOUND_LINKS : LifetimePolicy.PERMANENT;
                exclusivityPolicy = ExclusivityPolicy.NONE;
            }
            if (!attributes.containsKey(Queue.EXCLUSIVE)) {
                attributes.put(Queue.EXCLUSIVE, exclusivityPolicy);
            }
            if (!attributes.containsKey(Queue.LIFETIME_POLICY)) {
                attributes.put(Queue.LIFETIME_POLICY, lifetimePolicy);
            }
            queue = virtualHost.createMessageSource(Queue.class, attributes);
            setDefaultQueue(queue);
            if (!nowait) {
                sync();
                MethodRegistry methodRegistry = _connection.getMethodRegistry();
                QueueDeclareOkBody responseBody = methodRegistry.createQueueDeclareOkBody(queueName, queue.getQueueDepthMessages(), queue.getConsumerCount());
                _connection.writeFrame(responseBody.generateFrame(getChannelId()));
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Queue " + queueName + " declared successfully");
                }
            }
        } catch (AbstractConfiguredObject.DuplicateNameException qe) {
            queue = (Queue<?>) qe.getExisting();
            if (!queue.verifySessionAccess(this)) {
                _connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "Queue '" + queue.getName() + "' is exclusive, but not created on this Connection.", getChannelId());
            } else if (queue.isExclusive() != exclusive) {
                closeChannel(ErrorCodes.ALREADY_EXISTS, "Cannot re-declare queue '" + queue.getName() + "' with different exclusivity (was: " + queue.isExclusive() + " requested " + exclusive + ")");
            } else if ((autoDelete && queue.getLifetimePolicy() == LifetimePolicy.PERMANENT) || (!autoDelete && queue.getLifetimePolicy() != ((exclusive && !durable) ? LifetimePolicy.DELETE_ON_CONNECTION_CLOSE : LifetimePolicy.PERMANENT))) {
                closeChannel(ErrorCodes.ALREADY_EXISTS, "Cannot re-declare queue '" + queue.getName() + "' with different lifetime policy (was: " + queue.getLifetimePolicy() + " requested autodelete: " + autoDelete + ")");
            } else {
                setDefaultQueue(queue);
                if (!nowait) {
                    sync();
                    MethodRegistry methodRegistry = _connection.getMethodRegistry();
                    QueueDeclareOkBody responseBody = methodRegistry.createQueueDeclareOkBody(queueName, queue.getQueueDepthMessages(), queue.getConsumerCount());
                    _connection.writeFrame(responseBody.generateFrame(getChannelId()));
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("Queue " + queueName + " declared successfully");
                    }
                }
            }
        } catch (AccessControlException e) {
            _connection.sendConnectionClose(ErrorCodes.ACCESS_REFUSED, e.getMessage(), getChannelId());
        } catch (UnknownAlternateBindingException e) {
            final String message = String.format("Unknown alternate exchange: '%s'", e.getAlternateBindingName());
            _connection.sendConnectionClose(ErrorCodes.NOT_FOUND, message, getChannelId());
        } catch (IllegalArgumentException | IllegalConfigurationException e) {
            String message = String.format("Error creating queue '%s': %s", queueName, e.getMessage());
            _connection.sendConnectionClose(ErrorCodes.COMMAND_INVALID, message, getChannelId());
        }
    }
}
Also used : LifetimePolicy(org.apache.qpid.server.model.LifetimePolicy) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) AccessControlException(java.security.AccessControlException) ExclusivityPolicy(org.apache.qpid.server.model.ExclusivityPolicy) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) UnknownAlternateBindingException(org.apache.qpid.server.virtualhost.UnknownAlternateBindingException) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Queue(org.apache.qpid.server.model.Queue)

Aggregations

Queue (org.apache.qpid.server.model.Queue)56 HashMap (java.util.HashMap)14 Exchange (org.apache.qpid.server.model.Exchange)12 MessageDestination (org.apache.qpid.server.message.MessageDestination)11 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)9 DestinationAddress (org.apache.qpid.server.model.DestinationAddress)8 MessageSource (org.apache.qpid.server.message.MessageSource)6 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)6 Matchers.anyString (org.mockito.Matchers.anyString)6 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)5 ServerMessage (org.apache.qpid.server.message.ServerMessage)5 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)5 AccessControlException (java.security.AccessControlException)4 QmfAgentData (org.apache.qpid.qmf2.agent.QmfAgentData)4 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)4 MessagePublishInfo (org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo)4 Map (java.util.Map)3 AMQMessageHeader (org.apache.qpid.server.message.AMQMessageHeader)3 ReplyTo (org.apache.qpid.server.protocol.v0_10.transport.ReplyTo)3 Source (org.apache.qpid.server.protocol.v1_0.type.messaging.Source)3