use of org.apache.qpid.server.protocol.v0_8.transport.CompositeAMQDataBlock 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);
}
Aggregations