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 » Sending Serialized Java Objects through MQ from JMS program

Post new topic  Reply to topic Goto page 1, 2  Next
 Sending Serialized Java Objects through MQ from JMS program « View previous topic :: View next topic » 
Author Message
tapak
PostPosted: Thu Jan 12, 2006 5:29 am    Post subject: Sending Serialized Java Objects through MQ from JMS program Reply with quote

Centurion

Joined: 26 Oct 2005
Posts: 149
Location: Hartford,CT

Has anyone come across any issues with sending Serialized objects through MQ from a JMS program .Is it a common practice to send Java objects through MQ instead of a text or XML message .Any guidlines to be followed on sending serialized objects .

I am developing a prototype to send a Java objects through MQ which invokes a Message Driven Bean (MDB). I was able to send the object . But when the MDB process the message , it throws a MQ Exception code 2009. Any thoughts?

Is there a sample code available for processing serialized Java object from a queue .
_________________
IBM Certified Solution Designer -- WebSphere MQ V5.3
IBM Certified Solution Designer -- WebSphere Business Integration - Message Broker V5
IBM Certified Specialist -- IBM WebSphere App Svr Advd Single Svr Ed. for Multiplatforms (Java)
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Thu Jan 12, 2006 5:35 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

There is an Object message type in JMS. I assume you're using that.

But it's a relatively poor idea to send serialized objects. If anything other than a Java program needs to read this message, you're out of luck.

If the message ever moves across a channel that happens to have data conversion enabled, you're out of luck.

If the message ever goes to a Java program that doesn't have the serialized object's class on it's classpath or available for dynamic loading, you're out of luck.

The RC 2009 should have nothing to do with this. 2009 is purely a connection error, and could be due to a lot of things.

There are lots and lots of threads discussing 2009's. Can you show us where in your code this error is thrown?
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
tapak
PostPosted: Thu Jan 12, 2006 6:33 am    Post subject: Reply with quote

Centurion

Joined: 26 Oct 2005
Posts: 149
Location: Hartford,CT

Hi Jeff ,

Thank you for the quickreply . In my case both the sending and recieving application is in Java and on same operating system . So there is no data conversion happening in the channel. My worry is that if serialization cause an issue if the object is large and no of the transactions per second is also large . I am trying to compare performance on using serialized object instead of xml message for sending the data through MQ . For xml message , we need to generate the xml object from the DataObject at the sending app and parse the xml message and create the data object . Thought that sending the serialized object may be better as the extra xml processing can be avoided . Any thoughts.?

I guess the exception 2009 I got was related to the MQ restart .When I restarted the app server i didnt got any exception . I had the same error yesterday and today , so thought that it may be due to my code. Anyway I am having issues with dynamic reloading of the class . Here is my code in the MDB.

public void onMessage(javax.jms.Message inMessage) {
System.out.println("MESSAGE BEAN: In OnMessage Method");

EmpSerObj msg = null;

try {
if (inMessage instanceof ObjectMessage) {
msg = (EmpSerObj) inMessage;
System.out.println(
"MESSAGE BEAN: Message " + "received: " + msg.toString());
} else {
System.out.println(
"Message of wrong type: " + inMessage.getClass().getName());
}

} catch (Throwable te) {
System.err.println(
"MessageBean.onMessage: " + "Exception: " + te.toString());
}

}
_________________
IBM Certified Solution Designer -- WebSphere MQ V5.3
IBM Certified Solution Designer -- WebSphere Business Integration - Message Broker V5
IBM Certified Specialist -- IBM WebSphere App Svr Advd Single Svr Ed. for Multiplatforms (Java)
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Thu Jan 12, 2006 6:38 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

It's extremely unlikely that the serialization has anything to do with your 2009 problem.

I would bet that your 2009 problem is related to failing to close connections properly - and so you are leaving channels open until you reach MAXCHANNELS on the qm. Then, when you restart the QM, those orphened channels go away, and you start again.

Another problem with using Object messages is that it is very difficult for a human to inspect a message on the queue to determine why the data in it is bad. It is also very hard to determine why you can't unserialize the object through visual inspection of the message data.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
tapak
PostPosted: Thu Jan 12, 2006 7:31 am    Post subject: Got it worked . Reply with quote

Centurion

Joined: 26 Oct 2005
Posts: 149
Location: Hartford,CT

Jeff ,

Got it working after I added the code to convert the ObjectMessage to my Java Object . I am not using connection class as the recieving application is MDB. After I restarted the App Server 2009 error code also disappeared .Here is the code I added .

public void onMessage(javax.jms.Message inMessage) {
System.out.println("MESSAGE BEAN: In OnMessage Method");

EmpSerObj msg = null;
ObjectMessage om = null;
try {
if (inMessage instanceof ObjectMessage) {
om = (ObjectMessage)inMessage;
msg =(EmpSerObj) om.getObject();
} else {
System.out.println(
"Message of wrong type: " + inMessage.getClass().getName());
}
} catch (Throwable te) {
System.err.println(
"MessageBean.onMessage: " + "Exception: " + te.toString());
}
}
_________________
IBM Certified Solution Designer -- WebSphere MQ V5.3
IBM Certified Solution Designer -- WebSphere Business Integration - Message Broker V5
IBM Certified Specialist -- IBM WebSphere App Svr Advd Single Svr Ed. for Multiplatforms (Java)
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Thu Jan 12, 2006 7:37 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

