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 1, 2  Next
 WebSphere MQ base Vs WebSphere MQ JMS « View previous topic :: View next topic » 
Author Message
viki
PostPosted: Wed Feb 08, 2006 3:46 am    Post subject: WebSphere MQ base Vs WebSphere MQ JMS Reply with quote

Acolyte

Joined: 07 Feb 2006
Posts: 50

Hi,

What is the difference between WebSphere MQ base and WebSphere MQ JMS?

Bye,
Viki.
Back to top
View user's profile Send private message
wschutz
PostPosted: Wed Feb 08, 2006 3:48 am    Post subject: Reply with quote

Jedi Knight

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

If you look at the "Using Java" document, it should become obvious... in a "nutshell"

(1) MQ Base classes implement the Object Oriented MQ programming inteface
(2) MQ JMS is an implementation of the JMS specification using MQ
_________________
-wayne
Back to top
View user's profile Send private message Send e-mail AIM Address
viki
PostPosted: Wed Feb 08, 2006 3:59 am    Post subject: Reply with quote

Acolyte

Joined: 07 Feb 2006
Posts: 50

Hi,

Thanks buddy. I used the wrong term "difference" . Actually, I was looking for the advantages/benifits of both. In other words, which is recommended to use and why?

Bye,
Viki.
Back to top
View user's profile Send private message
wschutz
PostPosted: Wed Feb 08, 2006 4:10 am    Post subject: Reply with quote

Jedi Knight

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

I see.... that issue has been debated many times before, but in a nutshell, IMHO:

(1) Using the base classes gives you full access to all WebSphere MQ features,

(2) Using JMS gives you the ability to program to a "standardized" api and you can (in theory) use different providers for "under the covers".

So, what are your requirements?
_________________
-wayne
Back to top
View user's profile Send private message Send e-mail AIM Address
viki
PostPosted: Wed Feb 08, 2006 4:24 am    Post subject: Reply with quote

Acolyte

Joined: 07 Feb 2006
Posts: 50

Hi,
wschutz wrote:
So, what are your requirements?


My requirement:

There is a file, MyFile.xyz which is currently present in a local harddisk. Now, I wanna write a program which retrieves MyFile.xyz from harddisk and transfer it to a specific queue running in MQSeries.

Here, retrieving file from harddisk is not a big deal. What is really challenging and new to me is transferring MyFile.xyz to MQSeries.

Considering above mentioned requirement (file transfer), which approach (MQ base or MQ JMS) should I used? Also, it will be great if you could provide any guidence on file transfer to MQSeries.

Thanks in advance.

Bye,
Viki.
Back to top
View user's profile Send private message
BenR
PostPosted: Wed Feb 08, 2006 4:46 am    Post subject: Reply with quote

Acolyte

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

If you don't know anything about the MQI, then JMS will be easier.

- read file off disk
- create a MQConnectionFactory (see yesterday)
- create a JMS Connection
- use the Connection to create a JMS Session
- use the Session to create a JMS Queue
- use the Session to create a JMS MessageProducer pointing at the Queue
- use the Session to create a JMS Message to contain the file
- use the MessageProducer to send the Message to MQ
- close everything
Back to top
View user's profile Send private message Visit poster's website
mvic
PostPosted: Wed Feb 08, 2006 5:43 am    Post subject: Reply with quote

Jedi

Joined: 09 Mar 2004
Posts: 2080

BenR wrote:
If you don't know anything about the MQI, then JMS will be easier.

IMHO...
In API terms, MQ base Java classes are in many cases "easier" because you don't need abstract concepts like a Session and a MessageProducer.

However, as wschutz pointed out, JMS is a more widely-implemented spec, so it would be theoretically possible to pick up the JMS app classes and deploy in an environment with a different JMS provider.

Also, if you come to MQ knowing JMS already, then MQ's JMS classes are "easier".

So, as always, the answer to "which is recommended" is, "it depends..."
Back to top
View user's profile Send private message
wschutz
PostPosted: Wed Feb 08, 2006 6:45 am    Post subject: Reply with quote

Jedi Knight

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

Quote:
My requirement:

There is a file, MyFile.xyz which is currently present in a local harddisk. Now, I wanna write a program which retrieves MyFile.xyz from harddisk and transfer it to a specific queue running in MQSeries.
Maybe the answer is "neither"... there are already programs which will load a file into a queue, the easiest of which is Paul Clarke's MA01 supportpac (the "q" program). Or, in the broker environment, the "File Extender Nodes", or , for a complete file transfer solution: PM4Data.
_________________
-wayne
Back to top
View user's profile Send private message Send e-mail AIM Address
viki
PostPosted: Sat Feb 11, 2006 2:40 am    Post subject: Reply with quote

