Skip to content

Enforce non-negative delivery delay in strictCompliance mode#1809

Closed
pradeep85841 wants to merge 2 commits intoapache:mainfrom
pradeep85841:feature/jakarta-strict-delivery-delay
Closed

Enforce non-negative delivery delay in strictCompliance mode#1809
pradeep85841 wants to merge 2 commits intoapache:mainfrom
pradeep85841:feature/jakarta-strict-delivery-delay

Conversation

@pradeep85841
Copy link
Contributor

  • Implemented setDeliveryDelay and getDeliveryDelay in ActiveMQMessageProducer
  • Added Jakarta 3.1 compliance check to reject negative delays when strictCompliance is enabled
  • Added unit tests to verify both strict enforcement and legacy behaviour

@jbonofre jbonofre self-requested a review March 19, 2026 17:49
@pradeep85841
Copy link
Contributor Author

  • Updated ActiveMQJMS2ContextTest to reflect that these methods are now fully supported, removing legacy UnsupportedOperationException assertions.
  • Added validation to throw MessageFormatException for negative delays when strictCompliance is enabled, as required by Jakarta Messaging 3.1.
  • Maintained backward compatibility for legacy/non-strict mode.

private MessageTransformer transformer;
private MemoryUsage producerWindow;

protected long deliveryDelay = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deliveryDelay is not used in send().

It means that it's not effective.

To be effective, the delay needs to be applied during message dispatch (so either passing it through to the session send, or setting AMQ_SCHEDULED_DELAY on the message).

Also ActiveMQProducer.setDeliveryDelay() (for JMS 2.0 JMSProducer) is not updated and still throws UnsupportedOperationException.

I think it's better to have the PR atomic and consistent.


// Jakarta 3.1 Compliance Guard
if (deliveryDelay < 0 && session.connection.isStrictCompliance()) {
throw new jakarta.jms.MessageFormatException("Delivery delay cannot be negative when strictCompliance is enabled.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong imho.

Jakarta Messaging 3.1 spec (MessageProducer.setDeliveryDelay) doesn't mandate MessageFormatException for invalid arguments.

MessageFormatException is for message body/property type conversion issues (like in setBody).
An IllegalArgumentException or JMSException (generic) would be more appropriate.
The JMS Spec says nothing about negative delays being illegal, the behavior is undefined and it's up to us to decide the validation logic.

*/

@Override
public void setDeliveryDelay(long deliveryDelay) throws JMSException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than defining here, why not updated ActiveMQMessageProducerSupport ?

private MessageTransformer transformer;
private MemoryUsage producerWindow;

protected long deliveryDelay = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need really protected here ?
As we have getter/setter access, we can go with private and using mock in the test, right ?

@mattrpav
Copy link
Contributor

Updates to DeliveryDelay work should be applied to the pre-existing WIP PR: [#1157]

@pradeep85841
Copy link
Contributor Author

Closing this in favor of consolidating the Delivery Delay work into #1157 as requested by @mattrpav. I will move the Jakarta 3.1 compliance and 'effective delay' logic there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants