POC on JMS with MySQL
Problem Definition
Need to read data from a table and will place in a queue through a Java client. After reading the records from table, you will update a read flag. Essentially you will pickup records with read flag not true. Another Java client will read the queue and will append the data in an XML file.
Software Used
· Mysql 5.0
· J2SDK1.5
· Sun Application Server PE 8(provided with Sun Java System Message Queue)
Mysql Configuration
Follow the step below one by one
a) Download and Installation
You can download Mysql 5.0 from http://dev.mysql.com/downloads/
After downloading you can install it.
b) Login to Mysql
You can login to mysql through command prompt by using following command
mysql -h 127.0.0.1 -u root –p
you should provide the password for the user root(if you want to login as different user created during installation use that username in place of root in command given above) this will prompt you with mysql command prompt
c) Create the Database to work
You can create the database by using command below in mysql prompt.
CREATE DATABASE ASSIGNMENT;
Once you create the Database you can make use of that by using the command below
USE ASSIGNMENT;
d) Create the Table
You can create the table by using the Sql Query below
CREATE TABLE SOURCETABLE(
EMPID INT,
EMPNAME VARCHAR(255),
JOIN_DATE DATE,
BASIC_SALARY FLOAT,
READ_FLAG BOOLEAN,
PRIMARY_KEY (EMPID));
JAVA Messaging Services (JMS)
The Java Message Service is a Java API that allows applications to create, send, receive, and read messages. Designed by Sun and several partner companies, the JMS API defines a common set of interfaces and associated semantics that allow programs written in the Java programming language to communicate with other messaging implementations.
When you talk about JMS client Application you should know about.
ConnectionFactory and Destination (Administered objects)
Connection
Session
Message Sender
Message Receiver
Message
The following diagram shows how all these objects fit together in a JMS client application.
Need to read data from a table and will place in a queue through a Java client. After reading the records from table, you will update a read flag. Essentially you will pickup records with read flag not true. Another Java client will read the queue and will append the data in an XML file.
Software Used
· Mysql 5.0
· J2SDK1.5
· Sun Application Server PE 8(provided with Sun Java System Message Queue)
Mysql Configuration
Follow the step below one by one
a) Download and Installation
You can download Mysql 5.0 from http://dev.mysql.com/downloads/
After downloading you can install it.
b) Login to Mysql
You can login to mysql through command prompt by using following command
mysql -h 127.0.0.1 -u root –p
you should provide the password for the user root(if you want to login as different user created during installation use that username in place of root in command given above) this will prompt you with mysql command prompt
c) Create the Database to work
You can create the database by using command below in mysql prompt.
CREATE DATABASE ASSIGNMENT;
Once you create the Database you can make use of that by using the command below
USE ASSIGNMENT;
d) Create the Table
You can create the table by using the Sql Query below
CREATE TABLE SOURCETABLE(
EMPID INT,
EMPNAME VARCHAR(255),
JOIN_DATE DATE,
BASIC_SALARY FLOAT,
READ_FLAG BOOLEAN,
PRIMARY_KEY (EMPID));
JAVA Messaging Services (JMS)
The Java Message Service is a Java API that allows applications to create, send, receive, and read messages. Designed by Sun and several partner companies, the JMS API defines a common set of interfaces and associated semantics that allow programs written in the Java programming language to communicate with other messaging implementations.
When you talk about JMS client Application you should know about.
ConnectionFactory and Destination (Administered objects)
Connection
Session
Message Sender
Message Receiver
Message
The following diagram shows how all these objects fit together in a JMS client application.
Administered Objects
Two parts of a JMS application Destinations and Connection factories are best maintained administratively rather than programmatically.
Connection Factories
A connection factory is the object a client uses to create a connection with a provider.
Each connection factory is an instance of either the QueueConnectionFactory or the TopicConnectionFactory interface.
At the beginning of a JMS client program, you usually perform a JNDI API lookup of the connection factory are programmatically create connection factory.
//JNDI LOOKUP
// need to create a InitialContext it looks for a jndi.properties files
jndiContext = new InitialContext();
//ConnectionFactory object should be created by the provider
QueueConnectionFactory queueConnectionFactory =
(QueueConnectionFactory) jndiContext.lookup("QueueConnectionFactory");
TopicConnectionFactory topicConnectionFactory =
(TopicConnectionFactory) jndiContext.lookup("TopicConnectionFactory");
Creation of the ConnectionFactory in Sun Application Server PE 8
Login to Admin Console http://localhost:4848/
In the Left Tab you can find JMS Resource ----> ConnectionFactory click on it
Two parts of a JMS application Destinations and Connection factories are best maintained administratively rather than programmatically.
Connection Factories
A connection factory is the object a client uses to create a connection with a provider.
Each connection factory is an instance of either the QueueConnectionFactory or the TopicConnectionFactory interface.
At the beginning of a JMS client program, you usually perform a JNDI API lookup of the connection factory are programmatically create connection factory.
//JNDI LOOKUP
// need to create a InitialContext it looks for a jndi.properties files
jndiContext = new InitialContext();
//ConnectionFactory object should be created by the provider
QueueConnectionFactory queueConnectionFactory =
(QueueConnectionFactory) jndiContext.lookup("QueueConnectionFactory");
TopicConnectionFactory topicConnectionFactory =
(TopicConnectionFactory) jndiContext.lookup("TopicConnectionFactory");
Creation of the ConnectionFactory in Sun Application Server PE 8
Login to Admin Console http://localhost:4848/
In the Left Tab you can find JMS Resource ----> ConnectionFactory click on it
You
can see the below in the main screen click on New button.

You
can see the screen with following fields and more provided the JNDI Name and
Type of Connectionfactory and leave other field as it is and click ok button on
the screen.

//Programmatic creation
QueueConnectionFactory myQConnFactory = new com.sun.messaging.QueueConnectionFactory();
TopicConnectionFactorymyTopicConnFactory = new com.sun.messaging.TopicConnectionFactory();
Destinations
A destination is the object a client uses to specify the target of messages it produces and the source of messages it consumes. In the PTP messaging domain, destinations are called queues and you use the in the pub/sub messaging domain, destinations are called topic.
A JMS application may use multiple queues and/or topics.In addition to looking up a connection factory or programmatically create connection factory, you usually look up a destination or programmatically create destination.
//JNDI LOOKUP
//Destination should be created by the provider
Topic myTopic = (Topic) ctx.lookup("MyTopic");
Queue myQueue = (Queue) ctx.lookup("MyQueue");
Creation of the ConnectionFactory in Sun Application Server PE 8
Login to Admin Console http://localhost:4848/
In the Left Tab you can find JMS Resource ----> Destination Resource click on it