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 » WebSphere MQ base Vs WebSphere MQ JMS

Post new topic  Reply to topic Goto page Previous  1, 2
 WebSphere MQ base Vs WebSphere MQ JMS « View previous topic :: View next topic » 
Author Message
fjb_saper
PostPosted: Mon Feb 13, 2006 3:55 am    Post subject: Reply with quote

Grand High Poobah

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

viki wrote:
Hi,
The code:
Code:
BytesMessage bm = session.createBytesMessage();
System.out.println(bm.getClass().getName());

is returning com.ibm.jms.JMSBytesMessage

However, the code:
Code:
if (bm instanceof javax.jms.BytesMessage)
System.out.println("True BytesMessage");

is returning True BytesMessage. How it is possible that bm.getClass().getName() is returning com.ibm.jms.JMSBytesMessage whereas bm instanceof javax.jms.BytesMessage is returning true?? Something going fishy here Or I'm missing something


You are indeed missing something. The class returns true for instanceof because com.ibm.jms.JMSBytesMessage has been declared with
Code:
public class com.ibm.jms.JMSBytesMessage implementing javax.jms.BytesMessage {...}


viki wrote:
Coming to the 2nd issue, How can I confirm that message via queueSender.send(bm); is send successfully?

As long as you don't receive an Exception(JMSException or any other Exception) on any of the lines leading up to the session.commit(), including the commit call your message made it onto the queue.

viki wrote:
For this I'm doing:
Code:
Message inMessage = queueReceiver.receive();
session.commit();
  if (inMessage instanceof javax.jms.BytesMessage) {
       ((javax.jms.BytesMessage) inMessage).readBytes(buf);
       for(int i =0; i<buf.length;i++){
         System.out.println("buf["+ i +"] = "+buf[i]);
   }//if closed.       

Output:
Code:
buf[0] = 115
buf[1] = 108
buf[2] = 115
buf[3] = 108
buf[4] = 13
.
.
.
buf[1023] = 13

This output is in bytes? But how can I retrieve the same message (originally the IO Stream which I write to the message) and build the same file? If this is done, then this means file sending and recieving is working OK!

Looking for your further help.

Thanks,
Bye,
Viki.


You do not need to do the commit right after the read.
If you want to see the content as a file you should extract the bytes and put them to the FileOutputStream....

Enjoy
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
viki
PostPosted: Tue Feb 14, 2006 6:14 am    Post subject: Reply with quote

Acolyte

Joined: 07 Feb 2006
Posts: 50

fjb_saper wrote:

As long as you don't receive an Exception(JMSException or any other Exception) on any of the lines leading up to the session.commit(), including the commit call your message made it onto the queue.

Ok! No exception is generated. And here is how I've conformed the message delivery . Open
WebSphere MQ Explorer --> Console Root --> WebSphere MQ --> Queue Managers --> QM_MyQueueManager --> Queues --- > Right Click QueueName --> Browse Messages

If the message is delievered successfully, then it must show in Browse Messages. In my case it is showing.

So far so good. I've also changed my architecture. Now using two machines. One is WebSphere MQ Client and another is WebSphere MQ Installed with all options. Connection to the remote queue is succcessfull and data delivery too.

Error: I'm getting error while recieveing data. Data recieved is sometimes ok and sometimes not. On executing Java program multiple times and changing file contents, it shows previous (old) data on recieving. Here is the recieving code:
Code:
queueReceiver = session.createReceiver(q);
Message inMessage = queueReceiver.receive();
  byte[] bytes = new byte[(int)bytes.length];
   
      ((javax.jms.BytesMessage) inMessage).reset();
     if (inMessage instanceof javax.jms.BytesMessage) {
         ((javax.jms.BytesMessage) inMessage).readBytes(bytes);
          for(int i =0; i<bytes.length;i++){
             System.out.println("bytes["+i+"] = "+bytes[i]);
           }// for closed.
     }// if closed.        

The statement System.out.println("bytes["+i+"] = "+bytes[i]); above prints the ASCII of data recieved from the queue. It sometimes prints the old data, sometimes new, sometimes both old and new. However, evertytime the data length (i.e. bytes.length) is correct as of the data length send on the queue.

Don't know why it's happening. Shall I've to delete the queue everytime before I send the new message? Or is there any history/session like problem?

How queueReceiver.receive(); works? Because there are many messages present/lying on the queue. Now which messages and on what basis the queueReceiver.receive(); recieves. Is there something like FIFO,LIFO,LILO (Last In Last Out)?

Thanks,

Bye,
Viki.
Back to top
View user's profile Send private message
BenR
PostPosted: Tue Feb 14, 2006 8:57 am    Post subject: Reply with quote

Acolyte

Joined: 31 Jan 2006
Posts: 60
Location: Hursley, UK

The short answer is that receives are FIFO. The long answer is that it's complicated by a number of factors including message priority, selectors, transactionality etc. The JMS spec defines what's involved with message ordering.

On a general note, it's usually not a great idea to use queueReceiver.receive() because it's a blocking call that waits for a message to become available - if no message arrives it blocks forever, causing your application to hang. queueReceiver.receive(int timeout) is usually better. If delivery is really asynchronous (i.e. you have no real idea when a message will arrive) then use onMessage()
Back to top
View user's profile Send private message Visit poster's website
jefflowrey
PostPosted: Tue Feb 14, 2006 8:59 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

Also, if messages are not getting permanently removed from the queue, then you likely have an issue with your transactions where you are not properly commiting the receives.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Tue Feb 14, 2006 4:18 pm    Post subject: Reply with quote

Grand High Poobah

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

The proper commit on the receive should be after the file has been successfully written. This will remove the message from the queue.

Enjoy
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
viki
PostPosted: Wed Feb 15, 2006 7:55 am    Post subject: Reply with quote

Acolyte

Joined: 07 Feb 2006
Posts: 50

fjb_saper wrote:
The proper commit on the receive should be after the file has been successfully written. This will remove the message from the queue.

Enjoy


That's simply gr88!!! It works..

Almost all the issues are fixed. File contents are transfering successfully and recieving as well.

Now working over making connection using JNDI. Right now, connection is made @ runtime using factories.

Thanks buddy!!

Bye,
Viki.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Goto page Previous  1, 2 Page 2 of 2

MQSeries.net Forum Index » IBM MQ Java / JMS » WebSphere MQ base Vs WebSphere MQ JMS
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.