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);
   }
 }
Exemple #2
0
 public static void main(String[] argv) throws Exception {
   TopicPublisher p = new TopicPublisher();
   String[] unknown = CommandLineSupport.setOptions(p, argv);
   if (unknown.length > 0) {
     System.out.println("Unknown options: " + Arrays.toString(unknown));
     System.exit(-1);
   }
   p.run();
 }
Exemple #3
0
  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);
  }
Exemple #4
0
 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();
 }
Exemple #5
0
  public ChatPublisher(String name, String topicName, boolean isDurable) throws JMSException {
    this.name = name;
    TopicConnectionFactory factory = new ActiveMQConnectionFactory("tcp://127.0.0.1:61616");
    conn = factory.createTopicConnection();
    session = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    pub = session.createPublisher(new ActiveMQTopic(topicName));

    if (isDurable) {
      pub.setDeliveryMode(DeliveryMode.PERSISTENT);
      //            pub.setTimeToLive(20000);
      System.out.println(" === persistence == ");
    }
  }
  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);
    }
  }