if (bridgeDup != null)
{
// if the message is being sent from the bridge, we just ignore the duplicate id, and use the internal one
byte[] bridgeDupBytes = (byte[])bridgeDup;
DuplicateIDCache cacheBridge = getDuplicateIDCache(BRIDGE_CACHE_STR.concat(message.getAddress()));
if (cacheBridge.contains(bridgeDupBytes))
{
StringBuffer warnMessage = new StringBuffer();
warnMessage.append("Duplicate message detected through the bridge - message will not be routed. Message information:\n");
warnMessage.append(message.toString());
PostOfficeImpl.log.warn(warnMessage.toString());
if (context.getTransaction() != null)
{
context.getTransaction().markAsRollbackOnly(new HornetQException(HornetQException.DUPLICATE_ID_REJECTED, warnMessage.toString()));
}
message.decrementRefCount();
return false;
}
else
{
if (context.getTransaction() == null)
{
context.setTransaction(new TransactionImpl(storageManager));
startedTX.set(true);
}
}
cacheBridge.addToCache(bridgeDupBytes, context.getTransaction());
message.removeProperty(MessageImpl.HDR_BRIDGE_DUPLICATE_ID);
}
else
{
// if used BridgeDuplicate, it's not going to use the regular duplicate
// since this will would break redistribution (re-setting the duplicateId)
byte[] duplicateIDBytes = message.getDuplicateIDBytes();
DuplicateIDCache cache = null;
boolean isDuplicate = false;
if (duplicateIDBytes != null)
{
cache = getDuplicateIDCache(message.getAddress());
isDuplicate = cache.contains(duplicateIDBytes);
if (rejectDuplicates && isDuplicate)
{
String warnMessage = "Duplicate message detected - message will not be routed. Message information:" + message.toString();
PostOfficeImpl.log.warn(warnMessage);
if (context.getTransaction() != null)
{
context.getTransaction().markAsRollbackOnly(new HornetQException(HornetQException.DUPLICATE_ID_REJECTED, warnMessage));
}
message.decrementRefCount();
return false;
}
}
if (cache != null && !isDuplicate)
{
if (context.getTransaction() == null)
{
// We need to store the duplicate id atomically with the message storage, so we need to create a tx for this
context.setTransaction(new TransactionImpl(storageManager));
startedTX.set(true);
}
cache.addToCache(duplicateIDBytes, context.getTransaction());
}
}
return true;
}