Guest User

Jim

a guest
Sep 30th, 2010
72
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.myorg.pelican;
  2.  
  3. import org.apache.log4j.Logger;
  4. import org.apache.thrift.TException;
  5. import org.hornetq.api.core.TransportConfiguration;
  6. import org.hornetq.api.jms.HornetQJMSClient;
  7. import org.hornetq.core.remoting.impl.netty.NettyConnectorFactory;
  8. import org.hornetq.integration.transports.netty.TransportConstants;
  9. import org.hornetq.jms.client.HornetQConnectionFactory;
  10.  
  11. import javax.jms.*;
  12. import java.text.SimpleDateFormat;
  13. import java.util.Calendar;
  14. import java.util.HashMap;
  15. import java.util.Map;
  16.  
  17.  
  18. public class PelicanRunner {
  19.  
  20.     final static Logger logger = Logger.getLogger(PelicanRunner.class);
  21.  
  22.     public static void main(String[] args) {
  23.  
  24.         logger.info("Starting up Pelican Test Code");
  25.  
  26.         testHornetJMS();
  27.  
  28.     }
  29.  
  30.     private static void testHornetJMS() {
  31.  
  32.         Map<String, Object> connectionParams = new HashMap<String, Object>();
  33.         connectionParams.put(TransportConstants.PORT_PROP_NAME, 5455);
  34.         connectionParams.put(TransportConstants.HOST_PROP_NAME, "cache09");
  35.         TransportConfiguration tc = new
  36.                 TransportConfiguration(NettyConnectorFactory.class.getName(),
  37.                 connectionParams);
  38.  
  39.         HornetQConnectionFactory cf = HornetQJMSClient.createConnectionFactory(tc);
  40.  
  41.         //This stuff happens on a per thread basis
  42.         Connection connection = null;
  43.         Session session = null;
  44.         MessageProducer producer = null;
  45.         try {
  46.             connection = cf.createConnection();
  47.             connection.start();
  48.             session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
  49.             Destination destination = session.createQueue("jimTest2");
  50.             producer = session.createProducer(destination);
  51.  
  52.  
  53.             System.out.println(now());
  54.             for (int i = 0; i < 50000; i++) {
  55.                 TextMessage message = session.createTextMessage("THIS IS A TEST MSG");
  56.                 producer.send(message);
  57.                 if(i % 10000 == 0) {
  58.                     System.out.println(i+ " messages inserted");
  59.                 }
  60.             }
  61.             System.out.println("COMPLETE");
  62.             System.out.println(now());
  63.  
  64.         } catch (Exception e) {
  65.             e.printStackTrace();
  66.         } finally {
  67.             if (producer != null) {
  68.                 try {
  69.                     producer.close();
  70.                 } catch (Exception e) {
  71.                     e.printStackTrace();
  72.                 }
  73.             }
  74.             if (session != null) {
  75.                 try {
  76.                     session.close();
  77.                 } catch (Exception e) {
  78.                     e.printStackTrace();
  79.                 }
  80.             }
  81.             if (connection != null) {
  82.                 try {
  83.                     connection.close();
  84.                 } catch (Exception e) {
  85.                     e.printStackTrace();
  86.                 }
  87.             }
  88.         }
  89.  
  90.  
  91.     }
  92.  
  93.     public static String now() {
  94.         Calendar cal = Calendar.getInstance();
  95.         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  96.         return sdf.format(cal.getTime());
  97.  
  98.     }
  99.  
  100. }
RAW Paste Data