Package javax.jms

Examples of javax.jms.Connection


    Integer orderId = (Integer) servletContext.getAttribute(ORDER_ID_ATTR);
    Float linePrice = (Float) servletContext.getAttribute(LINE_PRICE_ATTR);
    float amount = linePrice + shippingPrice;

    // create a connection
    Connection connection = connectionFactory.createConnection();
    try {
      // create a session
      Session session =
          connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
      try {
        // create the message
        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 });
      }
      finally {
        session.close();
      }
    }
    finally {
      connection.close();
    }
  }
View Full Code Here


    shippingInfo.setShippingPrice(shippingPrice);
    return shippingInfo;
  }

  protected void sendShippingMessage(String customerId) throws JMSException {
    Connection connection = connectionFactory.createConnection();
    try {
      // create a session
      Session session =
          connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
      try {
        // 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 {
        session.close();
      }
    }
    finally {
      connection.close();
    }
  }
View Full Code Here

                                    "OutboundReceiver(" + queue +
                                    ", " + consumer +
                                    ", " + session + ")");
   
    if (queue instanceof TemporaryQueue) {
      Connection tempQCnx = ((TemporaryQueue) queue).getCnx();

      if (tempQCnx == null || !session.cnx.cnxEquals(tempQCnx))
        throw new JMSSecurityException("Forbidden consumer on this "
                                       + "temporary destination.");
    }
View Full Code Here

    ictx = new InitialContext();
    Topic topic = (Topic) ictx.lookup("topic");
    ConnectionFactory tcf = (ConnectionFactory) ictx.lookup("tcf");
    ictx.close();

    Connection cnx = tcf.createConnection();
    Session session = cnx.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
    TopicSubscriber subscriber = session.createDurableSubscriber(topic, "durable");
    subscriber.setMessageListener(new MsgListener());

    cnx.start();

    System.in.read();

    cnx.close();

    System.out.println("Subscription closed.");
  }
View Full Code Here

      }
    } finally {
      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.");

    cnx.close();
  }
View Full Code Here

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

    System.out.println("Trace2");

    Connection cnx = cf.createConnection();
    Session sess = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer cons = sess.createConsumer(queue);

    System.out.println("Listens to the MailQueue...");
    System.out.println("hit a key to stop.");

    cons.setMessageListener(new MsgListener("Queue listener"));

    cnx.start();

    System.in.read();
    cnx.close();

    System.out.println("Consumer closed.");
  }
View Full Code Here

    Topic topic = Topic.create(0,"topic");

    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;
View Full Code Here

    Queue queue = (Queue) ictx.lookup("queue");
    // Topic topic = (Topic) ictx.lookup("topic");
    ConnectionFactory cf = (ConnectionFactory) ictx.lookup("cf");
    ictx.close();

    Connection cnx = cf.createConnection();
    Session sess = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer recv = sess.createConsumer(queue);
    // MessageConsumer subs = sess.createConsumer(topic);

    recv.setMessageListener(new MsgListener("Collector Queue listener"));
    // subs.setMessageListener(new MsgListener("Colector Topic listener"));

    cnx.start();

    System.in.read();
    cnx.close();

    System.out.println();
    System.out.println("Consumer closed.");
  }
View Full Code Here

    Context ictx = new InitialContext();
    Topic topic = (Topic) ictx.lookup("MonitoringTopic");
    ConnectionFactory cf = (ConnectionFactory) ictx.lookup("cf");
    ictx.close();

    Connection cnx = cf.createConnection();
    Session sess = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer subs = sess.createConsumer(topic);

    subs.setMessageListener(new MonitorMsgListener());

    cnx.start();

    System.in.read();
    cnx.close();

    System.out.println();
    System.out.println("Consumer closed.");
  }
View Full Code Here

    Context ictx = new InitialContext();
    Queue dmq = (Queue) ictx.lookup("dmq");
    ConnectionFactory cf = (ConnectionFactory) ictx.lookup("cf");
    ictx.close();

    Connection cnx = cf.createConnection("anonymous", "anonymous");

    Session session = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
    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

TOP

Related Classes of javax.jms.Connection

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.