1 37 38 package com.sun.j2ee.blueprints.opc.webservice.invoicercvr; 39 40 import javax.jms.*; 41 42 45 public class TopicHelper { 46 47 private Topic topic; 48 private TopicConnectionFactory topicFactory; 49 50 51 56 public TopicHelper(TopicConnectionFactory topicFactory, Topic topic) { 57 this.topicFactory = topicFactory; 58 this.topic = topic; 59 return; 60 } 61 62 67 public void sendMessage(String xmlMessage) throws JMSException { 68 TopicConnection connection = null; 69 TopicSession session = null; 70 try { 71 connection = topicFactory.createTopicConnection(); 72 session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); 73 TopicPublisher publisher = session.createPublisher(topic); 74 connection.start(); 75 TextMessage message = session.createTextMessage(); 76 message.setText(xmlMessage); 77 publisher.publish(message); 78 } finally { 79 try { 80 if(session != null) { 81 session.close(); 82 } 83 if(connection != null) { 84 connection.close(); 85 } 86 } catch(Exception exception) { 87 exception.printStackTrace(System.err); 88 } 89 } 90 return; 91 } 92 } 93 | Popular Tags |