/* * Created on Feb 17, 2011 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ /** * @author NNakarikanti * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ import javax.jms.Connection; import javax.jms.DeliveryMode; import javax.jms.Destination; import javax.jms.JMSException; import javax.jms.MessageConsumer; import javax.jms.MessageProducer; import javax.jms.Session; import javax.jms.TextMessage; import com.ibm.ws.sib.processor.runtime.Producer; import org.apache.activemq.ActiveMQConnection; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.broker.BrokerService; import java.util.Date; public class AMQProCon { private ActiveMQConnectionFactory connectionFactory; private Connection connection; private Session session; private Destination destination; private boolean transacted = false; private static int producerThreadCount = 1; private static int consumerThreadCount = 1; private static int messageCount = 10; private TextMessage textMessage; private String queueName1 = "TestTestTestQ"; private String queueName2 = "UIMJobQueueSTGTax"; public AMQProCon() { connectionFactory = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_USER, ActiveMQConnection.DEFAULT_PASSWORD, "tcp://dwdappq05pw:61616"); try { connection = connectionFactory.createConnection(); session = connection.createSession(transacted, Session.AUTO_ACKNOWLEDGE); //destination = session.createQueue("UIMJobQueuePreProdTax"); destination = session.createQueue(queueName1); textMessage = session.createTextMessage("NNP Message"); connection.start(); System.out.println("Connection Established :: " + connection.getClientID()); } catch (JMSException e) { e.printStackTrace(); } } private void closeAll() throws JMSException { try { session.close(); connection.close(); System.out.println("Closed Connection"); } catch (Exception e) { System.out.println("Caught: " + e); e.printStackTrace(); } } public static void main(String[] args) { final AMQProCon testAMQ = new AMQProCon(); System.out.println("\nActiveMQ Machine : "+testAMQ.connectionFactory.getBrokerURL()); System.out.println("ActiveMQ Queue : "+testAMQ.queueName1); Runnable pro = new Runnable(){ public void run(){ AMQProducer producer = new AMQProducer(testAMQ.connection, testAMQ.session, testAMQ.destination); producer.setMessage(testAMQ.textMessage); producer.setMessageCount(messageCount); producer.sendMessage(); } }; for(int i = 0; i < producerThreadCount; i++){ Thread producerThread = new Thread(pro); producerThread.setName("P T - " + (i+1)); producerThread.start(); } Runnable con = new Runnable(){ public void run(){ AMQConsumer consumer = new AMQConsumer(testAMQ.connection, testAMQ.session, testAMQ.destination); consumer.init(); } }; for(int i = 0; i < consumerThreadCount; i++){ Thread consumerThread = new Thread(con); consumerThread.setName("C T - " + (i+1)); consumerThread.start(); System.out.println("\nConsumer STARTED :: " + new Date().toString()); } } }