javapandit.net
  • Home
  • Quick Java
    • Exception Handling
    • Collections Framework
  • Java Best Practices
  • Web Services
    • Web Service Basics
    • Ten Basic webservice concepts
    • XML
    • Apache Axis
    • Restful Web Services
  • JMS Concepts
    • JMS- MySQL
  • Hadoop
    • NoSQL DATABASEs
    • Apache Sqoop
    • Hadoop Interview Questions
  • Java 5
  • Java 8
    • Java 8 : Lambda Expressions
  • JDBC
  • Java Architect
    • Enterprise application re-platforming strategies
    • Java Memory Management
  • Java Programs
  • Technical Tips
    • How to set JAVA_HOME environment variable
    • How to create an auto increment field in Oracle?
    • Linux Commands
  • Best Java Interview Questions
    • Java Interview Questions- YouTube
  • Interview Questions
    • Java Tech interview Questions
    • Core Java Interview Questions >
      • core tech questions1
      • Java Collection interview questions
      • Java Concurrency
    • Servlets Interview Questions
    • JSP Interview Questions
    • Java Web Services Interview Questions
    • EJB Interview Questions
    • XML Interview Questions
    • JMS Interview Questions
  • Struts Interview Questions
    • Struts 2 Interview Questions
  • Java EE Architects Interview Questions
    • Java Architect Interview Questions
    • Top 10 reasons for Java Enterprise Application Performance Problems
    • Web Application Scalability Questions for IT Architect
  • JavaPandit's Blog
  • Web Services Interview Questions
  • Servlets And JSP
  • Oracle SOA Interview Questions
    • Open ESB /JBI
    • BPEL Language
  • Log4J
  • Ant
  • Maven
  • JMeter
  • JUnit
  • Apache POI Framework
  • ORCALE SERVICE BUS (OSB) Interview Questions
  • J2EE Patterns
    • Model-View-Controller (MVC)
    • Front Controller
    • DAO
    • Business Delegate
    • Session Facade
    • Service Locator
    • Transfer Object
    • Design Patterns >
      • Creational Patterns >
        • Singleton
      • Behavioural Patterns
      • Structural Patterns
    • Intercepting Filter
  • SQL Interview Questions/Lab
  • Best Wall Papers
    • Devotional Songs
  • Java Community
  • HIBERNATE
  • ORACLE CC&B
    • Oracle CC&B Interview Questions
  • Docker
  • Little Princess
    • Sai Tanvi Naming Ceremony Celebrations
    • Rice Feeding Ceremony
    • Sai Tanvi Gallery
  • APPSC Career Guidance
    • AP History
    • Indian Polity
    • Indian Economy
    • Science & Technology
    • Mental Ability and Reasoning
    • Disaster Management
    • Current Affairs and Events
    • General Sciences >
      • Biology
      • Physics
      • Chemistry
    • Previous Question Papers
  • About Us
  • Contact US

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.

Picture
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
Picture

You can see the below in the main screen click on New button.

Picture

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.

Picture
















//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

Powered by Create your own unique website with customizable templates.