Acolyte

Joined: 07 Feb 2006
Posts: 50

BenR wrote:
If you don't know anything about the MQI, then JMS will be easier.

- read file off disk
- create a MQConnectionFactory (see yesterday)
- create a JMS Connection
- use the Connection to create a JMS Session
- use the Session to create a JMS Queue
- use the Session to create a JMS MessageProducer pointing at the Queue
- use the Session to create a JMS Message to contain the file
- use the MessageProducer to send the Message to MQ
- close everything

Hi,
I've tried to follow the steps you mentioned. Connection is created successfully @ runtime. Here is the code. But before you read the code, I would like to bring to issues in your knowledge.

i) When I use queueSender.send(q,om); it gives me Exception: Exeption java.lang.UnsupportedOperationException: MQJMS1014: operation invalid for identified producer. However, if I use queueSender.send(om); it do not give any error/exception.

ii) There is a small icon in my taskbar, WebSphere MQ Running. When i double click this icon, In Event Viewer ---> Application, it shows error after running the below code. Error is:
Quote:
Error on receive from host localhost (127.0.0.1).

An error occurred receiving data from localhost (127.0.0.1) over TCP/IP. This may be due to a communications failure.

The return code from the TCP/IP (recv) call was 10054 (X'2746'). Record these values and tell the systems administrator.


This means, queueSender.send(om) is not working properly? The file is not successfully transfered to the queue? How can I make sure that file is successfully transferred to the MQ Queue?

Code is here:
Code:

public static void main(String args[]) {
 
 
  String HOSTNAME = "localhost";
  String QMGRNAME = "MyQMGR";
  String CHANNEL = "SYSTEM.DEF.SVRCONN";
 
 
  boolean transacted = false;
  MQQueueConnectionFactory factory=null;
  QueueConnection connection=null;
  QueueSession session=null;
  Queue q=null;
  QueueSender queueSender=null;
  QueueReceiver queueReceiver=null;
  try{
   
     factory = new com.ibm.mq.jms.MQQueueConnectionFactory();
     factory.setQueueManager(QMGRNAME);
     factory.setHostName(HOSTNAME);
     factory.setPort(1414);
     factory.setTransportType(JMSC.MQJMS_TP_CLIENT_MQ_TCPIP);
     factory.setChannel(CHANNEL);
     connection = factory.createQueueConnection();
     System.out.println("connection created successfully: "+connection);
     connection.start();
   
   
     session = connection.createQueueSession(transacted, Session.AUTO_ACKNOWLEDGE);
   
     q = session.createQueue("queue:///SYSTEM.DEFAULT.LOCAL.QUEUE");
    
     queueSender = session.createSender(q);
    
     File source = new File ("MyFile");
     source.createNewFile();
    
     ObjectMessage om = session.createObjectMessage(source);
      
     queueSender.send(om);
    
     queueReceiver = session.createReceiver(q);
     Message inMessage = queueReceiver.receive();
    
     if (inMessage instanceof ObjectMessage) {
         File myFile= (File)((ObjectMessage) inMessage).getObject();
        System.out.println("File Recieved from queueReceiver.receive() "+myFile.getName());
       } else {
                  System.out.println("Reply message was not a ObjectMessage");
                 
            }
     inMessage.clearBody();
   }catch(Exception e){
     System.out.println("Exeption "+e);   
   }
   
   try{
              
         queueSender.close();
         session.close();
         queueReceiver.close();
         connection.stop();
         connection.close();
   
   
   }catch(Exception e){
    System.out.println("Exception occured while closing: "+ e);
   }
   
 }// main() closed
[


Output generated by running above code
Code:

connection created successfully: com.ibm.mq.jms.MQQueueConnection@ca9d921
File Recieved from queueReceiver.receive() MyFile


Bye,
Viki.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Sat Feb 11, 2006 5:56 am    Post subject: Reply with quote

Grand High Poobah

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

A few observations:

When creating the queue you might not want to pass the RFH header at this stage (=non jms target) ... makes it easier to read by a non JMS app.
Code:
q = session.createQueue("queue:///SYSTEM.DEFAULT.LOCAL.QUEUE?targetClient=1");


You are right that the method you tried first queueSender.send(q,om) would not work. This is because you created the producer passing the queue in the argument. Creating the producer with a null argument forces you to use this form of the send method instead of producer.send(msg) because the queue is unknown at invocation time. So use the known producer or the anonymous one but do not mix.

You created an Object message and are transporting a serializable object message. Good. But it only works because the file is on the same platform. You do not want to transport a reference to a file (object) but the file content. Use a BytesMessage and write the IO stream to the message.

Lastly your logic between sender and receiver is flawed. It worked only because sender and receiver are in the same session.
a) you use a transacted session and never commit.
b) with a transacted session you should always use explicit commit/rollback.
c) use session.commit() after the send to make the message available to anybody.
d) use session.commit() after the receive to make sure the message will not be left on the queue and its lock be released when you disconnect.

