ibm-messaging / mq-dev-samples

Samples for getting started with IBM MQ
Apache License 2.0
69 stars 108 forks source link

Unable to connect to local queue manager in created in MQ Explorer #10

Closed fshi7418 closed 3 years ago

fshi7418 commented 3 years ago

Hello,

I set up a local queue manager via MQ Explorer (v 9.2.2.0, Windows 10) via this tutorial: https://www.ibm.com/docs/en/ibm-mq/8.0?topic=tutorials-tutorial-1-sending-message-local-queue and then I try to run JmsPutGet with the method here: https://developer.ibm.com/components/ibm-mq/tutorials/mq-develop-mq-jms but haven't been able to get it to work.

In particular, I have tried to set up the constants in the script to put/get a message from the queue manager, as follows:

    private static final String HOST = "localhost"; // Host name or IP address
private static final int PORT = 1414; // Listener port for your queue manager
private static final String CHANNEL = "SYSTEM.DEF.SVRCONN"; // Channel name
private static final String QMGR = "QM_APPLE"; // Queue manager name
private static final String APP_USER = "app"; // User name that application uses to connect to MQ
private static final String APP_PASSWORD = "passw0rd"; // API key
private static final String QUEUE_NAME = "Q1"; // Queue that the application uses to put and get messages to and from

I then compile the file with the following command in Windows command line: javac -cp .\com.ibm.mq.allclient-9.1.4.0.jar;.\javax.jms-api-2.0.1.jar com\ibm\mq\samples\jms\JmsPutGet.java

Then I try to run the compiled program with: java -cp .\com.ibm.mq.allclient-9.1.4.0.jar;.\javax.jms-api-2.0.1.jar;. com.ibm.mq.samples.jms.JmsPutGet

I get a error with reason code 2035 and completion code 2. I have tried numerous ways to fix the issue, such as the ones listed here and here, but still get the same error.

I've also tried to change channel to DEV.APP.SVRCONN, but that gives an error with reason code 2540.

The task of put/get to a local queue should be straightforward but for whatever reason I haven't been able to get it to work... If you could provide any help at all, I would really appreciate it.

Many thanks, Frank

maxkahan commented 3 years ago

Edit: adding context

Hi Frank,

Thanks for getting in touch. Firstly, I want to reassure you that your java steps look correct.

I am assuming you have taken the following steps:

  1. Installed MQ on Windows,
  2. Been through all the steps of the Set up MQ tutorial you mention above (https://www.ibm.com/docs/en/ibm-mq/9.2?topic=tutorials-tutorial-1-sending-message-local-queue) - including putting a test message using amqsputc in bindings mode
  3. Did not try amqsputc in client mode (the mode where you connect with a Java client application in your question)
  4. You followed this tutorial https://developer.ibm.com/components/ibm-mq/tutorials/mq-develop-mq-jms - to try to run a Java MQ Client app (in client mode) on the same machine. 5 . Did not run setmqaut MQSC steps.

Note: 2035 is MQRC_NOT_AUTHORIZED

I believe that your application may not be authorised to communicate with IBM MQ. In client mode, there must be a Windows group with authorisation granted to access MQ queues and put messages via channels.

Firstly, I would strongly recommend this tutorial: https://developer.ibm.com/tutorials/mq-connect-app-queue-manager-windows/

It includes the step of configuring your queue manager with some sensible developer default objects, including queues and channels, and the step of authorising the group to connect to MQ.

Note: if you follow the tutorial above, you will create a Windows user "mqclient" and authorise group members to access only queues with names beginning "DEV." If you want to use your queue with the name Q1, change the line in Step 5 from

setmqaut -m QM1 -n DEV.** -t queue -g mqclient +put +get +browse +inq to setmqaut -m QM1 -n Q1 -t queue -g mqclient +put +get +browse +inq

Once you've done this, you should be able to follow the steps in the Java tutorial and send messages with MQ.

This is explained on some level in this IBM Documentation tutorial https://www.ibm.com/docs/en/ibm-mq/9.2?topic=tutorials-tutorial-3-sending-message-client-server-configuration but we wrote the tutorial on IBM Developer to make this whole process clearer.

Let me know how you get on with it!

Max

fshi7418 commented 3 years ago

Hello Max,

Thank you for your prompt reply. It worked!

Before I did not complete this tutorial because I hit a bottleneck when I tried to add local groups and users. I am on Windows 10 Home, so my PC manager wouldn't let me add groups/users there. I didn't know this was actually important so I just left the tutorial.

On Windows 10 (Home) all I had to do is run cmd as admin, then use net localgroup mqclient /add to add a local group called mqclient. Then, I go to Control Panel to add a local user called "app" with the password "passw0rd". Finally I go back to cmd and use net localgroup mqclient app /add to add "app" into the "mqclient" group.

And then after that everything worked as intended.

Thanks a lot, Frank

maxkahan commented 3 years ago

Glad to hear it worked Frank! Yes, Windows manages authorisation when you connect in this way so creating the groups is very important here.

Max