ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ Java / JMS » [Solved] can't see a message in queue

Post new topic  Reply to topic
 [Solved] can't see a message in queue « View previous topic :: View next topic » 
Author Message
texan
PostPosted: Wed Feb 25, 2004 12:07 pm    Post subject: [Solved] can't see a message in queue Reply with quote

Acolyte

Joined: 25 Feb 2004
Posts: 74

I am new to JMS Programming. I have a mq server installed on my machine(version 5.3, Windows XP). I am using file based JNDI to lookup mq objects. I wrote the following porogram to put a message on queue, I am n't getting any exceptions but I can't see the message on Queue? Can somebody help in debugging this? Thanx in advance.


Here is the code:

package com.test.jms;

import java.util.Hashtable;

import javax.jms.DeliveryMode;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class MyJMSSender {

/**
* Constructor for MyJMSSender.
*/
public MyJMSSender() {
super();
}

public Context getContext(){
Hashtable hashtable = new Hashtable();
hashtable.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.RefFSContextFactory");
hashtable.put(Context.PROVIDER_URL,"file://C:/Program Files/IBM/WebSphere MQ/Java/JNDI/jms");
Context context = null;
try{
context = new InitialContext(hashtable);
}catch(NamingException ne){
ne.printStackTrace();
}

return context;
}

public Object getJMSObject(String jndiName){
Context context = getContext();
if(context == null){
return null;
}

Object object = null;
try{
object = context.lookup(jndiName);
}catch(NamingException ne){
ne.printStackTrace();
}
return object;
}

public int sendMessage(String message){
Object obj = getJMSObject("myQCF");
if(obj != null){
System.out.println(obj.getClass());
}
//lookup QueueConnectionFactory
QueueConnectionFactory queueConnectionFactory =
(QueueConnectionFactory)getJMSObject("myQCF");
if(queueConnectionFactory == null){
System.out.println("Could n't get QueueConnectionFactory");
return -1;
}else{
System.out.println("QueueConnectionFactory Object obtained from JNDI..");
}

//look up queue name to put a message on it.
Queue requestQueue = (Queue)getJMSObject("myFirstQueue");
if(requestQueue == null){
System.out.println("Could n't get Queue");
return -1;
}else{
System.out.println("Queue Object obtained from JNDI..");
}

QueueConnection queueConnection = null;
try{
System.out.println(requestQueue.getQueueName());
//create QueueConnection.
queueConnection = queueConnectionFactory.createQueueConnection();
System.out.println("QueueConnection object created...");

//start queue connection
queueConnection.start();
System.out.println("Queue Connection Started..");

//create Queue Session
QueueSession queueSession = queueConnection.
createQueueSession(true,0);
System.out.println("QueueSession created..");

//create Sender
QueueSender queueSender = queueSession.
createSender(requestQueue);
System.out.println("QueueSender created..");

//create mesage object that you want to send
TextMessage textMessage = queueSession.createTextMessage();

textMessage.setText(message);
queueSender.send(textMessage,DeliveryMode.PERSISTENT,5,0);
System.out.println("Send Completed..");
System.out.println("Message id is:"+textMessage.getJMSMessageID());
}catch(JMSException je){
je.printStackTrace();
return -1;
}catch(Exception e){
e.printStackTrace();
}finally{
//close objects
try{
if(queueConnection != null){
System.out.println("Closing Queue Connection...");
queueConnection.stop();
queueConnection.close();
queueConnection = null;
System.out.println("Queue Connection Closed...");
}
}catch(JMSException je){
System.out.println("Exception while cleaning JMS Connection object");
}
}

return 0;

}

public static void main(String[] args) {
MyJMSSender sender = new MyJMSSender();
int retValue = sender.sendMessage("Hello, World");
System.out.println(retValue);
}
}
Back to top
View user's profile Send private message
vennela
PostPosted: Wed Feb 25, 2004 12:16 pm    Post subject: Reply with quote

Jedi Knight