I see where we have been confused, I think.

You've been talking about an MQJMS2009 error, not an MQ Return Code of 2009.

Yes?

MQJMS errors can contain a linked exception that includes the MQ Return Code.

http://publib.boulder.ibm.com/infocenter/wmqv6/v6r0/index.jsp?topic=/com.ibm.mq.csqzaw.doc/jms77he.htm
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
tapak
PostPosted: Thu Jan 12, 2006 7:49 am    Post subject: Reply with quote

Centurion

Joined: 26 Oct 2005
Posts: 149
Location: Hartford,CT

I was getting MQ error code 2009 . I am not getting the problem anymore .I was not closing the connection in the sending obj .May be it cause the problem. Recieving app (MDB) is also in the same EAR project and the same server .Anyway I will watch if it happens again . Thank you for the information provided.
_________________
IBM Certified Solution Designer -- WebSphere MQ V5.3
IBM Certified Solution Designer -- WebSphere Business Integration - Message Broker V5
IBM Certified Specialist -- IBM WebSphere App Svr Advd Single Svr Ed. for Multiplatforms (Java)
Back to top
View user's profile Send private message
tapak
PostPosted: Thu Jan 12, 2006 8:28 am    Post subject: Reply with quote

Centurion

Joined: 26 Oct 2005
Posts: 149
Location: Hartford,CT

Got the error again . I guess it happens everytime I change the code in MDB and restart the project in WSAD5.1 . Once the project is restarted ,and the first message comes to the queue ,the exception occurs. after 60 sec Port restart successfully and the message is processed fine . I guess it is something related to the handling of connection by WAS. When I restart the was after changing MDB ,it doesnt cause an issue .

[1/12/06 11:13:23:825 EST] 449bb9b1 SystemOut O Message Sent
[1/12/06 11:13:23:825 EST] 4d20b9b2 WASLogger E CLASSNAME METHODNAME rollback failed
[1/12/06 11:13:23:856 EST] 449bb9b1 WebGroup I SRVE0180I: [J2EEPrjWeb] [/J2EEPrjWeb] [Servlet.LOG]: /EmployeeData.jsp: init
[1/12/06 11:13:23:856 EST] 449bb9b1 SystemOut O Before Conn
[1/12/06 11:13:23:841 EST] 4d20b9b2 JMSExceptionL E WMSG0018E: Error on JMSConnection for MDB MDBProcessSerObj , JMSDestination jms/javaobjq : javax.jms.JMSException: MQJMS1025: failed to browse message
at com.ibm.mq.jms.services.ConfigEnvironment.newException(ConfigEnvironment.java:540)
at com.ibm.mq.jms.MQQueueAgentThread1Impl.browse(MQQueueAgentThread1Impl.java:441)
at com.ibm.mq.jms.MQQueueAgentThread.run(MQQueueAgentThread.java:1602)
at java.lang.Thread.run(Thread.java:568)
---- Begin backtrace for Nested Throwables
com.ibm.mq.MQException: MQJE001: Completion Code 2, Reason 2009
at com.ibm.mq.jms.MQQueueAgentThread1Impl.browseMsg(MQQueueAgentThread1Impl.java:554)
at com.ibm.mq.jms.MQQueueAgentThread1Impl.browse(MQQueueAgentThread1Impl.java:384)
at com.ibm.mq.jms.MQQueueAgentThread.run(MQQueueAgentThread.java:1602)
at java.lang.Thread.run(Thread.java:568)

[1/12/06 11:13:23:872 EST] 4d20b9b2 JMSExceptionL E WMSG0057E: Error on JMSConnection for MDB MDBProcessSerObj , JMSDestination jms/javaobjq , JMS Linked Exception : com.ibm.mq.MQException: MQJE001: Completion Code 2, Reason 2009
at com.ibm.mq.jms.MQQueueAgentThread1Impl.browseMsg(MQQueueAgentThread1Impl.java:554)
at com.ibm.mq.jms.MQQueueAgentThread1Impl.browse(MQQueueAgentThread1Impl.java:384)
at com.ibm.mq.jms.MQQueueAgentThread.run(MQQueueAgentThread.java:1602)
at java.lang.Thread.run(Thread.java:568)
_________________
IBM Certified Solution Designer -- WebSphere MQ V5.3
IBM Certified Solution Designer -- WebSphere Business Integration - Message Broker V5
IBM Certified Specialist -- IBM WebSphere App Svr Advd Single Svr Ed. for Multiplatforms (Java)
Back to top
View user's profile Send private message
wschutz
PostPosted: Thu Jan 12, 2006 9:53 am    Post subject: Reply with quote

Jedi Knight

