Search in sources :

Example 51 with Queue

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

the class MessageConverter_Internal_to_v0_10 method convertToAndInitialRoutingKey.

private void convertToAndInitialRoutingKey(final InternalMessage serverMsg, final DeliveryProperties deliveryProps, final NamedAddressSpace addressSpace) {
    String to = serverMsg.getTo();
    final String exchangeName;
    final String routingKey;
    if (to == null || "".equals(to)) {
        to = serverMsg.getInitialRoutingAddress();
    }
    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 = destinationAddress.getRoutingKey();
        } else {
            exchangeName = "";
            routingKey = to;
        }
    } else {
        exchangeName = "";
        routingKey = "";
    }
    deliveryProps.setRoutingKey(ensureStr8("to' or 'initialRoutingAddress", routingKey));
    deliveryProps.setExchange(ensureStr8("to' or 'initialRoutingAddress", exchangeName));
}
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 52 with Queue

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

the class PropertyConverter_Internal_to_v0_8Test method testToConversionWhenQueueIsSpecified.

@Test
public void testToConversionWhenQueueIsSpecified() {
    final String testQueue = "testQueue";
    InternalMessage message = createTestMessage(testQueue);
    final Queue queue = mock(Queue.class);
    when(queue.getName()).thenReturn(testQueue);
    doReturn(queue).when(_addressSpace).getAttainedMessageDestination(eq(testQueue), anyBoolean());
    final AMQMessage convertedMessage = _messageConverter.convert(message, _addressSpace);
    final MessagePublishInfo messagePublishInfo = convertedMessage.getMessagePublishInfo();
    assertEquals("Unexpected exchange", "", messagePublishInfo.getExchange().toString());
    assertEquals("Unexpected routing key", testQueue, messagePublishInfo.getRoutingKey().toString());
}
Also used : MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo) InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Queue(org.apache.qpid.server.model.Queue) Test(org.junit.Test)

Example 53 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 54 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 55 with Queue

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

the class MessageConverter_1_0_to_v0_10 method getReplyTo.

private ReplyTo getReplyTo(final NamedAddressSpace addressSpace, final String origReplyTo) {
    DestinationAddress destinationAddress = new DestinationAddress(addressSpace, origReplyTo);
    MessageDestination messageDestination = destinationAddress.getMessageDestination();
    return new ReplyTo(ensureStr8("reply-to[\"exchange\"]", messageDestination instanceof Exchange ? messageDestination.getName() : ""), ensureStr8("reply-to[\"routing-key\"]", messageDestination instanceof Queue ? messageDestination.getName() : destinationAddress.getRoutingKey()));
}
Also used : ReplyTo(org.apache.qpid.server.protocol.v0_10.transport.ReplyTo) 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)

Aggregations

Queue (org.apache.qpid.server.model.Queue)66 Test (org.junit.Test)32 HashMap (java.util.HashMap)18 Exchange (org.apache.qpid.server.model.Exchange)13 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 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)6 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)6 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)5 AccessControlException (java.security.AccessControlException)4 Map (java.util.Map)4 QmfAgentData (org.apache.qpid.qmf2.agent.QmfAgentData)4 ServerMessage (org.apache.qpid.server.message.ServerMessage)4 MessagePublishInfo (org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo)4 LinkedHashMap (java.util.LinkedHashMap)3 AMQInvalidArgumentException (org.apache.qpid.server.filter.AMQInvalidArgumentException)3