Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
How to read retained messages for a Topic

I have a web application that publishes messages to a topic then several Windows services that subscribe to those topics, some with multiple instances. If the services are running when the messages are published everything works correctly but if they are not then the messages are retained on the queue(s) subscribing to that topic but aren't read when the services start back up.

The desired behavior-

  1. When a message is published to the topic string MyTopic, it is read from the MyTopicQueue only once. I use some wildcard topics so each message is sent to multiple queues, but multiple instances of a services subscribe to the same topic string and each message should be read by only of those instances

  2. If the subscribers to the MyTopic topic aren't online when the message is published then the messages are retained on MyTopicQueue.

  3. When the Windows services subscribing to a particularly topic come back on line each retained message is read from MyTopicQueue by only a single subscriber.

I've found some [typically for IBM] spotty documentation about the MQSUBRQ and MQSO_PUBLICATIONS_ON_REQUEST options but I'm not sure how I should set them. Can someone please help figure out what I need to do to get my desired behavior? [Other than switching back to RabbitMQ which I can't do though I'd prefer it.]

My options:

private readonly int _openOptions = MQC.MQSO_CREATE | MQC.MQSO_FAIL_IF_QUIESCING | MQC.MQSO_MANAGED;
private readonly MQGetMessageOptions _messageOptions = new MQGetMessageOptions()

Code to open the Topic:

_topic = _queueManager.AccessTopic(_settings.TopicString, null, 
                    MQC.MQTOPIC_OPEN_AS_SUBSCRIPTION, _openOptions);

The line of code that reads from the topic (taken from a loop):

  _topic.Get(mqMessage, _messageOptions);
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

If you want the messages to accumulate while you are not connected you need to make the subscription durable by adding MQC.MQSO_DURABLE. In order to be able to resume an existing subscription add MQC.MQSO_RESUME in addition to MQC.MQSO_CREATE.


Be careful with terminology, what you are describing as retained messages is a durable subscription.

Retained publications are something else were MQ can retain one most recently published message on each topic and this message will be retrieved by new subscribers by default unless they use MQSO_NEW_PUBLICATIONS_ONLY to skip receiving the retained publication.

MQSO_PUBLICATIONS_ON_REQUEST allows a subscriber to only receive retained publications on request, it will not receive non-retained publications.


If you want multiple consumers to work together on a single subscription you have two options:

  1. Look at shared subscribers in XMS.NET, look at the CLONESUPP property.
  2. Create a one time durable subscription to a queue on the topics you want consumed, then have your consumers directly consume from the queue not a topic.
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!