Joined: 02 Jun 2005
Posts: 3316
Location: IBM (retired)

Quote:
In my case both the sending and recieving application is in Java and on same operating system .
Does this mean WAS and MQ are on the same machine also? If so, why are you using the MQ client bindings, you could use a direct server binding (and get better performance).
_________________
-wayne
Back to top
View user's profile Send private message Send e-mail AIM Address
tapak
PostPosted: Thu Jan 12, 2006 10:00 am    Post subject: Reply with quote

Centurion

Joined: 26 Oct 2005
Posts: 149
Location: Hartford,CT

MQ and WAS in the same machine and I am using local bindings.for the prototype development. Not sure if I specified client binding somewhere.
_________________
IBM Certified Solution Designer -- WebSphere MQ V5.3
IBM Certified Solution Designer -- WebSphere Business Integration - Message Broker V5
IBM Certified Specialist -- IBM WebSphere App Svr Advd Single Svr Ed. for Multiplatforms (Java)
Back to top
View user's profile Send private message
wschutz
PostPosted: Thu Jan 12, 2006 10:02 am    Post subject: Reply with quote

Jedi Knight

Joined: 02 Jun 2005
Posts: 3316
Location: IBM (retired)

Good, I was just reacting to Jeff's comment:
Quote:
I would bet that your 2009 problem is related to failing to close connections properly - and so you are leaving channels open until you reach MAXCHANNELS on the qm. Then, when you restart the QM, those orphened channels go away, and you start again.


So you are saying you're getting a 2009 from server bindings?
_________________
-wayne
Back to top
View user's profile Send private message Send e-mail AIM Address
tapak
PostPosted: Thu Jan 12, 2006 10:30 am    Post subject: Reply with quote

Centurion

Joined: 26 Oct 2005
Posts: 149
Location: Hartford,CT

Yes. For jms connection factory , I specified the transport type as binding mode not the client mode.
_________________
IBM Certified Solution Designer -- WebSphere MQ V5.3
IBM Certified Solution Designer -- WebSphere Business Integration - Message Broker V5
IBM Certified Specialist -- IBM WebSphere App Svr Advd Single Svr Ed. for Multiplatforms (Java)
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Thu Jan 12, 2006 3:44 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

tapak wrote:
Yes. For jms connection factory , I specified the transport type as binding mode not the client mode.


What is your version (5.3 ?) and CSD ? Be aware that CSD 8,9,10 are not optimal for JMS although I don't think it has much influence on a bindings connection. You should go to CSD 11.

_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
fjb_saper
PostPosted: Thu Jan 12, 2006 3:53 pm    Post subject: Re: Got it worked . Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

tapak wrote:
Here is the code I added .

public void onMessage(javax.jms.Message inMessage) {
System.out.println("MESSAGE BEAN: In OnMessage Method");

EmpSerObj msg = null;
ObjectMessage om = null;
try {
if (inMessage instanceof ObjectMessage) {
om = (ObjectMessage)inMessage;
msg =(EmpSerObj) om.getObject();
} else {
System.out.println(
"Message of wrong type: " + inMessage.getClass().getName());
}
} catch (Throwable te) {
System.err.println(
"MessageBean.onMessage: " + "Exception: " + te.toString());
}
}


You should code a little bit better:
Code:
public void onMessage(javax.jms.Message inMessage) {
      System.out.println("MESSAGE BEAN: In OnMessage Method");

EmpSerObj msg = null;
ObjectMessage om = null;
try {
if (inMessage instanceof ObjectMessage) {
om = (ObjectMessage)inMessage;
msg =(EmpSerObj) om.getObject();
} else {
System.out.println(
"Message of wrong type: " + inMessage.getClass().getName());
         }
}catch (ClassCastException cce){
   System.err.println("wrong class in object");
} catch (JMSException jmse){
   LinkedException le = jmse.getLinkedException();
   String mes = null ;
   if (le==null){
     mes = jmse.getMessage();
   }else{
     mes = le.getMessage();
   }//endif
   System.err.println(mes);
} catch (Throwable te) {
System.err.println(
            "MessageBean.onMessage: " + "Exception: " + te.toString());
}
}


Of course you can extract the object as object and check the class before the cast...
Enjoy
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
tapak
PostPosted: Fri Jan 13, 2006 5:40 am    Post subject: Reply with quote

Centurion

Joined: 26 Oct 2005
Posts: 149
Location: Hartford,CT

Thank you for the code . I am not getting the exception .It happens when I chnage the message driven bean in WSAD and deploy it in the wsad test environment without restarting WAS . I guess it is related to the way WAS handles MQ connection .
_________________
IBM Certified Solution Designer -- WebSphere MQ V5.3
IBM Certified Solution Designer -- WebSphere Business Integration - Message Broker V5
IBM Certified Specialist -- IBM WebSphere App Svr Advd Single Svr Ed. for Multiplatforms (Java)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Goto page 1, 2  Next Page 1 of 2

MQSeries.net Forum Index » IBM MQ Java / JMS » Sending Serialized Java Objects through MQ from JMS program
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.