Search in sources :

Example 6 with MessageTransfer

use of org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer in project qpid-broker-j by apache.

the class TransactionTimeoutTest method consumeTransactionTimeout.

@Test
public void consumeTransactionTimeout() throws Exception {
    String testMessageBody = "testMessage";
    getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, testMessageBody);
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        byte[] sessionName = "testSession".getBytes(UTF_8);
        final String subscriberName = "testSubscriber";
        interaction.negotiateOpen().channelId(1).attachSession(sessionName).tx().selectId(0).select().message().subscribeAcceptMode(MessageAcceptMode.EXPLICIT).subscribeAcquireMode(MessageAcquireMode.PRE_ACQUIRED).subscribeDestination(subscriberName).subscribeQueue(BrokerAdmin.TEST_QUEUE_NAME).subscribeId(0).subscribe().message().flowId(1).flowDestination(subscriberName).flowUnit(MessageCreditUnit.MESSAGE).flowValue(1).flow().message().flowId(2).flowDestination(subscriberName).flowUnit(MessageCreditUnit.BYTE).flowValue(-1).flow();
        MessageTransfer transfer = receiveResponse(interaction, MessageTransfer.class);
        assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(1)));
        RangeSet transfers = Range.newInstance(transfer.getId());
        interaction.message().acceptId(3).acceptTransfers(transfers).accept().session().flushCompleted().flush();
        SessionCompleted completed = receiveResponse(interaction, SessionCompleted.class);
        assertThat(completed.getCommands(), is(notNullValue()));
        assertThat(completed.getCommands().includes(3), is(equalTo(true)));
        ConnectionClose close = receiveResponse(interaction, ConnectionClose.class);
        assertThat(close.getReplyCode(), is(equalTo(ConnectionCloseCode.CONNECTION_FORCED)));
        assertThat(close.getReplyText(), containsString("transaction timed out"));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v0_10.FrameTransport) SessionCompleted(org.apache.qpid.server.protocol.v0_10.transport.SessionCompleted) Interaction(org.apache.qpid.tests.protocol.v0_10.Interaction) RangeSet(org.apache.qpid.server.protocol.v0_10.transport.RangeSet) ConnectionClose(org.apache.qpid.server.protocol.v0_10.transport.ConnectionClose) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MessageTransfer(org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer) Test(org.junit.Test)

Example 7 with MessageTransfer

use of org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer in project qpid-broker-j by apache.

the class ConsumerTarget_0_10 method doSend.

