I was working on a customer issue which reported that enabling Maintain strict message order on an existing topic space destination leads to deleting existing messages in the topic space destination. When we say, existing messages in a topic space destination, it means there are some durable subscriptions configured over JMS topics created on the topic destination. Also, the subscribers are currently not running and hence the messages produced are stored in the durable subscription homes waiting for subscribers to come on-line for message delivery. At first glance, it looks like a serious problem in the product, but after investigating further, it revealed that this behavior of deleting messages is the correct way of handling the existing messages.
I would like to explain the circumstances under which it is observed, and why this behavior is observed, and how to avoid it.
This configuration can be enabled on a topic space destination using the admin console as shown in the below Figure1. For more information about strict ordering of messages visit the link.
Figure1: Enabling strict message order on a topic space destination
The messages are deleted under the below circumstances.
- There is already a topic space destination on which the Maintain strict message order is NOT configured currently.
- There are also one or more JMS topics and one or more durable subscriptions defined over this topic space destination. These durable subscriptions are currently storing some messages published to them as there are no subscribers currently running.
- At this point of time, administrator enabled strict ordering on this topic space destination by checking the checkbox as shown in the Figure1 above and saved the configuration.
- This configuration will not be picked up at runtime. So it requires restart.
- When the environment is restarted, all the messages that are currently stored in the durable subscription homes are deleted without getting consumed by any subscribers.
The above phenomenon is an expected behavior because of the following reasons.
- The durable subscriptions are configured over JMS topics which are defined on the topic space destination. The messages published on the topic space destination are stored in the durable subscription home (Messaging engines) until subscribers come on-line if they are currently off-line. When subscribers come on-line, the messages stored are forwarded to subscribers and deleted further.
- When Maintain strict message order is enabled on the existing topic space destination, it overrides certain configurations as explained in the link. These overridden configurations affect the way subscribers have to function so as to satisfy the strictly ordered delivery of messages further on. For example, if the durable subscriptions on this topic space destination allow the creation of multiple consumer sessions currently, after the Maintain strict message order is enabled, its value is overridden so as to not to allow creation of the multiple consumer sessions further on.
- Since enabling Maintain strict message order overrides some of configurations, the messages which are produced before it is enabled can not be retrofit to the strict message order. This means, if there are existing durable subscriptions, these subscriptions along with any messages currently stored in them are no more valid with respect to the new configuration change.
- Because of the above explained reasons, after the configuration change and restart, when the subscribers try to connection to the messaging with the same durable subscription, the messaging engine compares the subscription request with existing details whose configuration is changed before restart. As these details do not match, the messaging engine throws SIDurableSubscriptionMismatchException. The subscribers which receive this exception delete the subscription and recreate it. As part of the deletion of the subscription, the existing messages also get deleted.
- By the way, more often than not we do not come across this kind of requirement to enable strict message ordering on an existing topic space destination which is not currently ordered. The strict message ordering is a business requirement which will be identified during the design phases of the application development along with the corresponding messaging destinations. So, the configuration Maintain strict message order usually remains for the entire life time of the destination.
To avoid losing the messages, first consume all the existing messages and later change the configuration and restart the environment. The configuration change like checking Maintain strict message order is significant in terms of how it is going to handle delivery of messages later. So, its implications have to be properly understood. Also, this problem does not occur with queue destinations.
There is one more related configuration which requires citation here. It is Share durable subscriptions on the activation specifications. Along with Maintain strict message order, it is recommended to set the value of Share durable subscriptions to Never Shared. If the value of Share durable subscriptions is not set to Never Shared, the warning messages CWSIV0769W & CWSIP0028W are continuously printed in the SystemOut.log files of messaging engine and application servers which unnecessarily eats up the disk space.