Refresh Your Java - Before Java Interview
We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....
import java.util.Properties;
import
javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import
javax.jms.QueueConnectionFactory;
import
javax.jms.QueueReceiver;
import
javax.jms.QueueSender;
import
javax.jms.QueueSession;
import javax.jms.Session;
import javax.naming.Context;
import
javax.naming.InitialContext;
public class TestMQ {
public static void main(String[] args) {
try {
Properties p = new Properties();
p.put("org.omg.CORBA.ORBClass","com.sun.CORBA.iiop.ORB");
//p.put("org.omg.CORBA.ORBSingletonClass","com.ibm.rmi.corba.ORBSingleton");
//
p.put("javax.rmi.CORBA.UtilClass","com.ibm.rmi.javax.rmi.CORBA.Util");
//
p.put("javax.rmi.CORBA.StubClass","com.ibm.rmi.javax.rmi.CORBA.StubDelegateImpl");
//
p.put("java.naming.factory.url.pkgs","com.ibm.ws.naming");
p.setProperty( javax.naming.Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory"
);
//javax.naming.Context.INITIAL_CONTEXT_FACTORY, for the property
name,
//and the constant,
com.ibm.websphere.naming.PROPS.INITIAL_CONTEXT_FACTORY, for the
property value.
p.setProperty( "java.naming.provider.url",
"iiop://HOSTNAME:PORT" );
String
connectionfactoryjndi="jms/testQCF";
//String sendQueueName="jms/apinboundq";
String sendQueueName="jms/destOutboundQ";
Context jndiContext = new InitialContext();
jndiContext = new InitialContext( p );
QueueConnectionFactory cf = (QueueConnectionFactory)
jndiContext.lookup(connectionfactoryjndi);
System.out.println("Looked up : QueueConnectionFactory
"+ connectionfactoryjndi);
System.out.println("Transport Queue [" +
sendQueueName + "]");
QueueConnection connection = (QueueConnection)
cf.createQueueConnection();
QueueSession session = (QueueSession)
connection.createQueueSession(false,
Session.CLIENT_ACKNOWLEDGE);
Queue queue = (Queue) jndiContext.lookup(sendQueueName);
QueueSender sender = (QueueSender)
session.createSender(queue);
QueueReceiver receiver = (QueueReceiver)
session.createReceiver(queue);
long uniqueNumber = System.currentTimeMillis() % 1000;
javax.jms.TextMessage message =
session.createTextMessage("Test Message "+
uniqueNumber);
// Start the connection
connection.start();
sender.send(message);
//
System.out.println("Sent message:\\n" +
message);
sender.close();
receiver.close();
session.close();
connection.close();
System.out.println("\\nSUCCESS\\n");
}
catch (JMSException jmsex) {
System.out.println(jmsex);
System.out.println("\\nFAILURE\\n");
}
catch (Exception ex) {
System.out.println(ex);
System.out.println("\\nFAILURE\\n");
}
}
}
This Portal is intended to put all Java/J2ee related topics at one single place for quick referance, not only Technical , but also the Project Management Related thing such as Development Process methodoogies build process, unit testing etc.,
This Portal has More than 500 Java Interview Questions (also could be Considered as Quick Notes) very neatly separated topic by topic with simple diagrams which makes you easily understandable. Importantly these are from our Realtime expericance.