Search in sources :

Example 26 with BasicContentHeaderProperties

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

the class BasicInteraction method publishMessage.

public Interaction publishMessage() throws Exception {
    List<AMQFrame> frames = new ArrayList<>();
    BasicPublishBody publishFrame = new BasicPublishBody(0, AMQShortString.valueOf(_publishExchange), AMQShortString.valueOf(_publishRoutingKey), _publishMandatory, _publishImmediate);
    frames.add(new AMQFrame(_interaction.getChannelId(), publishFrame));
    final BasicContentHeaderProperties basicContentHeaderProperties = new BasicContentHeaderProperties();
    basicContentHeaderProperties.setHeaders(FieldTable.convertToFieldTable(_contentHeaderPropertiesHeaders));
    basicContentHeaderProperties.setContentType(_contentHeaderPropertiesContentType);
    basicContentHeaderProperties.setDeliveryMode(_contentHeaderPropertiesDeliveryMode);
    basicContentHeaderProperties.setPriority(_contentHeaderPropertiesPriority);
    final int contentSize = _content == null ? 0 : _content.length;
    ContentHeaderBody contentHeaderBody = new ContentHeaderBody(basicContentHeaderProperties, contentSize);
    frames.add(new AMQFrame(_interaction.getChannelId(), contentHeaderBody));
    if (contentSize > 0) {
        final byte[] contentCopy = new byte[contentSize];
        System.arraycopy(_content, 0, contentCopy, 0, contentSize);
        final int framePayloadMax = _interaction.getMaximumFrameSize() - 8;
        int offset = 0;
        do {
            int contentToCopyLength = Math.min(framePayloadMax, contentSize - offset);
            ContentBody contentBody = new ContentBody(ByteBuffer.wrap(contentCopy, offset, contentToCopyLength));
            frames.add(new AMQFrame(_interaction.getChannelId(), contentBody));
            offset += contentToCopyLength;
        } while (offset < contentSize);
    }
    CompositeAMQDataBlock frame = new CompositeAMQDataBlock(frames.toArray(new AMQFrame[frames.size()]));
    return _interaction.sendPerformative(frame);
}
Also used : ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) ContentBody(org.apache.qpid.server.protocol.v0_8.transport.ContentBody) ArrayList(java.util.ArrayList) CompositeAMQDataBlock(org.apache.qpid.server.protocol.v0_8.transport.CompositeAMQDataBlock) AMQFrame(org.apache.qpid.server.protocol.v0_8.transport.AMQFrame) BasicPublishBody(org.apache.qpid.server.protocol.v0_8.transport.BasicPublishBody) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)

Example 27 with BasicContentHeaderProperties

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

the class BasicTest method consumeMessage.

