Search code examples
ibm-mq

IBM MQ: How to handle open/close connections on long running services/workers


I'm using .NET Core to write a Worker Service (Worker Services in .NET) which will connect to a IBM MQ queue to read messages of it. This will be done continuously in a long running process (process will be running until service is stopped).

My questing is: What kind of connection-strategy is the recommended usage when running long processes with IBM MQ?

I see three alternatives:

  1. One connection throughout the application lifetime Open the connection once at application start. Keep reading messages of the queue. Close the connection when the application stops. If the connection accidentally stops, use the appropriate autoconnect flags to reconnect to the queue automatically (if possible).
  2. Open a new connection for every read from the queue Every time we need to read from the queue, open a new connection to the queue and queue-manager and read one message. Close both connections when reading is done.
  3. Open a new connection and process items in the queue until empty Open a connection when we want to process messages. Process all messages in the queue until all messages are processed. When all messages are processed, close the connection.

Alternative two doesn't seem like an option. But what is the recommended connection procedure in this scenario for both queue and queue-manager?


Solution

  • Although not the "official" connection procedure for a long running connection, I settled on option 1: One connection throughout the application lifetime with the appropriate connection-flags for handling automatic reconnect.