Advertisement
Guest User

queue

a guest
Mar 22nd, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. public class TestQueue {
  2. Connection connection;
  3. Session session;
  4. Queue queueSend;
  5. private InitialContext ctxt = null;
  6. MessageProducer producer;
  7. public TestQueue() {
  8.  
  9. }
  10. public static void main(String ar[]){
  11. TestQueue t;
  12. for (int i = 0; i < 500000; i++)
  13. try {
  14. t=new TestQueue();
  15. t.openJMSQueues();
  16. t.sendByJMS("msg"+i);
  17. t.closeJMSQueues();
  18. } catch (Exception e) {
  19. e.printStackTrace();
  20. }
  21. }
  22. public void openJMSQueues()throws NamingException,JMSException
  23. {
  24. Properties props = new Properties();
  25. props.setProperty("java.naming.factory.initial", "weblogic.jndi.WLInitialContextFactory");
  26. props.setProperty("java.naming.provider.url","t3://192.168.48.132:7001");
  27. props.setProperty(InitialContext.SECURITY_PRINCIPAL,"wapppush");
  28. props.setProperty(InitialContext.SECURITY_CREDENTIALS,"latinia");
  29. ctxt = new InitialContext(props);
  30. ConnectionFactory connectionFactory=null;
  31. connectionFactory = (ConnectionFactory) ctxt.lookup("latinia/limsp/jms/connectionFactory/XAConnectionFactory");
  32. queueSend = (Queue) ctxt.lookup("latinia/limsp/jms/queue/serviceToLimsp/normalAuth");
  33. connection = connectionFactory.createConnection();
  34. session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
  35. producer=session.createProducer(queueSend);
  36. connection.start();
  37. }
  38. public void closeJMSQueues()
  39. {
  40. if (session != null) try {
  41. session.close();
  42. }
  43. catch(Exception ex) {
  44. System.out.println("error session.close()");
  45. }
  46. if (connection != null)
  47. try {
  48. connection.close();
  49. }
  50. catch(Exception ex) {
  51. System.out.println("error connection.close()");
  52. }
  53. }
  54. public void sendByJMS(String xml)throws JMSException{
  55. TextMessage txtMsg = session.createTextMessage(xml);
  56. txtMsg.setStringProperty("refProduct", "wapppush");
  57. producer.send(txtMsg);
  58. producer.send(session.createMessage());
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement