aspose file tools
The moose likes EJB and other Java EE Technologies and the fly likes JMS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "JMS" Watch "JMS" New topic


kavitha vasu
Ranch Hand

Joined: Feb 22, 2007
Posts: 70
Hi Friends,

Am new to JMS. Just now started to learn .

I need to know what are the technical requirements are need to write simple JMS Program.

At Present thisis my system requirements,

1) Jdk 1.5
2) Tomcat 5.5

3) Servlet 2.0
4) JSP 1.2

Can i implement JMS in tomcat or not ?

Do i need any Application server?
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Can i implement JMS in tomcat or not ?

No. Apache Tomcat is simply a servlet container for serving up servlets and JSP pages.

In order to build a messaging application, you need a message server. Apache ActiveMQ is an open-source server that is user-friendly and very robust. You can find it at:

Good luck!
[ June 27, 2008: Message edited by: James Clark ]
Amir Pourteymour
Ranch Hand

Joined: Mar 06, 2008
Posts: 45
Originally posted by kavitha vasu:
Do i need any Application server?

Yes You need an application server in order to use your JMS destinations (e.g. Queue or Topic). After you setup your ConnectionFactory and destinations, you can simply start using it in your application.

For Application servers you have access to different commercial and open-source AS such as Jboss Application Server, GlassFish, ActiveMQ, and etc.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
An application server is not required. Two command-line Java programs can communicate using the JMS API and a message server.
kavitha vasu
Ranch Hand

Joined: Feb 22, 2007
Posts: 70

where can i download message server?
vijay jamadade
Ranch Hand

Joined: May 12, 2008
Posts: 241
Hi Kavita,
Its true thatyou need the I have implemented JMS full life cycle in weblogic server 10.0. Weblogic workshop editor is the best editor to do that. In my application i created on JMs client file that will send the messages to the JMS server that i created on weblogic. the mappings of that server provided to the JMs Client program. Then i created one message driven bean and using annotations i provided the JMS server mappings to that bean.

Now when my client prog. sends messages to the JMS server on weblogic. The MDB gets called and receives the message.

I am giving you the code for JMS client file as below.

/* JMS Implementation by Vijay Jamadade
package com.dao;
import java.util.Properties;

import javax.jms.Message;
import javax.jms.ObjectMessage;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueReceiver;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.naming.Context;
import javax.naming.InitialContext;

public class TestJMS {
// get Logging instance
// private static LoggerDelegate log = new LoggerDelegate();

// Declare variables
// private static JMSQueueManager jmsQueueManager;

private QueueConnection connection;

private QueueSession session;

private Queue inboundQueue;

private Queue outboundQueue;

private QueueReceiver receiver;

private QueueSender sender;

private QueueConnectionFactory connFactory;

private ObjectMessage ackMessage;

private ObjectMessage dataMessage;

private Properties properties;

private InitialContext initialContext;

// private BgApplicationSession applicationSession;

// private Vector<ObjectMessage> messageQueue;

private ObjectMessage messageFromQueue;

private boolean connectedToQueue = false;

private String inboundQueueName;

private String outboundQueueName;

private int sorterId;

private String appServerIP;

private String jmsPort;

private String className = null ;

public void connectToQueue() {
try {

System.out.println("b4 the getInitialContext ");

properties = new Properties();
properties.put(Context.PROVIDER_URL, "t3://localhost:7001");

final Context initialContext = new InitialContext(properties);
System.out.println("Got the getInitialContext ");

//set queue connection
System.out.println("b4 the Connection Factory");
connFactory = (QueueConnectionFactory) initialContext.lookup("weblogic.jms.ConnectionFactory");
connection = (QueueConnection) connFactory.createQueueConnection();
System.out.println("Got the Connection Factory");

// set session, false implies session is not transacted
session = connection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
System.out.println("Got the session");

// set the queues
inboundQueue = (Queue) initialContext.lookup("jms/JMSQueue" );
outboundQueue = (Queue) initialContext.lookup("jms/JMSQueue1" );
System.out.println("Got the Queue");

// Set receiver
receiver = session.createReceiver(inboundQueue);
receiver.setMessageListener(new MessageListenerImpl());

// set sender
sender = session.createSender(inboundQueue);

// start messaging receiving
// connection.setExceptionListener(new ExceptionListenerImpl());
connectedToQueue = true;
ObjectMessage om = session.createObjectMessage();
om.setObject((Serializable) new String("TEStingfromremote"));
om.setIntProperty("id", 1);
System.out.println("Sent message");
//,"Connection to JMS Queue established");
receiver = session.createReceiver(outboundQueue);
Message message = receiver.receive();
System.out.println("Received message from the message bean "+message);

}catch (Exception e) {
System.out.println("Error Sent message"+e);



Regards, Vijay Jamadade.
( Nothing is Impossible.)
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

You can just download Apache ActiveMQ server as suggested by James and send/receive JMS messages.No need to download app server.

I agree. Here's the link:
subject: JMS