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

JMS Client Application

Setting Your Environment for Running Applications

Platform                                 Variable                                                         Name Values

Microsoft Windows                 %JAVA_HOME%                                 Directory in which the JDK installed                                                                                                         
                                               %J2EE_HOME%                                Directory in which the J2EE is installed.                                                                                                                                                                                                                                   %CLASSPATH%                              Include the following:.;%J2EE_HOME%\lib                                                                                                                \j2ee.jar;

                                                                                                              %J2EE_HOME%\lib\locale
                                                 %PATH%                                              Include %J2EE_HOME%\bin
UNIX                                        $JAVA_HOME                                     Directory in which the Java 2 SDK, Standard       
                                                                                                           Edition, version 1.3.1, is installed
                                                 $J2EE_HOME                                    Directory in which the J2EE SDK 1.3.1 is installed,                                                                                             usually $HOME/j2sdkee1.3.1
                                                 $CLASSPATH                            Include the following: .:$J2EE_HOME/lib/j2ee.jar:
                                                                                                           $J2EE_HOME/lib/locale
                                                $PATH                                                   Include $J2EE_HOME/bin

A Simple Point-to-Point Example:

Writing the PTP Client Programs:
The sending program, Sender.java, performs the following steps:
1. Performs a Java Naming and Directory Interface (JNDI) API lookup of the
QueueConnectionFactory and queue
2. Creates a connection and a session
3. Creates a QueueSender
4. Creates a TextMessage
5. Sends one or more messages to the queue
6. Sends a control message to indicate the end of the message stream
7. Closes the connection in a finally block, automatically closing the session
and QueueSender

The receiving program, Receiver.java, performs the following steps:

1. Performs a JNDI API lookup of the QueueConnectionFactory and queue
2. Creates a connection and a session
3. Creates a QueueReceiver
4. Starts the connection, causing message delivery to begin
5. Receives the messages sent to the queue until the end-of-message-stream control
    message is received
6. Closes the connection in a finally block, automatically closing the session
    and QueueReceiver.

Sender.java
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import com.sun.messaging.QueueConnectionFactory;
import com.sun.messaging.jms.JMSException;

public class Sender {
    public void sendData(){
             try{
        String imqAddressList = "mq://localhost:7676";
        String queueName = "QueueTest";
        System.out.println("sender sending data ...........");
        String data = " welcome to jms";
        QueueConnectionFactory queueFactory = new QueueConnectionFactory();
        queueFactory.setProperty("imqAddressList", imqAddressList);
        QueueConnection connection = queueFactory.createQueueConnection();
        QueueSession session = connection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
        Queue dest = session.createQueue(queueName);
        QueueSender sender = session.createSender(dest);
        sender.setDeliveryMode(DeliveryMode.PERSISTENT);
        TextMessage msg =  session.createTextMessage();
        msg.setText(data);
        sender.send(msg);
        session.close();
        connection.close();
        }catch(JMSException je){
            je.printStackTrace();
        }catch(javax.jms.JMSException je){
            je.printStackTrace();
        }
    }
}
Prev 1 2 3 4 5 6 7 8 9 Next
Powered by Create your own unique website with customizable templates.