@Override
public void doSend(final MessageInstanceConsumer consumer, final MessageInstance entry, boolean batch) {
    ServerMessage serverMsg = entry.getMessage();
    MessageTransfer xfr;
    DeliveryProperties deliveryProps;
    MessageProperties messageProps = null;
    MessageTransferMessage msg;
    MessageConverter<? super ServerMessage, MessageTransferMessage> converter = null;
    if (serverMsg instanceof MessageTransferMessage) {
        msg = (MessageTransferMessage) serverMsg;
    } else {
        if (!serverMsg.checkValid()) {
            throw new MessageConversionException(String.format("Cannot convert malformed message '%s'", serverMsg));
        }
        converter = (MessageConverter<? super ServerMessage, MessageTransferMessage>) MessageConverterRegistry.getConverter(serverMsg.getClass(), MessageTransferMessage.class);
        msg = converter.convert(serverMsg, _session.getAddressSpace());
    }
    DeliveryProperties origDeliveryProps = msg.getHeader() == null ? null : msg.getHeader().getDeliveryProperties();
    messageProps = msg.getHeader() == null ? null : msg.getHeader().getMessageProperties();
    deliveryProps = new DeliveryProperties();
    if (origDeliveryProps != null) {
        if (origDeliveryProps.hasDeliveryMode()) {
            deliveryProps.setDeliveryMode(origDeliveryProps.getDeliveryMode());
        }
        if (origDeliveryProps.hasExchange()) {
            deliveryProps.setExchange(origDeliveryProps.getExchange());
        }
        if (origDeliveryProps.hasExpiration()) {
            deliveryProps.setExpiration(origDeliveryProps.getExpiration());
        }
        if (origDeliveryProps.hasPriority()) {
            deliveryProps.setPriority(origDeliveryProps.getPriority());
        }
        if (origDeliveryProps.hasRoutingKey()) {
            deliveryProps.setRoutingKey(origDeliveryProps.getRoutingKey());
        }
        if (origDeliveryProps.hasTimestamp()) {
            deliveryProps.setTimestamp(origDeliveryProps.getTimestamp());
        }
        if (origDeliveryProps.hasTtl()) {
            deliveryProps.setTtl(origDeliveryProps.getTtl());
        }
    }
    deliveryProps.setRedelivered(entry.isRedelivered());
    boolean msgCompressed = messageProps != null && GZIPUtils.GZIP_CONTENT_ENCODING.equals(messageProps.getContentEncoding());
    QpidByteBuffer bodyBuffer = msg.getBody();
    boolean compressionSupported = _session.getConnection().getConnectionDelegate().isCompressionSupported();
    if (msgCompressed && !compressionSupported && bodyBuffer != null) {
        QpidByteBuffer uncompressedBuffer = inflateIfPossible(bodyBuffer);
        messageProps.setContentEncoding(null);
        bodyBuffer.dispose();
        bodyBuffer = uncompressedBuffer;
    } else if (!msgCompressed && compressionSupported && (messageProps == null || messageProps.getContentEncoding() == null) && bodyBuffer != null && bodyBuffer.remaining() > _session.getConnection().getMessageCompressionThreshold()) {
        QpidByteBuffer compressedBuffers = deflateIfPossible(bodyBuffer);
        if (messageProps == null) {
            messageProps = new MessageProperties();
        }
        messageProps.setContentEncoding(GZIPUtils.GZIP_CONTENT_ENCODING);
        bodyBuffer.dispose();
        bodyBuffer = compressedBuffers;
    }
    Header header = new Header(deliveryProps, messageProps, msg.getHeader() == null ? null : msg.getHeader().getNonStandardProperties());
    xfr = batch ? new MessageTransfer(_name, _acceptMode, _acquireMode, header, bodyBuffer, BATCHED) : new MessageTransfer(_name, _acceptMode, _acquireMode, header, bodyBuffer);
    if (bodyBuffer != null) {
        bodyBuffer.dispose();
        bodyBuffer = null;
    }
    if (_acceptMode == MessageAcceptMode.NONE && _acquireMode != MessageAcquireMode.PRE_ACQUIRED) {
        xfr.setCompletionListener(new MessageAcceptCompletionListener(this, consumer, _session, entry, _flowMode == MessageFlowMode.WINDOW));
    } else if (_flowMode == MessageFlowMode.WINDOW) {
        final long messageSize = entry.getMessage().getSize();
        xfr.setCompletionListener(new Method.CompletionListener() {

            @Override
            public void onComplete(Method method) {
                deferredAddCredit(1, messageSize);
            }
        });
    }
    _postIdSettingAction.setXfr(xfr);
    _postIdSettingAction.setAction(null);
    if (_acquireMode == MessageAcquireMode.PRE_ACQUIRED) {
        entry.incrementDeliveryCount();
    }
    if (_acceptMode == MessageAcceptMode.EXPLICIT) {
        _postIdSettingAction.setAction(new ExplicitAcceptDispositionChangeListener(entry, this, consumer));
    } else if (_acquireMode != MessageAcquireMode.PRE_ACQUIRED) {
        _postIdSettingAction.setAction(new ImplicitAcceptDispositionChangeListener(entry, this, consumer));
    }
    _session.sendMessage(xfr, _postIdSettingAction);
    xfr.dispose();
    if (converter != null) {
        converter.dispose(msg);
    }
    _postIdSettingAction.setAction(null);
    _postIdSettingAction.setXfr(null);
    if (_acceptMode == MessageAcceptMode.NONE && _acquireMode == MessageAcquireMode.PRE_ACQUIRED) {
        forceDequeue(entry, false);
    } else if (_acquireMode == MessageAcquireMode.PRE_ACQUIRED) {
        addUnacknowledgedMessage(entry);
    }
}
Also used : MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) ServerMessage(org.apache.qpid.server.message.ServerMessage) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties) Method(org.apache.qpid.server.protocol.v0_10.transport.Method) Header(org.apache.qpid.server.protocol.v0_10.transport.Header) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) MessageTransfer(org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer)

Example 8 with MessageTransfer

use of org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer in project qpid-broker-j by apache.

the class QueueTest method queueDeclareUsingRealQueueAttributesInWireArguments.

