Search in sources :

Example 91 with AMQMessage

use of org.apache.qpid.server.protocol.v0_8.AMQMessage in project qpid-broker-j by apache.

the class MessageFormat_0_9_1 method convertToMessageFormat.

@Override
public QpidByteBuffer convertToMessageFormat(final AMQMessage message) {
    final MessagePublishInfo messagePublishInfo = message.getMessagePublishInfo();
    final ContentHeaderBody contentHeaderBody = message.getContentHeaderBody();
    AMQShortString exchange = messagePublishInfo.getExchange();
    AMQShortString routingKey = messagePublishInfo.getRoutingKey();
    int length = contentHeaderBody.getSize() + (exchange == null ? 0 : exchange.length()) + (routingKey == null ? 0 : routingKey.length()) + 3;
    try (QpidByteBuffer headerBuf = QpidByteBuffer.allocateDirect(length);
        QpidByteBuffer content = message.getContent()) {
        EncodingUtils.writeShortStringBytes(headerBuf, exchange);
        EncodingUtils.writeShortStringBytes(headerBuf, routingKey);
        byte flags = messagePublishInfo.isMandatory() ? (byte) 0 : MANDATORY_MASK;
        if (messagePublishInfo.isImmediate()) {
            flags |= IMMEDIATE_MASK;
        }
        headerBuf.put(flags);
        headerBuf.flip();
        contentHeaderBody.writePayload(headerBuf);
        return QpidByteBuffer.concatenate(headerBuf, content);
    }
}
Also used : MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo) ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Example 92 with AMQMessage

use of org.apache.qpid.server.protocol.v0_8.AMQMessage in project qpid-broker-j by apache.

the class AMQMessageMutator method create.

@Override
public AMQMessage create() {
    final long contentSize = _message.getSize();
    final QpidByteBuffer content = _message.getContent();
    final ContentHeaderBody contentHeader = new ContentHeaderBody(_basicContentHeaderProperties, contentSize);
    final MessageMetaData messageMetaData = new MessageMetaData(_message.getMessagePublishInfo(), contentHeader, _message.getArrivalTime());
    final MessageHandle<MessageMetaData> handle = _messageStore.addMessage(messageMetaData);
    if (content != null) {
        handle.addContent(content);
    }
    return new AMQMessage(handle.allContentAdded(), _message.getConnectionReference());
}
Also used : ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Example 93 with AMQMessage

use of org.apache.qpid.server.protocol.v0_8.AMQMessage in project qpid-broker-j by apache.

the class ProtocolOutputConverterImpl method createEncodedDeliverBody.

private AMQBody createEncodedDeliverBody(AMQMessage message, boolean isRedelivered, final long deliveryTag, final AMQShortString consumerTag) {
    final AMQShortString exchangeName;
    final AMQShortString routingKey;
    final MessagePublishInfo pb = message.getMessagePublishInfo();
    exchangeName = pb.getExchange();
    routingKey = pb.getRoutingKey();
    return new EncodedDeliveryBody(deliveryTag, routingKey, exchangeName, consumerTag, isRedelivered);
}
Also used : MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo)

Example 94 with AMQMessage

use of org.apache.qpid.server.protocol.v0_8.AMQMessage in project qpid-broker-j by apache.

the class PropertyConverter_Internal_to_v0_8Test method testConversionWhenToIsUnsetButInitialRoutingKeyIsSet.

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

Example 95 with AMQMessage

use of org.apache.qpid.server.protocol.v0_8.AMQMessage 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)

Aggregations

Test (org.junit.Test)198 AMQMessage (org.apache.qpid.server.protocol.v0_8.AMQMessage)176 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)143 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)114 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)78 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)76 MessageTransferMessage (org.apache.qpid.server.protocol.v0_10.MessageTransferMessage)58 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)57 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)46 MessageProperties (org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)38 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)33 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)32 MessagePublishInfo (org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo)32 DeliveryProperties (org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)26 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)25 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)24 AmqpValue (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValue)17 HashMap (java.util.HashMap)15 Data (org.apache.qpid.server.protocol.v1_0.type.messaging.Data)14 Header (org.apache.qpid.server.protocol.v1_0.type.messaging.Header)12