public void onMessage(Message message) { try { MapMessage request = (MapMessage) message; String correlationID = request.getJMSCorrelationID(); int itemId = request.getInt("itemId"); // Retrieve the connection factory connectionFactory = (TopicConnectionFactory) initialContext.lookup(BeanConfig.TopicConnectionFactoryName); // get the bids history String html = getBidHistory(itemId); // send the reply TemporaryTopic temporaryTopic = (TemporaryTopic) request.getJMSReplyTo(); if (temporaryTopic != null) { // create a connection connection = connectionFactory.createTopicConnection(); // create a session: no transaction, auto ack session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); TextMessage reply = session.createTextMessage(); reply.setJMSCorrelationID(correlationID); reply.setText(html); replier = session.createPublisher(null); // unidentified publisher connection.start(); replier.publish(temporaryTopic, reply); replier.close(); session.close(); connection.stop(); connection.close(); } } catch (Exception e) { throw new EJBException("Message traitment failed for MDB_ViewBidHistory: " + e); } }
private void writeMessage(String s) throws JMSException { TextMessage message = session.createTextMessage(); message.setStringProperty("language", "java"); message.setText(s); System.out.println("sending text message " + message); pub.publish(message); }
public static void sendMessage(String m, TopicSession tses, TopicPublisher tpub) { try { TextMessage tm = tses.createTextMessage(m); tpub.publish(tm); } catch (JMSException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public static void topicPublish( TopicConnection cnn, String topicName, String payload, boolean transacted, int ack, String replyTo) throws JMSException { TopicSession session = cnn.createTopicSession(transacted, ack); Topic topic = session.createTopic(topicName); TopicPublisher publisher = session.createPublisher(topic); TextMessage msg = session.createTextMessage(); msg.setText(payload); msg.setJMSDeliveryMode(ack); if (replyTo != null) { msg.setJMSReplyTo(session.createTopic(replyTo)); } publisher.publish(msg); publisher.close(); session.close(); }
public tibjmsLoadBalancedTopicPublisher(String[] args) { parseArgs(args); /* print parameters */ System.out.println( "\n------------------------------------------------------------------------"); System.out.println("tibjmsLoadBalancedTopicPublisher SAMPLE"); System.out.println("------------------------------------------------------------------------"); System.out.println("Servers...................... " + serverList); System.out.println("User......................... " + (userName != null ? userName : "******")); System.out.println("Topic........................ " + topicName); System.out.println("Messages..................... " + messages); System.out.println("Delay........................ " + delay); System.out.println( "------------------------------------------------------------------------\n"); System.err.println("Publishing on topic '" + topicName + "'\n"); try { HashMap properties = new HashMap(); Integer metric; if (balanceByConnections) metric = new Integer(Tibjms.FACTORY_LOAD_BALANCE_METRIC_CONNECTIONS); else metric = new Integer(Tibjms.FACTORY_LOAD_BALANCE_METRIC_BYTE_RATE); properties.put(Tibjms.FACTORY_LOAD_BALANCE_METRIC, metric); TopicConnectionFactory factory = new com.tibco.tibjms.TibjmsTopicConnectionFactory(serverList, null, properties); TopicConnection connection = factory.createTopicConnection(userName, password); TopicSession session = connection.createTopicSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE); /* * Use createTopic() to enable publishing into dynamic topics. */ javax.jms.Topic topic = session.createTopic(topicName); TopicPublisher publisher = session.createPublisher(topic); /* publish messages */ for (int i = 0; i < messages; i++) { javax.jms.TextMessage message = session.createTextMessage(); String text = "Load balanced message " + i; message.setText(text); publisher.publish(message); System.err.println( "Published message " + i + " to server " + Tibjms.getConnectionActiveURL(connection)); try { Thread.sleep(delay * 1000); } catch (InterruptedException e) { } } connection.close(); } catch (JMSException e) { e.printStackTrace(); System.exit(0); } }
public void publish() throws JMSException { testPublisher.publish(topicSession.createTextMessage("message for topic")); }