@Test
public void queueDeclareUsingRealQueueAttributesInWireArguments() throws Exception {
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        SessionCompleted completed = interaction.negotiateOpen().channelId(1).attachSession(SESSION_NAME).queue().declareQueue(BrokerAdmin.TEST_QUEUE_NAME).declareArguments(Collections.singletonMap("defaultFilters", "{\"selector\":{\"x-filter-jms-selector\":[\"id=2\"]}}")).declareId(0).declare().session().flushCompleted().flush().consumeResponse().getLatestResponse(SessionCompleted.class);
        assertThat(completed.getCommands().includes(0), is(equalTo(true)));
        assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(0)));
        MessageProperties messageProperties1 = new MessageProperties();
        messageProperties1.setApplicationHeaders(Collections.singletonMap("id", 1));
        interaction.message().transferDestination(BrokerAdmin.TEST_QUEUE_NAME).transferId(0).transferHeader(null, messageProperties1).transferBody("Test1".getBytes(StandardCharsets.UTF_8)).transfer().session().flushCompleted().flush().consumeResponse();
        MessageProperties messageProperties2 = new MessageProperties();
        messageProperties2.setApplicationHeaders(Collections.singletonMap("id", 2));
        final String body2 = "Message 2 Content";
        interaction.message().transferDestination(BrokerAdmin.TEST_QUEUE_NAME).transferId(1).transferHeader(null, messageProperties2).transferBody(body2.getBytes(StandardCharsets.UTF_8)).transfer().session().flushCompleted().flush().consumeResponse();
        final String subscriberName = "Test";
        interaction.message().subscribeDestination(subscriberName).subscribeQueue(BrokerAdmin.TEST_QUEUE_NAME).subscribeId(0).subscribe().message().flowId(1).flowDestination(subscriberName).flowUnit(MessageCreditUnit.MESSAGE).flowValue(1).flow().message().flowId(2).flowDestination(subscriberName).flowUnit(MessageCreditUnit.BYTE).flowValue(-1).flow();
        MessageTransfer transfer = interaction.consume(MessageTransfer.class, SessionCompleted.class, SessionCommandPoint.class, SessionConfirmed.class);
        try (QpidByteBuffer buffer = transfer.getBody()) {
            final byte[] dst = new byte[buffer.remaining()];
            buffer.get(dst);
            assertThat(new String(dst, UTF_8), is(equalTo(body2)));
        }
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v0_10.FrameTransport) SessionCompleted(org.apache.qpid.server.protocol.v0_10.transport.SessionCompleted) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) Interaction(org.apache.qpid.tests.protocol.v0_10.Interaction) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) MessageTransfer(org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer) Test(org.junit.Test)

Example 9 with MessageTransfer

use of org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer in project qpid-broker-j by apache.

the class MessageTest method receiveTransfer.

@Test
@SpecificationTest(section = "10.message.transfer", description = "The client may request a broker to transfer messages to it, from a particular queue," + " by issuing a subscribe command. The subscribe command specifies the destination" + " that the broker should use for any resulting transfers.")
public void receiveTransfer() throws Exception {
    String testMessageBody = "testMessage";
    getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, testMessageBody);
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        byte[] sessionName = "testSession".getBytes(UTF_8);
        final String subscriberName = "testSubscriber";
        interaction.negotiateOpen().channelId(1).attachSession(sessionName).message().subscribeDestination(subscriberName).subscribeQueue(BrokerAdmin.TEST_QUEUE_NAME).subscribeId(0).subscribe().message().flowId(1).flowDestination(subscriberName).flowUnit(MessageCreditUnit.MESSAGE).flowValue(1).flow().message().flowId(2).flowDestination(subscriberName).flowUnit(MessageCreditUnit.BYTE).flowValue(-1).flow();
        MessageTransfer transfer = interaction.consume(MessageTransfer.class, SessionCompleted.class, SessionCommandPoint.class, SessionConfirmed.class);
        try (QpidByteBuffer buffer = transfer.getBody()) {
            final byte[] dst = new byte[buffer.remaining()];
            buffer.get(dst);
            assertThat(new String(dst, UTF_8), is(equalTo(testMessageBody)));
        }
    }
}
Also used : QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) MessageTransfer(org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Aggregations

MessageTransfer (org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer)9 Test (org.junit.Test)8 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)4 MessageProperties (org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)4 SessionCompleted (org.apache.qpid.server.protocol.v0_10.transport.SessionCompleted)4 RangeSet (org.apache.qpid.server.protocol.v0_10.transport.RangeSet)3 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)3 ConnectionTune (org.apache.qpid.server.protocol.v0_10.transport.ConnectionTune)2 Header (org.apache.qpid.server.protocol.v0_10.transport.Header)2 Method (org.apache.qpid.server.protocol.v0_10.transport.Method)2 FrameTransport (org.apache.qpid.tests.protocol.v0_10.FrameTransport)2 Interaction (org.apache.qpid.tests.protocol.v0_10.Interaction)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Subject (javax.security.auth.Subject)1 EventLogger (org.apache.qpid.server.logging.EventLogger)1 ServerMessage (org.apache.qpid.server.message.ServerMessage)1 AmqpPort (org.apache.qpid.server.model.port.AmqpPort)1 MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)1 Acquired (org.apache.qpid.server.protocol.v0_10.transport.Acquired)1