@Test
@SpecificationTest(section = "1.8.3.3", description = "start a queue consumer")
public void consumeMessage() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction();
        String messageContent = "Test";
        String consumerTag = "A";
        String queueName = BrokerAdmin.TEST_QUEUE_NAME;
        Map<String, Object> messageHeaders = Collections.singletonMap("test", "testValue");
        String messageContentType = "text/plain";
        byte deliveryMode = (byte) 1;
        byte priority = (byte) 2;
        interaction.openAnonymousConnection().channel().open().consumeResponse(ChannelOpenOkBody.class).basic().qosPrefetchCount(1).qos().consumeResponse(BasicQosOkBody.class).basic().consumeConsumerTag(consumerTag).consumeQueue(queueName).consume().consumeResponse(BasicConsumeOkBody.class).channel().flow(true).consumeResponse(ChannelFlowOkBody.class).basic().contentHeaderPropertiesContentType(messageContentType).contentHeaderPropertiesHeaders(messageHeaders).contentHeaderPropertiesDeliveryMode(deliveryMode).contentHeaderPropertiesPriority(priority).publishExchange("").publishRoutingKey(queueName).content(messageContent).publishMessage().consumeResponse(BasicDeliverBody.class);
        BasicDeliverBody delivery = interaction.getLatestResponse(BasicDeliverBody.class);
        assertThat(delivery.getConsumerTag(), is(equalTo(AMQShortString.valueOf(consumerTag))));
        assertThat(delivery.getConsumerTag(), is(notNullValue()));
        assertThat(delivery.getRedelivered(), is(equalTo(false)));
        assertThat(delivery.getExchange(), is(nullValue()));
        assertThat(delivery.getRoutingKey(), is(equalTo(AMQShortString.valueOf(queueName))));
        ContentHeaderBody header = interaction.consumeResponse(ContentHeaderBody.class).getLatestResponse(ContentHeaderBody.class);
        assertThat(header.getBodySize(), is(equalTo((long) messageContent.length())));
        BasicContentHeaderProperties properties = header.getProperties();
        Map<String, Object> receivedHeaders = new HashMap<>(FieldTable.convertToMap(properties.getHeaders()));
        assertThat(receivedHeaders, is(equalTo(new HashMap<>(messageHeaders))));
        assertThat(properties.getContentTypeAsString(), is(equalTo(messageContentType)));
        assertThat(properties.getPriority(), is(equalTo(priority)));
        assertThat(properties.getDeliveryMode(), is(equalTo(deliveryMode)));
        ContentBody content = interaction.consumeResponse(ContentBody.class).getLatestResponse(ContentBody.class);
        String receivedContent = getContent(content);
        assertThat(receivedContent, is(equalTo(messageContent)));
        assertThat(getBrokerAdmin().getQueueDepthMessages(queueName), is(equalTo(1)));
        interaction.basic().ackDeliveryTag(delivery.getDeliveryTag()).ack().channel().close().consumeResponse(ChannelCloseOkBody.class);
        assertThat(getBrokerAdmin().getQueueDepthMessages(queueName), is(equalTo(0)));
    }
}
Also used : ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) HashMap(java.util.HashMap) BasicConsumeOkBody(org.apache.qpid.server.protocol.v0_8.transport.BasicConsumeOkBody) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) ContentBody(org.apache.qpid.server.protocol.v0_8.transport.ContentBody) BasicDeliverBody(org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 28 with BasicContentHeaderProperties

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

the class MessageConverter_0_8_to_0_10 method convertMetaData.

private MessageMetaData_0_10 convertMetaData(AMQMessage message_0_8) {
    DeliveryProperties deliveryProps = new DeliveryProperties();
    MessageProperties messageProps = new MessageProperties();
    int size = (int) message_0_8.getSize();
    BasicContentHeaderProperties properties = message_0_8.getContentHeaderBody().getProperties();
    final AMQShortString exchange = message_0_8.getMessagePublishInfo().getExchange();
    if (exchange != null) {
        deliveryProps.setExchange(exchange.toString());
    }
    deliveryProps.setExpiration(message_0_8.getExpiration());
    if (message_0_8.getExpiration() != 0) {
        deliveryProps.setTtl(message_0_8.getExpiration() - message_0_8.getArrivalTime());
    }
    deliveryProps.setImmediate(message_0_8.isImmediate());
    deliveryProps.setDiscardUnroutable(!message_0_8.isMandatory());
    deliveryProps.setPriority(MessageDeliveryPriority.get(properties.getPriority()));
    deliveryProps.setRoutingKey(message_0_8.getInitialRoutingAddress());
    deliveryProps.setTimestamp(properties.getTimestamp());
    if (properties.getDeliveryMode() == BasicContentHeaderProperties.PERSISTENT) {
        deliveryProps.setDeliveryMode(MessageDeliveryMode.PERSISTENT);
    } else {
        deliveryProps.setDeliveryMode(MessageDeliveryMode.NON_PERSISTENT);
    }
    messageProps.setContentEncoding(properties.getEncodingAsString());
    messageProps.setContentLength(size);
    if (properties.getAppId() != null) {
        messageProps.setAppId(properties.getAppId().getBytes());
    }
    messageProps.setContentType(properties.getContentTypeAsString());
    if (properties.getCorrelationId() != null) {
        messageProps.setCorrelationId(properties.getCorrelationId().getBytes());
    }
    if (properties.getReplyTo() != null && properties.getReplyTo().length() != 0) {
        String origReplyToString = properties.getReplyTo().toString();
        ReplyTo replyTo = new ReplyTo();
        // if the string looks like a binding URL, then attempt to parse it...
        try {
            AMQBindingURL burl = new AMQBindingURL(origReplyToString);
            String routingKey = burl.getRoutingKey();
            if (routingKey != null) {
                replyTo.setRoutingKey(routingKey);
            }
            String exchangeName = burl.getExchangeName();
            if (exchangeName != null && !"".equals(exchangeName)) {
                replyTo.setExchange(exchangeName);
            }
        } catch (URISyntaxException e) {
            replyTo.setRoutingKey(origReplyToString);
        }
        messageProps.setReplyTo(replyTo);
    }
    if (properties.getMessageId() != null) {
        UUID uuid;
        String messageIdAsString = properties.getMessageIdAsString();
        if (messageIdAsString.startsWith("ID:")) {
            messageIdAsString = messageIdAsString.substring(3);
        }
        try {
            uuid = UUID.fromString(messageIdAsString);
        } catch (IllegalArgumentException e) {
            uuid = UUID.nameUUIDFromBytes(messageIdAsString.getBytes(UTF_8));
        }
        messageProps.setMessageId(uuid);
    }
    if (properties.getUserId() != null) {
        messageProps.setUserId(properties.getUserId().getBytes());
    }
    FieldTable fieldTable = properties.getHeaders();
    Map<String, Object> appHeaders = FieldTable.convertToMap(fieldTable);
    if (properties.getType() != null) {
        appHeaders.put("x-jms-type", properties.getTypeAsString());
    }
    messageProps.setApplicationHeaders(appHeaders);
    Header header = new Header(deliveryProps, messageProps, null);
    return new MessageMetaData_0_10(header, size, message_0_8.getArrivalTime());
}
Also used : AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) AMQBindingURL(org.apache.qpid.server.url.AMQBindingURL) FieldTable(org.apache.qpid.server.protocol.v0_8.FieldTable) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) URISyntaxException(java.net.URISyntaxException) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) ReplyTo(org.apache.qpid.server.protocol.v0_10.transport.ReplyTo) Header(org.apache.qpid.server.protocol.v0_10.transport.Header) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) UUID(java.util.UUID) MessageMetaData_0_10(org.apache.qpid.server.protocol.v0_10.MessageMetaData_0_10)