Joined: 11 Aug 2002
Posts: 4055
Location: Hyderabad, India

I could compile and run you program successfully and I could see the message.

How are you trying to see the message?
Where is the QMGR that your QCF is pointing to

What is the MQ QMGR name and MQ Queue name.?

You can do
Code:

amqsbcg QUEUENAME QMGRNAME
on a command promt to see the message.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
texan
PostPosted: Wed Feb 25, 2004 12:39 pm    Post subject: Reply with quote

Acolyte

Joined: 25 Feb 2004
Posts: 74

I am trying to see the message in MQExplorer. I right clicked on Queue to browse messages but I can't see anything. current depth is always "0".

The actual QManager name is:QM_itec0619 and Queuname is "myFirstQueue". JNDI names are: "myQCF" and "myFirstQueue".

I executed the command you gave me:

Here is the output fro that command.

AMQSBCG0 - starts here
**********************

MQOPEN - 'myFirstQueue'



No more messages
MQCLOSE
MQDISC
Back to top
View user's profile Send private message
gunter
PostPosted: Thu Feb 26, 2004 1:58 am    Post subject: Reply with quote

Partisan

Joined: 21 Jan 2004
Posts: 307
Location: Germany, Frankfurt

Please, post the settings in JNDI.
Back to top
View user's profile Send private message
texan
PostPosted: Thu Feb 26, 2004 4:42 am    Post subject: Reply with quote

Acolyte

Joined: 25 Feb 2004
Posts: 74

What do you mean by settings in JNDI?

My JNDI names are "myQCF" and "myFirstQueue" for QM and Queue respectively. I am using file based JNDI. If you want I can send .bindings that was generated when I ran JMSAdmin.bat file. Both QueueManager and Queue are residing on my local MQ Server.

Can you suggest me atleast how to debug these kind of problems? Is there anyway I can see some logs or enable trace. I checked the logs under MQSeries but they wrere n't even updated.

I can put messages on Queue from Explorer. Please help me.

Thanks in advance.
Back to top
View user's profile Send private message
gunter
PostPosted: Thu Feb 26, 2004 6:10 am    Post subject: Reply with quote

Partisan

Joined: 21 Jan 2004
Posts: 307
Location: Germany, Frankfurt

Sorry, there is nothing to found in JNDI.

The reason fore your problem is this code
Code:

 //create Queue Session
QueueSession queueSession = queueConnection.createQueueSession(true,0);


The first parameter(true) has the effect, that all maessages will be put in a "unit of work".
Use false or make after queueSender.send(...) queueSession.commit();
Back to top
View user's profile Send private message
texan
PostPosted: Thu Feb 26, 2004 7:38 am    Post subject: Reply with quote

Acolyte

Joined: 25 Feb 2004
Posts: 74

Gunter,

It worked like a champ. Thank you so much.

I have couple of questions. Now I can see the message in a queue. Then I right clicked, select browse message and highlighted the message and then selected properties. Clicked on data tab. It is showng data in hexa decimal. TeXt radio button is disabled. Do you know why? When I put messages directly through MQ Eplorer, i am able to see text but n't when I sent it through java.

The other question is: Which connection did it use? I mean bindings mode or TCP/IP mode. Since everything on single machine, I am assuming it will use bindings mode. But I heard bindings mode is deprecated now.

If I want to put message on QueueManager that is running on a different machine what should I do? Thanks in advance.
Back to top
View user's profile Send private message
vennela
PostPosted: Thu Feb 26, 2004 7:56 am    Post subject: Reply with quote

Jedi Knight

Joined: 11 Aug 2002
Posts: 4055
Location: Hyderabad, India

Quote:
Which connection did it use? I mean bindings mode or TCP/IP mode.


It depends on how you defined your QueueConnectionFactory object.

Quote:
But I heard bindings mode is deprecated now.

This is not true

Quote:
If I want to put message on QueueManager that is running on a different machine what should I do?

