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"));
}
}
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);
}
}
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)));
}
}
}
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)));
}
}
}
Aggregations