void sendMessage(JBossMessage msg, Transaction tx, boolean checkForDuplicates) throws Exception
{
if (trace) { log.trace(this + " sending " + msg + (tx == null ? " non-transactionally" : " in " + tx)); }
JBossDestination dest = (JBossDestination)msg.getJMSDestination();
// This allows the no-local consumers to filter out the messages that come from the same
// connection.
// TODO Do we want to set this for ALL messages. Optimisation is possible here.
msg.setConnectionID(id);
if (checkForDuplicates)
{
// Message is already stored... so just ignoring the call
if (serverPeer.getPersistenceManagerInstance().referenceExists(msg.getMessageID()))
{
return;
}
}
// messages arriving over a failed-over connections will be give preferential treatment by
// routers, which will send them directly to their corresponding failover queues, not to
// the "local" queues, to reduce clutter and unnecessary "pull policy" revving.
if (failedNodeID != null)
{
msg.putHeader(Message.FAILED_NODE_ID, failedNodeID);
}
// We must reference the message *before* we send it the destination to be handled. This is
// so we can guarantee that the message doesn't disappear from the store before the
// handling is complete. Each channel then takes copies of the reference if they decide to
// maintain it internally
MessageReference ref = null;
try
{
ref = ms.reference(msg);
long schedDeliveryTime = msg.getScheduledDeliveryTime();
if (schedDeliveryTime > 0)
{
ref.setScheduledDeliveryTime(schedDeliveryTime);
}
if (dest.isQueue())
{
if (!postOffice.route(ref, new JMSCondition(true, dest.getName()), tx))
{
throw new JMSException("Failed to route " + ref + " to " + dest.getName());
}
}
else
{
postOffice.route(ref, new JMSCondition(false, dest.getName()), tx);
}
}
finally
{
if (ref != null)