You should define your QueueConnectionFactory such that it has the hostname of the machine where the QMGR is running port number the listener is running and the SVRCONN channel name
Back to top
View user's profile Send private message Send e-mail Visit poster's website
jefflowrey
PostPosted: Thu Feb 26, 2004 8:12 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

texan wrote:
Now I can see the message in a queue. Then I right clicked, select browse message and highlighted the message and then selected properties. Clicked on data tab. It is showng data in hexa decimal. TeXt radio button is disabled. Do you know why? When I put messages directly through MQ Eplorer, i am able to see text but n't when I sent it through java.


I bet what's going on is that, although you are writing a TextMessage object, you are writing to a JMS destination type, instead of an MQ destination type. This is set as an option on your Queue Destination object in the JNDI.

When using a JMS destination, the send method writes out an MQRFH2 header that includes the JMS properties of the message object (setProperty).
Thus, when looking at the raw message on the queue, the Format of the message will be an MQFMT_RFH2 or some such, instead of MQFMT_STRING

Which means that Explorer will only show you the hex values, instead of the text.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
texan
PostPosted: Thu Feb 26, 2004 12:57 pm    Post subject: Reply with quote

Acolyte

Joined: 25 Feb 2004
Posts: 74

Quote:
I bet what's going on is that, although you are writing a TextMessage object, you are writing to a JMS destination type, instead of an MQ destination type. This is set as an option on your Queue Destination object in the JNDI.


i am new to jms. Can you tell me what do you mean by am writing to a jms destination type?
I did n't set any option on Queue Destination object in JNDI. I do n't even know how to set. What should I do to see regular text?
Back to top
View user's profile Send private message
texan
PostPosted: Thu Feb 26, 2004 1:03 pm    Post subject: Reply with quote

Acolyte

Joined: 25 Feb 2004
Posts: 74

Quote:
It depends on how you defined your QueueConnectionFactory object.

using JMDAdmin.bat, I defined as "def qcf(myQCF) qmgr(QM_itec0619)" I did n't specify any host name or port no. Now If I want to sepcify di I have to do in a java program or can I do through JNDI.

Quote:
You should define your QueueConnectionFactory such that it has the hostname of the machine where the QMGR is running port number the listener is running and the SVRCONN channel name

how to find out the port no. of listener?

Thanks in advance.
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Thu Feb 26, 2004 1:08 pm    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

The property you want to change to prevent the creation of the MQRFH2 header is the TARGCLIENT property.
According to the Using Java manual, in Chapter 5 in the Administering JMS Objects section, it takes two values:
JMS - The target of the message is a JMS application.
MQ - The target of the message is a non-JMS WebSphere MQ application.

You will want to ALTER your MQQueue definition to have a TARGCLIENT of MQ.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
vennela
PostPosted: Thu Feb 26, 2004 1:38 pm    Post subject: Reply with quote

Jedi Knight

Joined: 11 Aug 2002
Posts: 4055
Location: Hyderabad, India

Quote:
Now If I want to sepcify di I have to do in a java program or can I do through JNDI.

Since Jeff didn't answer this part of the question I can answer.

You can use JMSAdmin tool to alter the QCF object and specify the hostname , port number and channel

How to do it. Refer to :
Using Java manual, in Chapter 5

Quote:
how to find out the port no. of listener?

What platform are you running your QMGR on.

Assuming Windows:
If you open WebSphere MQ Services, under the Queue Manager, there is a listener. If you lokk in the properties, it will tell you what port the listener is running on.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
jefflowrey
PostPosted: Thu Feb 26, 2004 1:49 pm    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

vennela wrote:
Since Jeff didn't answer this part of the question I can answer.

That part of his question was in response to comments from you. I didn't want to answer for you...
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
texan
PostPosted: Thu Feb 26, 2004 8:49 pm    Post subject: Reply with quote

Acolyte

Joined: 25 Feb 2004
Posts: 74

Thank you all. Now am able to see messages in queue in plain text. This is really a great forum. I appreaciate all your time and help.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » [Solved] can't see a message in queue
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.