Package javax.jms

Examples of javax.jms.ConnectionFactory


      {
         // connecting to the first node

         ic = new InitialContext();

         ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
         Queue distributedQueue = (Queue)ic.lookup(destinationName);
         log("Distributed queue " + destinationName + " exists");


         // When connecting to a messaging cluster, the ConnectionFactory has the capability of
         // transparently creating physical connections to different cluster nodes, in a round
         // robin fashion ...

         // ... so this is a connection to a cluster node
         connection0 = cf.createConnection();

         // ... and this is a connection to a different cluster node
         connection1 = cf.createConnection();

         // Let's make sure that (this example is also a smoke test)
         assertNotEquals(getServerID(connection0), getServerID(connection1));

         // Create a session, a producer and a consumer on the first connection
View Full Code Here



      InitialContext ic = new InitialContext();


      ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
      Queue queue = (Queue)ic.lookup(destinationName);



      log("Queue " + destinationName + " exists");



      Connection connection = cf.createConnection();
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      MessageProducer sender = session.createProducer(queue);


View Full Code Here

   public void example() throws Exception
   {
      String destinationName = getDestinationJNDIName();
     
      InitialContext ic = null;
      ConnectionFactory cf = null;
      Connection connection =  null;
      Connection connection2 =  null;
     
      try
      {        
         ic = new InitialContext();
        
         cf = (ConnectionFactory)ic.lookup("/SecureConnectionFactory");
         Queue queue = (Queue)ic.lookup(destinationName);
         log("Queue " + destinationName + " exists");
        
         connection = cf.createConnection();
         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
         MessageProducer sender = session.createProducer(queue);
        
         TextMessage message = session.createTextMessage("Hello!");
         sender.send(message);
         log("The message was successfully sent to the " + queue.getQueueName() + " queue");
        
         connection2 = cf.createConnection();
         Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
         MessageConsumer consumer =  session2.createConsumer(queue);
        
         connection2.start();
        
View Full Code Here

        
         //Send some messages to durable sub
        
         InitialContext ic = new InitialContext(ServerManagement.getJNDIEnvironment());
        
         ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
        
         Topic topic = (Topic)ic.lookup("/topic/ReloadTopic");
  
         Connection conn = cf.createConnection();
        
         conn.start();
        
         conn.setClientID("wibble765");
        
         Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        
         MessageConsumer cons = sess.createDurableSubscriber(topic, "subxyz");
        
         MessageProducer prod = sess.createProducer(topic);
         prod.setDeliveryMode(DeliveryMode.PERSISTENT);
    
         for (int i = 0; i < 10; i++)
         {
            TextMessage tm = sess.createTextMessage();
           
            tm.setText("message:" + i);
           
            prod.send(tm);
         }
        
         conn.close();
        
         //Receive half of them
        
         conn = cf.createConnection();
        
         conn.setClientID("wibble765");
        
         sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        
         cons = sess.createDurableSubscriber(topic, "subxyz");
        
         conn.start();
        
         for (int i = 0; i < 5; i++)
         {
            TextMessage tm = (TextMessage)cons.receive(1000);
           
            assertNotNull(tm);
           
            assertEquals("message:" + i, tm.getText());
         }
        
         conn.close();
        
         //Undeploy and redeploy the queue
         //The last 5 persistent messages should still be there
        
         undeployDestination("ReloadTopic");
        
         deploy(config);
        
         topic = (Topic)ic.lookup("/topic/ReloadTopic");
        
         conn = cf.createConnection();
        
         conn.setClientID("wibble765");     
        
         sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        
View Full Code Here

         ServerManagement.startServerPeer();
      }
     
      ServerManagement.invoke(ServerManagement.getServerPeerObjectName(), "enableMessageCounters", null, null);
     
      ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
     
      ServerManagement.deployQueue("Queue1");
     
      ServerManagement.deployQueue("Queue2");
     
      ServerManagement.deployQueue("Queue3");
     
      ServerManagement.deployTopic("Topic1");
     
      ServerManagement.deployTopic("Topic2");
     
      Queue queue1 = (Queue)initialContext.lookup("/queue/Queue1");
     
      Queue queue2 = (Queue)initialContext.lookup("/queue/Queue2");
     
      Queue queue3 = (Queue)initialContext.lookup("/queue/Queue3");
     
      Topic topic1 = (Topic)initialContext.lookup("/topic/Topic1");
     
      Topic topic2 = (Topic)initialContext.lookup("/topic/Topic2");
     
      Connection conn = null;
     
      try
      {
         conn = cf.createConnection();
        
         conn.setClientID("wib");
        
         Integer i = (Integer)ServerManagement.getAttribute(ServerManagement.getServerPeerObjectName(), "DefaultMessageCounterHistoryDayLimit");
        
View Full Code Here

   }
  
   public void testConnectionConsumerWrongTemporaryDestination() throws Exception
   {
      InitialContext ctx = getInitialContext();
      ConnectionFactory factory = (ConnectionFactory) ctx.lookup("ConnectionFactory");
      Queue queue = null;
      Connection connection = factory.createConnection();
      try
      {
         Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
         queue = s.createTemporaryQueue();
         Connection connection2 = factory.createConnection();
         try
         {
            connection2.createConnectionConsumer(queue, "", MockServerSessionPool.getServerSessionPool(), 1);
            fail("Expected an error listening to a temporary destination from a different connection");
         }
View Full Code Here

   public Connection getConnection() throws Exception
   {
      if (connection != null)
         return connection;
     
      ConnectionFactory factory = (ConnectionFactory) lookup(connectionFactoryJNDI, ConnectionFactory.class);
      connection = factory.createConnection();
      connection.setExceptionListener(this);
      return connection;
   }
View Full Code Here

   public Connection getConnection(String user, String password, String clientID) throws Exception
   {
      if (connection != null)
         return connection;

      ConnectionFactory factory = (ConnectionFactory) lookup(connectionFactoryJNDI, ConnectionFactory.class);
      connection = factory.createConnection(user, password);
      if (clientID != null)
      {
         connection.setClientID(clientID);
      }
      connection.setExceptionListener(this);
View Full Code Here

      return cls.cast(getInitialContext().lookup(name));
   }
  
   public void testSendMessage() throws Exception
   {
      ConnectionFactory connFactory = lookup("ConnectionFactory", ConnectionFactory.class);
      Connection conn = connFactory.createConnection();
      conn.start();
      Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      TemporaryQueue replyQueue = session.createTemporaryQueue();
      TextMessage msg = session.createTextMessage("Hello world");
      msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
View Full Code Here

      InitialContext ctx = new InitialContext();
      Connection conn = null;
      try
      {
         Queue queue = (Queue)ctx.lookup(jndi);
         ConnectionFactory cf = (javax.jms.ConnectionFactory)ctx.lookup("ConnectionFactory");
         conn = cf.createConnection();
         Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
         conn.start();
         MessageConsumer cons = sess.createConsumer(queue);
        
         while (cons.receiveNoWait() != null);
View Full Code Here

TOP

Related Classes of javax.jms.ConnectionFactory

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.