简体   繁体   中英

MQ client application connect to a client

I wrote a client application to connect to MQ. It is working fine on svrconn channel, but not working on other channels.

My code:

try {
    // Create a connection factory
    JmsFactoryFactory ff = JmsFactoryFactory.getInstance(WMQConstants.WMQ_PROVIDER);
    JmsConnectionFactory cf = ff.createConnectionFactory();

    // Set the properties
    cf.setStringProperty(WMQConstants.WMQ_HOST_NAME, HOST);
    cf.setIntProperty(WMQConstants.WMQ_PORT, PORT);
    cf.setStringProperty(WMQConstants.WMQ_CHANNEL, CHANNEL);
    cf.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT);
    cf.setStringProperty(WMQConstants.WMQ_QUEUE_MANAGER, QMGR);
    cf.setStringProperty(WMQConstants.WMQ_APPLICATIONNAME, "JmsPutGet (JMS)");
    cf.setBooleanProperty(WMQConstants.USER_AUTHENTICATION_MQCSP, true);
    cf.setStringProperty(WMQConstants.USERID, APP_USER);
    cf.setStringProperty(WMQConstants.PASSWORD, APP_PASSWORD);

    // Create JMS objects
    context = cf.createContext();
    destination = context.createQueue("queue:///" + QUEUE_NAME);

    long uniqueNumber = System.currentTimeMillis() % 1000;
    TextMessage message = context.createTextMessage("Your lucky number today is " + uniqueNumber);

    producer = context.createProducer();
    producer.send(destination, message);
    System.out.println("Sent message:\n" + message);

    consumer = context.createConsumer(destination); // autoclosable
    String receivedMessage = consumer.receiveBody(String.class, 15000); // in ms or 15 seconds

    System.out.println("\nReceived message:\n" + receivedMessage);

    recordSuccess();
}

Please help with these 2 questions:

  1. How can I connect to a qmgr which is in client mode?
  2. How can I make this code connect to other channels as well?

Right now, when I try to use other channel it gives below error:

JMSWMQ0018: Failed to connect to a queue manager 'qmgr name' with connection mode 'Client'

You have specified the channel name in, cf.setStringProperty(WMQConstants.WMQ_CHANNEL, CHANNEL);

If you use cf.setStringProperty(WMQConstants.WMQ_CHANNEL, "MYOTHERCHANNEL"); it would try to use that channel name instead of what you had specified

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM