Package javax.jms

Examples of javax.jms.MessageProducer


        MapMessage invoiceMessage = session.createMapMessage();
        invoiceMessage.setInt("orderId", orderId);
        invoiceMessage.setFloat("amount", amount);

        // send it!
        MessageProducer producer = session.createProducer(invoiceQueue);
        producer.send(invoiceMessage);

        logger.log(
            Level.FINE,
            "sent invoice message for PO #{0,number,integer} with amount {1,number,currency}",
            new Object[] { orderId, amount });
View Full Code Here


        // create the message
        MapMessage message = session.createMapMessage();
        message.setString("customerId", customerId);

        // send it!
        MessageProducer producer = session.createProducer(shippingQueue);
        producer.send(message);

        logger.log(Level.FINE, "sent shipping message for customer {0}",
            customerId);
      }
      finally {
View Full Code Here

      ictx.close();
    }

    Connection cnx = cf.createConnection("anonymous", "anonymous");
    Session session = cnx.createSession(true, 0);
    MessageProducer pub = session.createProducer(dest);

    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

    AdminModule.disconnect();


    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

    Connection cnx = cf.createConnection();
    Session prodSession = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Session consSession = cnx.createSession(true, 0);
   
    MessageProducer producer = prodSession.createProducer(null);
    MessageConsumer consumer = consSession.createConsumer(queue1);

    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");
    try {
      producer.send(queue2, msg);
    } catch (JMSException exc) {
      System.out.println(exc.getMessage());
    }
   
//    // Producing a message to a deleted destination
View Full Code Here

    Topic topic = (Topic) jndiCtx.lookup("topic");
    jndiCtx.close();

    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");
    }
    session.commit();
   
    producer.close();
    session.close();
    cnx.close();
  }
View Full Code Here

    ictx.close();

    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();
    cnx.close();
View Full Code Here

    ConnectionFactory cf = (ConnectionFactory) ictx.lookup("cf");
    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");

    cnx.close();
  }
View Full Code Here

    ConnectionFactory cf = (ConnectionFactory) ictx.lookup("cf");
    ictx.close();

    Connection cnx = cf.createConnection();
    Session sess = cnx.createSession(true, 0);
    MessageProducer producer = sess.createProducer(topic);

    System.out.println("Produces 5 messages on the MailTopic.");

    for (int i=0; i<5; i++) {
      TextMessage msg = sess.createTextMessage();
      msg.setBooleanProperty("showProperties", false);
      msg.setText("Queue : Test number #" + i);
      producer.send(msg);
    }
    sess.commit();

    System.out.println("Messages sent.");
View Full Code Here

TOP

Related Classes of javax.jms.MessageProducer

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.