boolean mandatory, boolean immediate, boolean wait) throws JMSException
{
checkTemporaryDestination(destination);
origMessage.setJMSDestination(destination);
AbstractJMSMessage message = convertToNativeMessage(origMessage);
if (_disableMessageId)
{
message.setJMSMessageID(null);
}
else
{
if (message.getJMSMessageID() == null)
{
message.setJMSMessageID(UUID.randomUUID().toString());
}
}
int type;
if (destination instanceof Topic)
{
type = AMQDestination.TOPIC_TYPE;
}
else if (destination instanceof Queue)
{
type = AMQDestination.QUEUE_TYPE;
}
else
{
type = AMQDestination.UNKNOWN_TYPE;
}
message.getJmsHeaders().setInteger(CustomJMSXProperty.JMS_QPID_DESTTYPE.getShortStringName(), type);
// AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
// TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
// Be aware of possible changes to parameter order as versions change.
AMQFrame publishFrame =
BasicPublishBody.createAMQFrame(_channelId, _protocolHandler.getProtocolMajorVersion(),
_protocolHandler.getProtocolMinorVersion(), destination.getExchangeName(), // exchange
immediate, // immediate
mandatory, // mandatory
destination.getRoutingKey(), // routingKey
_session.getTicket()); // ticket
message.prepareForSending();
ByteBuffer payload = message.getData();
BasicContentHeaderProperties contentHeaderProperties = message.getContentHeaderProperties();
if (!_disableTimestamps)
{
final long currentTime = System.currentTimeMillis();
contentHeaderProperties.setTimestamp(currentTime);
if (timeToLive > 0)
{
contentHeaderProperties.setExpiration(currentTime + timeToLive);
}
else
{
contentHeaderProperties.setExpiration(0);
}
}
contentHeaderProperties.setDeliveryMode((byte) deliveryMode);
contentHeaderProperties.setPriority((byte) priority);
final int size = (payload != null) ? payload.limit() : 0;
final int contentBodyFrameCount = calculateContentBodyFrameCount(payload);
final AMQFrame[] frames = new AMQFrame[2 + contentBodyFrameCount];
if (payload != null)
{
createContentBodies(payload, frames, 2, _channelId);
}
if ((contentBodyFrameCount != 0) && _logger.isDebugEnabled())
{
_logger.debug("Sending content body frames to " + destination);
}
// weight argument of zero indicates no child content headers, just bodies
// AMQP version change: Hardwire the version to 0-8 (major=8, minor=0)
// TODO: Connect this to the session version obtained from ProtocolInitiation for this session.
AMQFrame contentHeaderFrame =
ContentHeaderBody.createAMQFrame(_channelId,
BasicConsumeBody.getClazz(_protocolHandler.getProtocolMajorVersion(),
_protocolHandler.getProtocolMinorVersion()), 0, contentHeaderProperties, size);
if (_logger.isDebugEnabled())
{
_logger.debug("Sending content header frame to " + destination);
}
frames[0] = publishFrame;
frames[1] = contentHeaderFrame;
CompositeAMQDataBlock compositeFrame = new CompositeAMQDataBlock(frames);
_protocolHandler.writeFrame(compositeFrame, wait);
if (message != origMessage)
{
_logger.debug("Updating original message");
origMessage.setJMSPriority(message.getJMSPriority());
origMessage.setJMSTimestamp(message.getJMSTimestamp());
_logger.debug("Setting JMSExpiration:" + message.getJMSExpiration());
origMessage.setJMSExpiration(message.getJMSExpiration());
origMessage.setJMSMessageID(message.getJMSMessageID());
}
}