1600 PMP mock questions 1400 CAPM mock questions 800 SCJP 6 mock questions 600 OCAJP 7 mock questions 590 OCPJP 7 mock questions 556 SCWCD 5 mock questions 500 OCEJWCD 6 mock questions pdfDownload (java,struts, hibernet etc)

JMS interview questions

!!! JMS interview questions !!!

What are the steps to send and receive JMS message ?



Step 1.
lookup the ConnectionFactory .
(A connection factory is the object a client uses to create a connection to a provider. A connection factory encapsulates a set of connection configuration parameters that has been defined by an administrator. Each connection factory is an instance of the ConnectionFactory, QueueConnectionFactory, or TopicConnectionFactory interface)

Context ctx = new InitialContext();
ConnectionFactory connectionFactory = (ConnectionFactory)
ctx.lookup("jms/ConnectionFactory");

Step 2.
lookup the destination (A destination is the object a client uses to specify the target of messages it produces and the source of messages it consumes.)

Destination myDest = (Destination) ctx.lookup("jms/MyTopic");
or
Queue myQueue = (Queue) ctx.lookup("jms/MyQueue");


Step 3.
Create the Connection
Connection connection = connectionFactory.createConnection();

Step 4.
Session session = connection.createSession(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

Step 5.
Create Message Producers

You use a Session to create a MessageProducer for a destination. Here, the first example creates a producer for the destination myQueue, and the second for the destination myTopic:

MessageProducer producer = session.createProducer(myQueue);
or
MessageProducer producer = session.createProducer(myTopic);

Step 6.
Create message and send message

TextMessage message = session.createTextMessage();
message.setText("testmsg");
producer.send(message);

Step 7.
create Message Consumers and receive message
MessageConsumer consumer = session.createConsumer(myQueue);
or
MessageConsumer consumer = session.createConsumer(myTopic);

Message m = consumer.receive();
if (m instanceof TextMessage) {
TextMessage message = (TextMessage) m;
System.out.println("Reading message: " + message.getText());
} else {
// Handle error
}




Reviews and Comments


PMP, CAPM, PMI is a registered certification mark of the Project Management Institute, Inc

Copyright © www.techfaq360.com 2016


About US | Contact US | Privacy Policy | Terms and Conditions  | Website disclaimer  | Cancellation and Refund Policy  | Shipping & Delivery Policy