mattrpav commented on code in PR #1139:
URL: https://github.com/apache/activemq/pull/1139#discussion_r1456232186
##########
activemq-broker/src/main/java/org/apache/activemq/broker/TransactionBroker.java:
##########
@@ -291,13 +294,43 @@ public void send(ProducerBrokerExchange producerExchange,
final Message message)
transaction = getTransaction(context, message.getTransactionId(),
false);
}
context.setTransaction(transaction);
+
try {
+ // [AMQ-9344] Limit uncommitted transactions by count
+ verifyUncommittedCount(producerExchange, transaction, message);
next.send(producerExchange, message);
} finally {
context.setTransaction(originalTx);
}
}
+ protected void verifyUncommittedCount(ProducerBrokerExchange
producerExchange, Transaction transaction, Message message) throws Exception {
+ // maxUncommittedCount <= 0 disables
+ int maxUncommittedCount =
this.getBrokerService().getMaxUncommittedCount();
+ if (maxUncommittedCount > 0 && transaction.size() >=
maxUncommittedCount) {
+
+ try {
+ // Rollback as we are throwing an error the client as throwing
the error will cause
+ // the client to reset to a new transaction so we need to
clean up
+ transaction.rollback();
+
+ // Send ResourceAllocationException which will translate to a
JMSException
+ final ResourceAllocationException e = new
ResourceAllocationException(
+ "Can not send message on transaction with id: '" +
transaction.getTransactionId().toString()
+ + "', Transaction has reached the maximum allowed number
of pending send operations before commit of '"
+ + maxUncommittedCount + "'", "42900");
+ if(LOG.isDebugEnabled()) {
+ LOG.warn("ConnectionId:{} exceeded maxUncommittedCount:{}
for destination:{} in transactionId:{}",
(producerExchange.getConnectionContext() != null ?
producerExchange.getConnectionContext().getConnectionId() : "<not set>"),
maxUncommittedCount, message.getDestination().getQualifiedName(),
transaction.getTransactionId().toString(), e);
Review Comment:
When DEBUG is enabled, the log is at the same level, but includes the
exception
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]