Package javax.jms

Examples of javax.jms.TextMessage


    * Send the given String as a JMS message to the testQueue queue.
    */
   public void send(String msg) throws JMSException {

      // Create a message
      TextMessage message = queueSession.createTextMessage();
      message.setText(msg);

      // Send the message
      queueSender.send(queue, message);
   }
View Full Code Here


    String location = System.getProperty("location");
    if (location != null)
      System.out.println("Publishes messages on topic on " + location);

    TextMessage msg = session.createTextMessage();

    int i;
    for (i = 0; i < 10; i++) {
      msg.setText("Msg " + i);
      pub.send(msg);
    }
    session.commit();

    System.out.println(i + " messages published.");
View Full Code Here

    Connection cnx = cf.createConnection("anonymous", "anonymous");
    Session sess = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer pub = sess.createProducer(topic);

    TextMessage msg = sess.createTextMessage();

    int i;
    for (i = 0; i < 1000; i++) {
      msg.setText("Msg " + i);
      pub.send(msg);
      Thread.sleep(250L);
      System.out.println("publish message " + i);
    }
  }
View Full Code Here

    MessageConsumer consumer = session.createConsumer(dmq);

    cnx.start();
   
    for (int i=0; i<3; i++) {
      TextMessage msg = (TextMessage) consumer.receive();
      System.out.println("\nreceives: \"" + msg.getText() + "\", " +
                         "JMS_JORAM_ERRORCOUNT=" + msg.getIntProperty("JMS_JORAM_ERRORCOUNT"));
      System.out.println("JMS_JORAM_ERRORCAUSE_1=" + msg.getStringProperty("JMS_JORAM_ERRORCAUSE_1") + ", " +
                         "JMS_JORAM_ERRORCODE_1=" + msg.getStringProperty("JMS_JORAM_ERRORCODE_1"));
      System.out.println("JMSXDeliveryCount=" + msg.getIntProperty("JMSXDeliveryCount"));
    }

    cnx.close();
  }
View Full Code Here

      System.out.println("OutboundConsumer ok");

      oc.start();
      System.out.println();
      System.out.println("Without MessageListener");
      TextMessage msg = os.createTextMessage("avec queue");
      prod.send(msg);
      TextMessage msg1 =(TextMessagecons.receive();
      System.out.println("msg receive :"+msg1.getText());
      System.out.println();

      System.out.println("With MessageListener");
      MessagePointFactory  mep = new MessagePointFactory();
      ActivationSpecImpl spec = new ActivationSpecImpl();
      spec.setResourceAdapter(ja);
      spec.setDestinationType("javax.jms.Queue");
      spec.setDestination("queue");

      MessagePointFactory mep2 = new MessagePointFactory();
      ActivationSpecImpl spec2 = new ActivationSpecImpl();
      spec2.setResourceAdapter(ja);
      spec2.setDestinationType("javax.jms.Topic");
      spec2.setDestination("topic");
     
     
      ja.endpointActivation(mep , spec); // listener on queue
      ja.endpointActivation(mep2 , spec2);// listener on topic
    
     
      System.out.println("new thread producer on queue");
      new Thread() {
    public void run() {
        int i = 0;
        try {
      while(i!=100){
                          i++;
                          TextMessage msg = os.createTextMessage("with queue "+i);
                          prod.send(msg);
      }
        } catch (Exception exc) {
     
        }
    }
      }.start();
      System.out.println("new thread producer on topic");
      new Thread() {
    public void run() {
        int i = 0;
        try {
      while(i!=100){
          i++;
          TextMessage msg = os.createTextMessage("with topic2 "+i);
          prod1.send(msg);
      }
        } catch (Exception exc) {
     
        }
View Full Code Here

    cnx.start();

    // Producing messages with a very short time to live: 20 ms.
    System.out.println("Sends Message1 with a very short time to live");
    TextMessage msg = prodSession.createTextMessage("Message1");
    producer.send(queue1, msg, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, 20);
   
    // Waiting for the message to be expired.
    System.out.println("Waits for the message to be expired");
    Thread.sleep(100);

    msg = (TextMessage) consumer.receiveNoWait();
    System.out.println("receives: " + msg);
   
    // Producing "undeliverable" messages
    System.out.println("Send Message2");  
    msg = prodSession.createTextMessage("Message2");
    producer.send(queue1, msg);
   
    msg = (TextMessage) consumer.receive();
    System.out.println("Receives: " + msg.getText() + " then deny it!");
    consSession.rollback();
   
    msg = (TextMessage) consumer.receive();
    System.out.println("Receives: " + msg.getText() + " then deny it!");
    consSession.rollback();
       
    // Producing "forbidden" messages
    System.out.println("Send Message3");  
    msg = prodSession.createTextMessage("Message3");
View Full Code Here

    Connection cnx = tcf.createConnection("anonymous", "anonymous");
    Session sess = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer pub = sess.createProducer(topic);

    TextMessage msg = sess.createTextMessage();

    int i;
    for (i = 0; i < 5000; i++) {
      msg.setText("Msg " + i);
      pub.send(msg);
      Thread.sleep(250L);
      System.out.println("publish message " + i);
    }
  }
View Full Code Here

public class AProducer {
  public static void main(String[] args) throws Exception {
    Session session = null;
    Connection cnx = null;
    MessageProducer  producer = null;
    TextMessage message = null;
    Queue queue = null;
    ConnectionFactory cf = null;

    Context initialContext = new InitialContext();
    cf = (ConnectionFactory) initialContext.lookup("cf");
    queue = (Queue) initialContext.lookup("queue");
    initialContext.close();

    cnx = cf.createConnection();
   
    session = cnx.createSession(true, Session.AUTO_ACKNOWLEDGE);
    cnx.start();

    producer = session.createProducer(queue);
    message = session.createTextMessage();

    for (int i = 1; i <= 100000; i++) {
      message.setText("Test number " + i);
      producer.send(message);

      if ((i % 100) == 0)session.commit();

      if ((i % 1000) == 0) System.out.println(i + " messages sent");
View Full Code Here

    Connection cnx = cf.createConnection();
    Session sess = cnx.createSession(true, 0);

    MessageProducer producer = sess.createProducer(null);

    TextMessage msg = sess.createTextMessage();

    for (int i = 1; i <= 10; i++) {
      msg.setText("Soap test " + i);
      producer.send(queue, msg);
      System.out.println("SOAP test " + i);
    }

    sess.commit();
View Full Code Here

    ictx.close();

    Connection cnx = cf.createConnection();
    Session sess = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = sess.createProducer(null);
    TextMessage msg = sess.createTextMessage();

    msg.setText("Test transfer " + file);
    if (user != null && pass != null)
      msg.setStringProperty("url", "ftp://" + user + ':' + pass + '@' + host + '/' + file + ";type=i");
    else
      msg.setStringProperty("url", "ftp://" + host + '/' + file + ";type=i");
    msg.setLongProperty("crc", new File(".", file).length());
    msg.setBooleanProperty("ack", false);

    msg.setLongProperty("date", System.currentTimeMillis());

    producer.send(queue, msg);

    System.out.println("message send");
View Full Code Here

TOP

Related Classes of javax.jms.TextMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.