ibm-messaging / mq-dev-samples

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

Compiled JmsPutGet.java executes ok but no message placed in the queue #22

Closed estreetco closed 7 months ago

estreetco commented 8 months ago

I'm running these tutorial instructions using a couple different Docker MQ images, both 9.2.0 and 9.3.5. When I execute JmsPut.class, I get the expected output showing me the lucky number:

java -cp `.\com.ibm.mq.allclient-9.3.0.0.jar;.\javax.jms-api-2.0.1.jar;.\json-20220320.jar;.' com.ibm.mq.samples.jms.JmsPutGet
Sent message:

  JMSMessage class: jms_text
  JMSType:          null
  JMSDeliveryMode:  2
  JMSDeliveryDelay: 0
  JMSDeliveryTime:  1710285567365
  JMSExpiration:    0
  JMSPriority:      4
  JMSMessageID:     ID:414d5120514d312020202020202020200e8ef06501d00440
  JMSTimestamp:     1710285567365
  JMSCorrelationID: null
  JMSDestination:   queue:///DEV.QUEUE.1
  JMSReplyTo:       null
  JMSRedelivered:   false
    JMSXAppID: JmsPutGet (JMS)
    JMSXDeliveryCount: 0
    JMSXUserID: app
    JMS_IBM_PutApplType: 28
    JMS_IBM_PutDate: 20240312
    JMS_IBM_PutTime: 23192739
Your lucky number today is 336

Received message:
Your lucky number today is 336
SUCCESS

However, when I go into my MQ console, I don't see the actual message in queue DEV.QUEUE.1. All my queues show 0 messages. I tried a bunch of different tests on both MQ versions, and I get the same results. If I use the amqsput command to manually put a message on the same qm/queue, it works just fine.

Anyone see this before or have any ideas what could be wrong?

chughts commented 8 months ago

The configuration for the sample is hard-coded in the .java file. So that anytime the configuration needs to be modified, the .java code needs to be recompiled.

estreetco commented 8 months ago

The configuration for the sample is hard-coded in the .java file. So that anytime the configuration needs to be modified, the .java code needs to be recompiled.

Thanks for your reply, although it doesn't really address my problem. I did modify the script and compiled it, but after running I don't see the new message in my queue. Do you have any idea what might cause this, and could there be an issue with the Java program itself?

chughts commented 8 months ago

If there was an error in putting the message the application would have reported it in the output. To check, change the queue to one that you know doesn't exist. ie. one of wrong queue manager, wrong channel, wrong queue.

If you don't see an error message, then the application you are changing is not the application you are running.

If you do see an error, then some other application is reading the message off the queue. Try putting a message on the queue using the console, leave it there, then run the application.

estreetco commented 8 months ago

If there was an error in putting the message the application would have reported it in the output. To check, change the queue to one that you know doesn't exist. ie. one of wrong queue manager, wrong channel, wrong queue.

If you don't see an error message, then the application you are changing is not the application you are running.

If you do see an error, then some other application is reading the message off the queue. Try putting a message on the queue using the console, leave it there, then run the application.

Good tips. I tried what you suggested, and even adjusted with various other invalid items like QM name, password, etc. All changes ended up producing a Java exception, which was expected. But when I switch back to the correct parameters, I still don't see the message in the queue. I checked my system and I am not running any other MQ or program which might pick up the message (to the best of my knowledge).

I thought perhaps the version of my JDK might be at issue. So I downloaded the latest OpenJDK which is linked in the IBM tutorial (11.0.22.0, OpenJDK 11.0.22+7, OpenJ9 0.43.0). I re-downloaded all the required jars again including the JmsPutGet.java, edited the file and recompiled, this time using the regular DOS command prompt window instead of PowerShell. But still the same result. Lucky number is generated, and all program output looks good but there is no message actually seen in DEV.QUEUE.1.

Here are the parameters I am using in my JavaPutGet:

    // Create variables for the connection to MQ
    private static final String HOST = "mq"; // Host name or IP address
    private static final int PORT = 1414; // Listener port for your queue manager
    private static final String CHANNEL = "DEV.APP.SVRCONN"; // Channel name
    private static final String QMGR = "QM1"; // 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"; // Password that the application uses to connect to MQ
    private static final String QUEUE_NAME = "DEV.QUEUE.1"; // Queue that the application uses to put and get messages to and from

I'm using Docker image ibmcom/mq:9.2.0.0-r1 and the newest one from icr.io/ibm-messaging/mq:latest (v9.3.5). The hostname "mq" above is mapped to 127.0.0.1 in my hosts file, and I also tried using 127.0.0.1 directly.

So strange, but I am sure there is some simple reason causing this. Is it working for you and which MQ version are you using?

chughts commented 7 months ago

If you are running the PutGet sample then there will be no net change in the queue, as the sample puts a message then retrieves it.

If there is a message already in the queue, then that message will be replaced by the one the PutGet puts on the queue.

estreetco commented 7 months ago

So are you saying then that it is normal to observe the queue as being empty after running the JavaPutGet program? I am just going by the turoial, which at the very end mentions the message appearing in the queue afterwards when you look at the console. Have you actually run this program and what are you seeing on your end? What version of MQ are you running it against?

chughts commented 7 months ago

There are three samples in this part of this repo:

If you want to see the message on the console then you need to download, compile and run JmsPut

I should have seen this in the output you posted, but read JmsPut and incorrectly concluded that that was running. The tell-tale signature in the output that you are running JmsPutGet is:

Received message:
Your lucky number today is 336
SUCCESS

This is the Get bit of JmsPutGet

This bit puts the message

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

This bit gets the message back

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

            System.out.println("\nReceived message:\n" + receivedMessage);
estreetco commented 7 months ago

Ahh ok, this clears up the mystery! 🤦‍♂️That makes sense too, as the filename says "PutGet" and I never considered that. Sorry, I was not previously familiar with the part of the Java code which gets the message at the end. I was just going by the part in the tutorial at the end which mentioned observing the message in the console.

I commented out the Get part you highlighted, and re-compiled. This time I can see the message in the queue. The very last part of the output is also not shown (ie. Received message: Your lucky number today is xx).

Thanks a lot for your help and input on this! Really appreciate it.