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
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. 
command to create queue : j2eeadmin -addJmsDestination queue_name queue

In the pub/sub messaging domain, destinations are called topics
command to create topic : j2eeadmin -addJmsDestination topic_name topic

The following line of code performs a JNDI API lookup of the previously created topic MyTopic and assigns it to a Topic object:

    Topic myTopic = (Topic) ctx.lookup("MyTopic");

 The following line of code looks up a queue named MyQueue and assigns it to a Queue object:
  Queue myQueue = (Queue) ctx.lookup("MyQueue");

Connections:
A connection encapsulates a virtual connection with a JMS provider. A connection could represent an open TCP/IP socket between a client and a provider service daemon.

Like connection factories, connections come in two forms, implementing either the QueueConnection or the TopicConnection interface. For example, once you have a QueueConnectionFactory or a opicConnectionFactory object, you can use it to create a connection:

    QueueConnection queueConnection = queueConnectionFactory.createQueueConnection();

    TopicConnection topicConnection = topicConnectionFactory.createTopicConnection();

When an application completes, you need to close any connections that you have created. Failure to close a connection can cause resources not to be released by the JMS provider. Closing a connection also closes its sessions and their message producers and message consumers.

    queueConnection.close();
    topicConnection.close();

Before your application can consume messages, you must call the connection’s start method. If you want to stop message delivery temporarily without closing the connection, you call the stop method.

Sessions:
A session is a single-threaded context for producing and consuming messages. You use sessions to create message producers, message consumers, and messages. Sessions serialize the execution of message listeners.

A session provides a transactional context with which to group a set of sends and receives into an atomic unit of work.

Sessions, like connections, come in two forms, implementing either the QueueSession or the TopicSession interface. For example, if you created a Topic-Connection object, you use it to create a TopicSession:
TopicSession topicSession =topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

The first argument means that the session is not transacted; the second means that the session automatically acknowledges messages when they have been received successfully.

Similarly, you use a QueueConnection object to create a QueueSession:

QueueSession queueSession =queueConnection.createQueueSession(true, 0);

Here, the first argument means that the session is transacted; the second indicates that message acknowledgment is not specified for transacted sessions.

Message Producers:
A message producer is an object created by a session and is used for sending messages to a destination. The PTP form of a message producer implements the Queue-Sender interface. The pub/sub form implements the TopicPublisher interface.

For example, you use a QueueSession to create a sender for the queue myQueue, and you use a TopicSession to create a publisher for the topic myTopic:

    QueueSender queueSender = queueSession.createSender(myQueue);
    TopicPublisher topicPublisher = topicSession.createPublisher(myTopic);

You can create an unidentified producer by specifying null as the argument to createSender or createPublisher.With an unidentified producer, you can wait to specify which destination to send the message to until you send or publish a message. Once you have created a message producer, you can use it to send messages.With a Queue-Sender, you use the send method:

queueSender.send(message);
With a TopicPublisher, you use the publish method:
topicPublisher.publish(message);
If you created an unidentified producer, use the overloaded send or publish method
that specifies the destination as the first parameter.
Prev 1 2 3 4 5 6 7 89 Next
Powered by Create your own unique website with customizable templates.