public static void main(String[] args) { Producer producer = new Producer(); try { producer.start(); } catch (JMSException | NamingException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public void start() throws JMSException, NamingException { Context ctx = getInitialContext(); TopicConnectionFactory tcf = (TopicConnectionFactory) ctx.lookup("ConnectionFactory"); Topic t = (Topic) ctx.lookup("topic/i_jms"); TopicConnection tconn = tcf.createTopicConnection(); TopicSession tses = tconn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); TopicPublisher tpub = tses.createPublisher(t); tconn.start(); for (int i = 0; i < 10; i++) { Producer.sendMessage("Message= " + i, tses, tpub); try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } tpub.close(); }