use of org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody 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);
}
use of org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody 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)));
}
}
use of org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody in project qpid-broker-j by apache.
the class BasicTest method qosBytesSizeQosDoesNotPreventFirstMessage.
@Test
@SpecificationTest(section = "1.8.3.3", description = "The server MUST ignore this setting when the client is not processing any messages - i.e. " + "the prefetch size does not limit the transfer of single messages to a client, only " + "the sending in advance of more messages while the client still has one or more " + "unacknowledged messages.")
public void qosBytesSizeQosDoesNotPreventFirstMessage() throws Exception {
String messageContent = String.join("", Collections.nCopies(1024, "*"));
getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, messageContent);
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
String consumerTag = "A";
interaction.openAnonymousConnection().channel().open().consumeResponse(ChannelOpenOkBody.class).channel().flow(true).consumeResponse(ChannelFlowOkBody.class).basic().qosPrefetchSize(512).qos().consumeResponse(BasicQosOkBody.class).basic().consumeConsumerTag(consumerTag).consumeQueue(BrokerAdmin.TEST_QUEUE_NAME).consume().consumeResponse(BasicConsumeOkBody.class).consumeResponse(BasicDeliverBody.class);
BasicDeliverBody delivery = interaction.getLatestResponse(BasicDeliverBody.class);
ContentHeaderBody header = interaction.consumeResponse().getLatestResponse(ContentHeaderBody.class);
assertThat(header.getBodySize(), is(equalTo((long) messageContent.length())));
ContentBody content = interaction.consumeResponse().getLatestResponse(ContentBody.class);
String receivedContent = getContent(content);
assertThat(receivedContent, is(equalTo(messageContent)));
interaction.basic().ackDeliveryTag(delivery.getDeliveryTag()).ack().channel().close().consumeResponse(ChannelCloseOkBody.class);
assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), is(equalTo(0)));
}
}
use of org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody in project qpid-broker-j by apache.
the class MessageConverter_1_0_to_v0_8 method convertMetaData.
private MessageMetaData convertMetaData(final Message_1_0 serverMsg, final String bodyMimeType, final int size, final NamedAddressSpace addressSpace) {
final MessageMetaData_1_0.MessageHeader_1_0 header = serverMsg.getMessageHeader();
final BasicContentHeaderProperties props = new BasicContentHeaderProperties();
props.setAppId(serverMsg.getMessageHeader().getAppId());
props.setContentType(bodyMimeType);
props.setEncoding(convertToShortStringForProperty("content-encoding", serverMsg.getMessageHeader().getEncoding()));
props.setCorrelationId(getCorrelationIdAsShortString(serverMsg));
props.setDeliveryMode(serverMsg.isPersistent() ? BasicContentHeaderProperties.PERSISTENT : BasicContentHeaderProperties.NON_PERSISTENT);
final Date absoluteExpiryTime = getAbsoluteExpiryTime(serverMsg);
if (absoluteExpiryTime != null) {
props.setExpiration(absoluteExpiryTime.getTime());
} else {
Long ttl = getTtl(serverMsg);
if (ttl != null) {
props.setExpiration(ttl + serverMsg.getArrivalTime());
}
}
props.setMessageId(getMessageIdAsShortString(serverMsg));
props.setPriority(serverMsg.getMessageHeader().getPriority());
props.setReplyTo(getReplyTo(serverMsg, addressSpace));
Date timestamp = getCreationTime(serverMsg);
if (timestamp != null) {
props.setTimestamp(timestamp.getTime());
} else {
props.setTimestamp(serverMsg.getArrivalTime());
}
props.setUserId(getUserIdAsShortString(serverMsg));
Map<String, Object> headerProps = new LinkedHashMap<>();
if (header.getSubject() != null) {
headerProps.put("qpid.subject", header.getSubject());
props.setType(convertToShortStringForProperty("subject", header.getSubject()));
}
String groupId = getGroupId(serverMsg);
if (groupId != null) {
headerProps.put("JMSXGroupID", groupId);
}
UnsignedInteger groupSequence = getGroupSequence(serverMsg);
if (groupSequence != null) {
headerProps.put("JMSXGroupSeq", groupSequence.intValue());
}
for (String headerName : serverMsg.getMessageHeader().getHeaderNames()) {
headerProps.put(headerName, convertValue(serverMsg.getMessageHeader().getHeader(headerName)));
}
final FieldTable headers;
try {
headers = FieldTable.convertToFieldTable(headerProps);
} catch (IllegalArgumentException e) {
throw new MessageConversionException("Could not convert message from 1.0 to 0-8 because conversion of 'application-properties' failed.", e);
}
props.setHeaders(headers);
final ContentHeaderBody chb = new ContentHeaderBody(props);
chb.setBodySize(size);
MessagePublishInfo publishInfo = createMessagePublishInfo(header, addressSpace);
return new MessageMetaData(publishInfo, chb, serverMsg.getArrivalTime());
}
use of org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody in project qpid-broker-j by apache.
the class BDBMessageStoreTest method createAndStoreSingleChunkMessage_0_8.
private StoredMessage<MessageMetaData> createAndStoreSingleChunkMessage_0_8(MessageStore store) {
QpidByteBuffer chunk1 = QpidByteBuffer.wrap(CONTENT_BYTES);
int bodySize = CONTENT_BYTES.length;
// create and store the message using the MessageStore interface
MessagePublishInfo pubInfoBody_0_8 = createPublishInfoBody_0_8();
BasicContentHeaderProperties props_0_8 = createContentHeaderProperties_0_8();
ContentHeaderBody chb_0_8 = createContentHeaderBody_0_8(props_0_8, bodySize);
MessageMetaData messageMetaData_0_8 = new MessageMetaData(pubInfoBody_0_8, chb_0_8);
MessageHandle<MessageMetaData> storedMessage_0_8 = store.addMessage(messageMetaData_0_8);
storedMessage_0_8.addContent(chunk1);
((AbstractBDBMessageStore.StoredBDBMessage) storedMessage_0_8).flushToStore();
return storedMessage_0_8.allContentAdded();
}
Aggregations