Package javax.jms

Examples of javax.jms.Connection


    ictx = new InitialContext();
    Topic topic = (Topic) ictx.lookup("sendMailTopic");
    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.");

    cnx.close();
  }
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);
    MessageConsumer sub = sess.createConsumer(topic);

    sub.setMessageListener(new Listener());

    cnx.start();

    System.in.read();

    System.out.println();
    System.out.println("Subscriber closed.");
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);
    MessageProducer producer = sess.createProducer(null);

    Message msg = sess.createMessage();
    msg.setStringProperty("expiration", "0");
    msg.setStringProperty("persistent", "true");
    msg.setStringProperty("acquisition.period", "30000");
    msg.setStringProperty("collector.url", "http://www.gnu.org/licenses/lgpl-3.0.txt");
    msg.setStringProperty("collector.type", "5");
    producer.send(queue, msg);
//    producer.send(topic, msg);

    System.out.println("messages sent.");

    cnx.close();
  }
View Full Code Here

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

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

    Message msg1 = sess.createMessage();
    msg1.setStringProperty("Joram#0:type=Destination,name=*",
                           "NbMsgsReceiveSinceCreation,NbMsgsSentToDMQSinceCreation");
    prod.send(msg1);
    System.out.println(" --> Monitoring message sent: " + msg1.getJMSMessageID());
   
    Message msg2 = cons.receive();
   
    System.out.println(" --> Monitoring message received: " + msg2.getJMSMessageID());
    try {
      Monitor.doReport(msg2);
    } catch (JMSException exc) {
      exc.printStackTrace();
    }

    cnx.close();

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

   */
  public static JoramAdmin doCreate(AbstractConnectionFactory cf,
                             String name,
                             String password,
                             String identityClass) throws ConnectException, AdminException {
    Connection cnx = null;

    //  set identity className
    cf.setIdentityClassName(identityClass);
    try {
      cnx = cf.createConnection(name, password);
      cnx.start();

      return new JoramAdmin(cnx);
    } catch (JMSSecurityException exc) {
      if (logger.isLoggable(BasicLevel.DEBUG))
        logger.log(BasicLevel.DEBUG, "JoramAdmin - error during creation", exc);
View Full Code Here

        }

        // get JMS connection resources and destination
        //
        Context context = JMSUtils.getInitialContext(addrDetails);
        Connection connection = null;
       
        if (JMSConstants.JMS_QUEUE.equals(addrDetails.getDestinationStyle().value())) {
            QueueConnectionFactory qcf =
                (QueueConnectionFactory)context.lookup(addrDetails.getJndiConnectionFactoryName());
            if (addrDetails.isSetConnectionUserName()) {
                connection = qcf.createQueueConnection(addrDetails.getConnectionUserName(),
                                                       addrDetails.getConnectionPassword());
            } else {
                connection = qcf.createQueueConnection();
            }
        } else {
            TopicConnectionFactory tcf =
                (TopicConnectionFactory)context.lookup(addrDetails.getJndiConnectionFactoryName());
            if (addrDetails.isSetConnectionUserName()) {
                connection = tcf.createTopicConnection(addrDetails.getConnectionUserName(),
                                                       addrDetails.getConnectionPassword());
            } else {
                connection = tcf.createTopicConnection();
            }
        }

        connection.start();

        Destination requestDestination =
                (Destination)context.lookup(
                                           addrDetails.getJndiDestinationName());
View Full Code Here

public class DefaultJmsProducer extends JmsProducerImpl {

    private Connection connection;

    public static DefaultJmsProducer newInstance(ConnectionFactory factory, JmsProducerConfig config) throws JMSException {
        Connection connection = factory.createConnection();

        String clientID = config.getClientID();
        if (clientID != null) {
            connection.setClientID(clientID);
        }
       
        // lets start the connection in case that we consume on the same connection
        connection.start();

        return newInstance(connection, config);
    }
View Full Code Here

    }

    public void close() throws JMSException {
        super.close();
        if (connection != null) {
            Connection tmp = connection;
            connection = null;
            tmp.close();
        }
    }
View Full Code Here

            "with HTTP transport enabled, skipping test ...");
         return;
      }

      // send a bunch of messages and let them accumulate in the queue
      Connection conn = cf.createConnection();
      Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      MessageProducer prod = session.createProducer(queue);

      int messageCount = 20;

      for(int i = 0; i < messageCount; i++)
      {
         Message m = session.createTextMessage("krakatau" + i);
         prod.send(m);
      }

      conn.close();

      // make sure messages made it to the queue
      Integer count = (Integer)ServerManagement.getAttribute(queueObjectName, "MessageCount");
      assertEquals(messageCount, count.intValue());


      conn = cf.createConnection();
      session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      MessageConsumer cons = session.createConsumer(queue);

      conn.start();

      // messages will be sent in bulk from server side, on the next HTTP client listner poll

      for(int i = 0; i < messageCount; i++)
      {
         TextMessage t = (TextMessage)cons.receive(2000);
         assertNotNull(t);
         assertEquals("krakatau" + i, t.getText());
      }
     
      conn.close();

   }
View Full Code Here

   }

  
   public void testReceiveWithClientAckThenCloseSession() throws Exception
   {
      Connection conn = null;
     
      try
      {
         conn = cf.createConnection();
        
         Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        
         MessageProducer prod = sess.createProducer(queue);
        
         final int NUM_MESSAGES = 5;
        
         for (int i = 0; i < NUM_MESSAGES; i++)
         {
            TextMessage tm = sess.createTextMessage("message" + i);
           
            prod.send(tm);
         }
        
         Session sess2 = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        
         MessageConsumer cons = sess2.createConsumer(queue);
        
         conn.start();
        
         for (int i = 0; i < NUM_MESSAGES; i++)
         {
            TextMessage tm = (TextMessage)cons.receive(500);
           
            assertNotNull(tm);
           
            assertEquals("message" + i, tm.getText());
         }
        
         // Now close the session

         sess2.close();
        
      }
      finally
      {
         if (conn != null)
         {
            conn.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.