e) learn about the default behavior of a transacted session on close.

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

Acolyte

Joined: 07 Feb 2006
Posts: 50

fjb_saper wrote:
A few observations:

When creating the queue you might not want to pass the RFH header at this stage (=non jms target) ... makes it easier to read by a non JMS app.
Code:
q = session.createQueue("queue:///SYSTEM.DEFAULT.LOCAL.QUEUE?targetClient=1");


Ok, I have changed my code to:
Code:
queue:///SYSTEM.DEFAULT.LOCAL.QUEUE?targetClient=1


Quote:
You created an Object message and are transporting a serializable object message. Good. But it only works because the file is on the same platform. You do not want to transport a reference to a file (object) but the file content. Use a BytesMessage and write the IO stream to the message.

I'm not sure whether the application i m currently developing will run on same single machine or in a distributed environment. In either case, I have note your BytesMessage suggesstion and will come back to it later.

Quote:
Lastly your logic between sender and receiver is flawed. It worked only because sender and receiver are in the same session.
a) you use a transacted session and never commit.
b) with a transacted session you should always use explicit commit/rollback.
c) use session.commit() after the send to make the message available to anybody.
d) use session.commit() after the receive to make sure the message will not be left on the queue and its lock be released when you disconnect.
e) learn about the default behavior of a transacted session on close.

Ok, I have changed my code to: [Please tell me if it is ok?]
Code:

boolean transacted = true;
session = connection.createQueueSession(transacted, Session.AUTO_ACKNOWLEDGE);
queueSender.send(om);
session.commit();

queueReceiver = session.createReceiver(q);
Message inMessage = queueReceiver.receive();
session.commit();


Thanks for your suggesstions. Kindly review my updated code and tell me what flaws are there. Like still I have to use JNDI to make connection from JNDI instead @ runtime.

Bye,
Viki.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Sun Feb 12, 2006 5:31 am    Post subject: Reply with quote

Grand High Poobah

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

Hi Viki,

Apart from the additional step of using JNDI instead of MQxxx classes your code looks fine. (Noted you'll get to the BytesMessage later...)

A word of advice: In the absence of an APP server start with using the file context for JNDI. It makes things just a lot easier....(com.sun....fscontext...) for a standalone app.

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

Acolyte

Joined: 07 Feb 2006
Posts: 50

Hi,

Right. Well, I'm working over these two issues right now:

1) BytesMessage.
2) Using the file context for JNDI.

As for ByteMessage, I'm not successfull in implementation so far. I'm creating ByteMessage using session, but session.createBytesMessage(); returns com.ibm.jms.JMSBytesMessage. I don't know why it is returning com.ibm.jms.JMSBytesMessage instead of javax.jms.BytesMessage ?

Apart from this, here is the code for writing IO Stream to the message. [again: just want to show you for review]
Code:

byte[] buf = new byte[1024];
int len = 0;     
BytesMessage bm = (BytesMessage)session.createBytesMessage();
bm.clearBody();
InputStream in = new FileInputStream (MySourceFile);

      while ((len = in.read(buf)) > 0) {
               bm.writeBytes(buf, 0, len);
      }
queueSender.send(bm);
session.commit();

Thanks!

Bye,
Viki.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Sun Feb 12, 2006 12:54 pm    Post subject: Reply with quote

Grand High Poobah

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

viki wrote:
Hi,

Right. Well, I'm working over these two issues right now:

1) BytesMessage.
2) Using the file context for JNDI.

As for ByteMessage, I'm not successfull in implementation so far. I'm creating ByteMessage using session, but session.createBytesMessage(); returns com.ibm.jms.JMSBytesMessage. I don't know why it is returning com.ibm.jms.JMSBytesMessage instead of javax.jms.BytesMessage ?

Well you have to remember when you look at
Code:
System.out.println(object.getClass().getName());
you really get the implementation class name. To check for the interface you can do something like
Code:
if (obj instanceof javax.jms.BytesMessage) System.out.println("True BytesMessage");


viki wrote:
Apart from this, here is the code for writing IO Stream to the message. [again: just want to show you for review]Thanks!

Bye,
Viki.

Code looks fine but I would check as well the StreamMessage.
Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
viki
PostPosted: Mon Feb 13, 2006 12:46 am    Post subject: Reply with quote

Acolyte

Joined: 07 Feb 2006
Posts: 50

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

Coming to the 2nd issue, How can I confirm that message via queueSender.send(bm); is send successfully? 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.
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 » 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.