Example 29 with BasicContentHeaderProperties

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

the class PropertyConverter_0_10_to_0_8Test method testPriorityConversion.

public void testPriorityConversion() {
    final byte priority = 5;
    final DeliveryProperties deliveryProperties = new DeliveryProperties();
    deliveryProperties.setPriority(MessageDeliveryPriority.get(priority));
    MessageTransferMessage message = createTestMessage(deliveryProperties);
    final AMQMessage convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
    BasicContentHeaderProperties properties = convertedMessage.getContentHeaderBody().getProperties();
    assertEquals("Unexpected priority", priority, properties.getPriority());
}
Also used : MessageTransferMessage(org.apache.qpid.server.protocol.v0_10.MessageTransferMessage) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) AMQMessage(org.apache.qpid.server.protocol.v0_8.AMQMessage)

Example 30 with BasicContentHeaderProperties

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

the class PropertyConverter_0_10_to_0_8Test method testReplyToConversionWhenRoutingKeySpecified.

public void testReplyToConversionWhenRoutingKeySpecified() {
    final String routingKey = "test_routing_key";
    final MessageProperties messageProperties = new MessageProperties();
    messageProperties.setReplyTo(new ReplyTo(null, routingKey));
    MessageTransferMessage message = createTestMessage(messageProperties);
    final AMQMessage convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
    BasicContentHeaderProperties properties = convertedMessage.getContentHeaderBody().getProperties();
    String expectedReplyTo = String.format("direct:////?routingkey='%s'", routingKey);
    assertEquals("Unexpected reply-to", expectedReplyTo, properties.getReplyTo().toString());
}
Also used : ReplyTo(org.apache.qpid.server.protocol.v0_10.transport.ReplyTo) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) MessageTransferMessage(org.apache.qpid.server.protocol.v0_10.MessageTransferMessage) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) AMQMessage(org.apache.qpid.server.protocol.v0_8.AMQMessage)

Aggregations

BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)151 AMQMessage (org.apache.qpid.server.protocol.v0_8.AMQMessage)115 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)74 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)59 MessageTransferMessage (org.apache.qpid.server.protocol.v0_10.MessageTransferMessage)52 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)48 MessageProperties (org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)39 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)31 DeliveryProperties (org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)21 Matchers.anyString (org.mockito.Matchers.anyString)20 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)18 HashMap (java.util.HashMap)16 ContentHeaderBody (org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody)16 Header (org.apache.qpid.server.protocol.v1_0.type.messaging.Header)12 MessagePublishInfo (org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo)9 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)8 ReplyTo (org.apache.qpid.server.protocol.v0_10.transport.ReplyTo)7 Date (java.util.Date)6 UUID (java.util.UUID)6 MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)6