MQ

 View Only
Expand all | Collapse all

Spring JMS and MQ application rebalancing with default MQ connection factory

  • 1.  Spring JMS and MQ application rebalancing with default MQ connection factory

    IBM Champion
    Posted Fri March 25, 2022 05:22 PM
    Is there a way to use the default MQ connection factory so that I can have application instances be rebalanced across a uniform cluster?  The Spring JMS code is pretty simple in our case.  I would prefer to not create a custom MQConnectionFactory just to rebalance.

    Main class:
    @EnableJms
    @SpringBootApplication
    public class MyApplication {
    	public static void main(final String[] args) {
    		SpringApplication.run(MyApplication.class, args);
    	}
    }​


    Message listener:

    @Service
    public class MessageService {	
    	@JmsListener(destination = "MQDEV.QUEUE.V1")
    	public void listener(Message msg) {
    		try {		
    			System.out.println(msg.getBody(String.class));
    		} catch (Exception e) {
    			System.out.println("Failed!");
    		}
    	}
    }
    These are the relevant values from application.yaml:
    spring:
      jms:
        pub-sub-domain: false
          
    ibm:
      mq:
        queue-manager: "*QM_ANY"
        ccdt-url: <my CCDT URL>
        user: <user>
        password: <pwd>
        application-name: "My Application"
        default-reconnect: YES​

    I was hopeful the default-reconnect property would do the trick, but I still see both connections remain on the same qmgr.  If I run "dis apstatus(*) all" on either of the queue managers I see COUNT(2), but BALANCED(NOTAPPLIC) for this application.  For our other (non-JMS) clients the value for balanced eventually gets to YES and I see the instances reconnect to different qmgrs.

    I believe what I really need is to specify
    WMQConstants.WMQ_CLIENT_RECONNECT in the connection properties.  This would allow these clients to connect to any queue manager and accept the reconnect request.  Would that fix the issue?  Is there a way to access the connection properties for the default MQ connection factory that is being used, or do I need to create a custom MQConnectionFactory as mentioned in this post from StackOverflow?  In a uniform cluster world it would be nice to have a property for this exposed.  We are using version 2.6.3 of the mq-jms-spring-boot-starter package.

    Thanks,
    Jim





    ------------------------------
    Jim Creasman
    ------------------------------


  • 2.  RE: Spring JMS and MQ application rebalancing with default MQ connection factory

    IBM Champion
    Posted Mon March 28, 2022 01:18 AM
    Edited by Francois Brandelik Mon March 28, 2022 01:20 AM
    Hi Jim,
    You don't specify what type the CCDTURL is (whether JSON or binary) (I haven't tested the Uniform Cluster without a JSON CCDT) and you might have to access the custom property field (CF configuration) of your CF and set the re-connection properties there... don't remember what the default ones are...

    ------------------------------
    Francois Brandelik
    ------------------------------



  • 3.  RE: Spring JMS and MQ application rebalancing with default MQ connection factory

    IBM Champion
    Posted Mon March 28, 2022 01:17 PM
    Francois, our CCDTURL response is in JSON format.  Is it possible to use binary CCDT when supplying this via CCDTURL?

    ------------------------------
    Jim Creasman
    ------------------------------



  • 4.  RE: Spring JMS and MQ application rebalancing with default MQ connection factory

    Posted Mon March 28, 2022 05:22 AM
    • "DISPLAY CONN(*) WHERE(APPLTYPE EQ USER) CONNOPTS" will show the effective reconnect options in case the channel has explicitly overridden the app
    • Don't forget that JMS "Connections" can result in >1 MQ connection; for rebalancing purposes they are tied together based on the generated CONNTAG value
    • If further options are needed on the CF that are not explicitly listed as configurable, then you can either use a customizer method or use the "additionalProperties" map in the configuration
    • Using debug logging on the Spring app will show the applied configuration for the CF to make sure your config is correctly set


    ------------------------------
    Mark Taylor
    Winchester
    ------------------------------



  • 5.  RE: Spring JMS and MQ application rebalancing with default MQ connection factory

    IBM Champion
    Posted Mon March 28, 2022 01:16 PM
    Thanks, Mark.  Adding CLIENTRECONNECTOPTIONS: ANY to the ibm.mq.additionalProperties in application.yaml seems to have worked.  For others who might be searching I found these properties documented here.  

    I did notice one behavior that I'm not certain about.  Initially, both my clients connected to the first qmgr.  Within a few seconds a balance request was logged on the console of the second qmgr and one instance of my application reconnected.  This all went as expected, except that I saw the following two message logged repeatedly at the first qmgr's console.

    03/28/22 15:51:41 - Process(212.27) User(mqm) Program(amqzlaa0)
                        Host(mqserver-uc-0) Installation(Installation1)
                        VRMF(9.2.0.4) QMgr(QC90)
                        Time(2022-03-28T15:51:41.299Z)
                        CommentInsert1(amqrmppa)
                       
    AMQ5540E: Application 'amqrmppa' did not supply a user ID and password
    
    EXPLANATION:
    The queue manager is configured to require a user ID and password, but none was
    supplied.
    ACTION:
    Ensure that the application provides a valid user ID and password, or change
    the value of CHCKCLNT to OPTIONAL on the AUTHINFO object specified by the
    CONNAUTH attribute on the queue manager. For the change to take effect, you
    must refresh the connection authentication configuration of the queue manager.
    ----- amqzfuca.c : 5089 -------------------------------------------------------
    03/28/22 15:51:43 - Process(549.7) User(mqm) Program(amqrmppa)
                        Host(mqserver-uc-0) Installation(Installation1)
                        VRMF(9.2.0.4) QMgr(QC90)
                        Time(2022-03-28T15:51:43.302Z)
                        RemoteHost(172.19.0.1)
                        CommentInsert1(ccxOPT_NETWORK_ERROR)
                        CommentInsert2(ccxReceive)
                       
    AMQ9213E: A communications error for ccxReceive occurred.
    
    EXPLANATION:
    An unexpected error occurred in communications.
    ACTION:
    The return code from the ccxReceive call was 0 (X'0'). Record these values and
    tell the systems administrator.
    ----- amqcccxa.c : 2590 -------------------------------------------------------​

    This went on for about a minute and then stopped.  Both consumer client instances are connected and able to receive messages.  What is the meaning of these errors?  Application 'amqrmppa' is the channel pooling process from what I read.  Are these errors normal, or is there something else I should do?  We use LDAP for security and the clients supply a user ID and password when they log in.  FWIW, I don't see these errors whenever our NodeJS clients rebalance.

    Jim

    ------------------------------
    Jim Creasman
    ------------------------------



  • 6.  RE: Spring JMS and MQ application rebalancing with default MQ connection factory

    Posted Mon March 28, 2022 01:42 PM
    Edited by Mark Taylor Mon March 28, 2022 01:42 PM
    I suspect your original problem was in the YAML where you say you had
    default-reconnect: yes
    which likely got interpreted as a boolean. not a string. That's YAML's fault ... And I don't know what Spring did with it then, but it wouldn't have ended up getting set correctly. Either put the "yes" in quotes, or "any" is an acceptable alternative.

    Can't help with the password issue though.

    ------------------------------
    Mark Taylor
    Winchester
    ------------------------------



  • 7.  RE: Spring JMS and MQ application rebalancing with default MQ connection factory

    IBM Champion
    Posted Mon March 28, 2022 02:06 PM
    I removed the additionalProperties from my application.yaml and changed the YES value of default-reconnect to "ANY".  This is how the current YAML looks:

    ibm:
      mq:
        queue-manager: ${MQ_MANAGER}
        ccdt-url: ${MQ_CCDT_URL}
        user: ${MQ_USER}
        password: ${MQ_PWD}
        application-name: "@project.artifactId@"
        default-reconnect: "ANY"​

    I'll keep my eye on the password error.  It goes away after a few seconds.



    ------------------------------
    Jim Creasman
    ------------------------------



  • 8.  RE: Spring JMS and MQ application rebalancing with default MQ connection factory

    Posted Wed March 30, 2022 01:47 PM
    Hi Mark,

    Can you expand a bit more on this comment and/or point me to some doco describing this please?

    • Don't forget that JMS "Connections" can result in >1 MQ connection; for rebalancing purposes they are tied together based on the generated CONNTAG value

    TIA,
    Don

    ------------------------------
    Donald Thomas
    ------------------------------



  • 9.  RE: Spring JMS and MQ application rebalancing with default MQ connection factory

    Posted Wed March 30, 2022 01:48 PM
    Hi Mark,

       Can you expand a bit more on this comment and/or point me to some doco that describes this behavior please?

    • Don't forget that JMS "Connections" can result in >1 MQ connection; for rebalancing purposes they are tied together based on the generated CONNTAG value

    TIA,
    Don

    ------------------------------
    Don Thomas
    ------------------------------



  • 10.  RE: Spring JMS and MQ application rebalancing with default MQ connection factory

    Posted Wed March 30, 2022 03:50 PM
    See for example https://www.imwuc.org/HigherLogic/System/DownloadDocumentFile.ashx?DocumentFileKey=b55c93fd-d2c9-21b1-4340-47b16cddc511

    ------------------------------
    Mark Taylor
    Winchester
    ------------------------------