package org.jboss.qa.hornetq; import java.util.Properties; import javax.jms.Connection; import javax.jms.ConnectionFactory; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageProducer; import javax.jms.Queue; import javax.jms.Session; import javax.jms.TextMessage; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import org.apache.log4j.Logger; public class TestProducer { private static Logger log = Logger.getLogger(TestProducer.class); private static boolean trace = log.isTraceEnabled(); private static Message createMessage(Session session, int counter) throws Exception { TextMessage message = session.createTextMessage("Hello " + counter); return message; } public static void main(String[] args) { final int MESSAGES_COUNT = 50000; Context context = null; Connection con = null; try { Properties properties = new Properties(); properties.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory"); // properties.setProperty("java.naming.provider.url", "jnp://perf23:1099"); // properties.setProperty("java.naming.provider.url", "jnp://perf24:1099"); // properties.setProperty("java.naming.provider.url", "jnp://perf25:1099"); properties.setProperty("java.naming.provider.url", "jnp://jawa01:1099"); // properties.setProperty("java.naming.provider.url", "jnp://10.0.0.4:1099"); // properties.setProperty("java.naming.provider.url", "jnp://jawa01.englab.brq.redhat.com:1099"); // properties.setProperty("java.naming.provider.url", "jnp://jawa03.englab.brq.redhat.com:1099"); // properties.setProperty("java.naming.provider.url", "jnp://jawa04.englab.brq.redhat.com:1099"); // properties.setProperty("java.naming.provider.url", "jnp://slave4:1099"); // properties.setProperty("java.naming.provider.url", "jnp://10.16.88.228:1099"); properties.setProperty("java.naming.factory.url.pkgs", "org.jnp.interfaces.NamingContextFactory"); context = new InitialContext(properties); ConnectionFactory cf = (ConnectionFactory) context.lookup("/ClusteredConnectionFactory"); con = cf.createConnection(); Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = (Queue) context.lookup("/queue/testDistributedQueue"); MessageProducer producer = session.createProducer(queue); long time = System.currentTimeMillis(); for (int i = 0; i < MESSAGES_COUNT; i++) { producer.send(createMessage(session, i)); System.out.println("Sent message: " + i); log.debug("Sent message: " + i); // Thread.sleep(10); } producer.close(); System.out.println("It took " + (System.currentTimeMillis() - time) + " ms"); session.close(); } catch (Exception e) { e.printStackTrace(); } finally { if (con != null) { try { con.close(); } catch (JMSException e) { e.printStackTrace(); } } if (context != null) { try { context.close(); } catch (NamingException e) { e.printStackTrace(); } } } } }