ibm-cloudibm-mqopen-liberty

Is there any option to activate/deactivate a MDB in open liberty


I have an enterprise application where I have defined around 10 Message-Driven Beans (MDBs), and I would like to activate them only when necessary, keeping them deactivated otherwise. I will do the required configuration in server.xml, ibm-ejb-jar-bnd.xml, and ejb-jar.xml, and I would like to know if there is any flag kind of option to enable/disable the required MDBs.

Sample config shown below,

ibm-ejb-jar-bnd.xml

    <message-driven name="channel1TransactedMDB">
      <jca-adapter activation-spec-binding-name="jms/channel1MessageMDB" destination-binding-name="jms/channel1Queue"/>
      <resource-ref binding-name="jms/ConnectionFactory" name="jms/QueueConnectionFactory"/>
      <message-destination-ref binding-name="jms/channel1ReplyQueue" name="jms/ReplyQueue"/>
     </message-driven>
     <message-driven name="channel2TransactedMDB">
      <jca-adapter activation-spec-binding-name="jms/channel2MessageMDB" destination-binding-name="jms/channel2Queue"/>
      <resource-ref binding-name="jms/ConnectionFactory" name="jms/QueueConnectionFactory"/>
      <message-destination-ref binding-name="jms/channel2ReplyQueue" name="jms/ReplyQueue"/>
   </message-driven>

server.xml

   <jmsQueue id="jms/channel1Queue" jndiName="jms/channel1Queue">
     <properties.wasJms  queueName="channel1Queue" />
    </jmsQueue>
    <jmsQueue id="jms/channel1ReplyQueue" jndiName="jms/channel1ReplyQueue">
     <properties.wasJms  queueName="channel1ReplyQueue" />
    </jmsQueue>

    <jmsQueue id="jms/channel2Queue" jndiName="jms/channel2Queue">
     <properties.wasJms  queueName="channel2Queue" />
    </jmsQueue>
    <jmsQueue id="jms/channel2ReplyQueue" jndiName="jms/channel2ReplyQueue">
     <properties.wasJms  queueName="channel2ReplyQueue" />
    </jmsQueue>

    <jmsActivationSpec id="jms/channel1MessageMDB">
     <properties.wasJms destinationRef="jms/channel1MessageMDB" destinationType="javax.jms.Queue" />
    </jmsActivationSpec>
    <jmsActivationSpec id="jms/channel2MessageMDB">
      <properties.wasJms destinationRef="jms/channel2MessageMDB" destinationType="javax.jms.Queue"/>
    </jmsActivationSpec>

I have found a workaround in the below link, but would like to know if this feature is available now,

Is it possible to stop an MDB from receiving messages in Liberty Profile?

Expecting a configuration that could activate or deactivate my MDB as and when required.


Solution

  • You can configure the jmsActivationSpec with autoStart set to false which will stop the MDB starting automatically. When you have a stopped MDB you can use the ServerEndpointControl MBean to resume the MDB. You can also use server resume to do the same on the command line.