Examples of QueueConnection


Examples of javax.jms.QueueConnection

   {
      log.info("+++ testOnCreateMDBTimer");
      InitialContext ctx = new InitialContext();
      QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");

      QueueConnection queConn = null;
      QueueSession session = null;
      QueueSender sender = null;
      QueueReceiver receiver = null;

      try
      {
         queConn = factory.createQueueConnection();
         queConn.start();

         Queue queueA = (Queue) ctx.lookup("queue/C");
         Queue queueB = (Queue) ctx.lookup("queue/D");

         session = queConn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
         sender = session.createSender(queueA);
         receiver = session.createReceiver(queueB);

         while (receiver.receive(1000) != null)
         {
            // Empty the queue
         }

         TextMessage message = session.createTextMessage();
         message.setText("testOnCreateMDBTimer");
         message.setIntProperty("UNIQUE_ID", 123456788);
         message.setJMSReplyTo(queueB);
         sender.send(message);

         // Get the initial onMessage ack
         Message reply = receiver.receive(15000);
         log.info("onMessage reply: " + reply);
         assertTrue("onMessage reply != null", reply != null);
         int id = reply.getIntProperty("UNIQUE_ID");
         assertTrue("onMessage reply.id = 123456788", id == 123456788);

         // Get the 10 ejbCreate timer replys
         for(int n = 0; n < 10; n ++)
         {
            reply = receiver.receive(15000);
            log.info("ejbTimeout reply: " + reply);
            assertTrue("ejbTimeout reply != null", reply != null);
            id = reply.getIntProperty("UNIQUE_ID");
            assertTrue("onMessage reply.id = 123456788", id == 123456788);
            long elapsed = reply.getLongProperty("Elapsed");
            log.info("Elapsed: "+elapsed);
         }
      }
      finally
      {
         if (receiver != null)
         {
            try
            {
               receiver.close();
            } catch (JMSException ignore)
            {
               //
            }
         }
         if (sender != null)
         {
            try
            {
               sender.close();
            } catch (JMSException ignore)
            {
               //
            }
         }
         if (session != null)
         {
            try
            {
               session.close();
            } catch (JMSException ignore)
            {
               //
            }
         }
         if (queConn != null)
         {
            try
            {
               queConn.close();
            } catch (JMSException ignore)
            {
               //
            }
         }
View Full Code Here

Examples of javax.jms.QueueConnection

      // Get the ConnectionFactory from JNDI
      final QueueConnectionFactory factory = (QueueConnectionFactory) NAMING_CONTEXT
            .lookup(JNDI_NAME_CONNECTION_FACTORY);

      // Make a Connection
      final QueueConnection connection = factory.createQueueConnection();
      final QueueSession sendSession = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);

      // Make the message
      final TextMessage message = sendSession.createTextMessage(contents);

      // Send the message
      final QueueSender sender = sendSession.createSender(queue);
      sender.send(message);
      log.info("Sent message " + message + " with contents: " + contents);

      // Clean up
      sendSession.close();
      connection.close();
   }
View Full Code Here

Examples of javax.jms.QueueConnection

    protected void doPost(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {

        try {

            PrintWriter out = arg1.getWriter();
            QueueConnection connection = qcf.createQueueConnection();
            connection.start();
            QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
            QueueReceiver queueReceiver = session.createReceiver(queue);
            Message msg = queueReceiver.receiveNoWait();

            if ( msg instanceof TextMessage ) {
                TextMessage txtMsg = (TextMessage)msg;
                System.out.println("Message : "+txtMsg.getText());
                out.println("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>");
                out.println("<head><title>JMS Receiver</title></head>");
                out.println("<body>Received JMS Queue Message</body></html>");
            }
            else {
                out.println("<body>Did Not Receive JMS Queue Message</body></html>");
            }

            queueReceiver.close();
            session.close();
            connection.stop();

        }
        catch ( Exception e ) {
            e.printStackTrace();
        }
View Full Code Here

Examples of javax.jms.QueueConnection

     */
    protected void doPost(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
        try {

            PrintWriter out = arg1.getWriter();
            QueueConnection connection = qcf.createQueueConnection();
            connection.start();
            QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
            QueueSender queueSender = session.createSender(queue);
            TextMessage tmsg = session.createTextMessage("JMS - Test Queue Message");
            queueSender.send(tmsg);
            queueSender.close();
            session.close();
            connection.stop();
            out.println("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>");
            out.println("<head><title>JMS Sender</title></head>");
            out.println("<body>Sent JMS Queue Message</body></html>");
        }
        catch ( Exception e ) {
View Full Code Here

Examples of javax.jms.QueueConnection

            Destination dest = (Destination) kernel.invoke(adminObjectName,
                    "$getResource");
            if (dest instanceof Queue) {
                Queue queue = (Queue) dest;
                QueueConnectionFactory qConFactory = null;
                QueueConnection qConnection = null;
                QueueSession qSession = null;
                QueueBrowser qBrowser = null;
                try {
                    qConFactory = (QueueConnectionFactory) kernel.invoke(
                            ObjectName.getInstance(CONNECTION_FACTORY_NAME),
                            "$getResource");
                    qConnection = qConFactory.createQueueConnection();
                    qSession = qConnection.createQueueSession(false,
                            QueueSession.AUTO_ACKNOWLEDGE);
                    qBrowser = qSession.createBrowser(queue);
                    qConnection.start();
                    for (Enumeration e = qBrowser.getEnumeration(); e
                            .hasMoreElements();) {
                        Object o = e.nextElement();
                        ret.add(o);
                    }
                    qConnection.stop();
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    try {
                        if (qBrowser != null) {
                            qBrowser.close();
                        }
                    } catch (JMSException ignore) {
                    }
                    try {
                        if (qSession != null) {
                            qSession.close();
                        }
                    } catch (JMSException ignore) {
                    }
                    try {
                        if (qConnection != null) {
                            qConnection.close();
                        }
                    } catch (JMSException ignore) {
                    }
                }
            } else if (dest instanceof Topic) {
View Full Code Here

Examples of javax.jms.QueueConnection

    }

    private void exerciseQueueOnServer(final String queueName, final ServerIdentity server) throws Exception {
        stdout.println("Exercising queue " + queueName + " on server " + server.getServerName());

        QueueConnection conn = null;
        QueueSession session = null;
        try {
            QueueConnectionFactory qcf = lookup(server, "RemoteConnectionFactory", QueueConnectionFactory.class);
            Queue queue = lookup(server, queueName, Queue.class);

            conn = qcf.createQueueConnection();
            conn.start();
            session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);

            // Set the async listener
            QueueReceiver recv = session.createReceiver(queue);
            recv.setMessageListener(new MessageListener() {

                @Override
                public void onMessage(Message message) {
                    TextMessage msg = (TextMessage)message;
                    try {
                        stdout.println("---->Received: " + msg.getText());
                    } catch (JMSException e) {
                        e.printStackTrace();
                    }
                }
            });

            QueueSender sender = session.createSender(queue);
            for (int i = 0 ; i < 10 ; i++) {
                String s = "Test" + i;
                stdout.println("----> Sending: " +s );
                TextMessage msg = session.createTextMessage(s);
                sender.send(msg);
            }
        }
        finally {
            try {
                conn.stop();
            } catch (Exception ignore) {
            }
            try {
                session.close();
            } catch (Exception ignore) {
            }
            try {
                conn.close();
            } catch (Exception ignore) {
            }
        }
    }
View Full Code Here

Examples of javax.jms.QueueConnection

public class ExampleRunner {

    private static final String QUEUE_NAME = "createdTestQueue";

    public static void main(String[] args) throws Exception {
        QueueConnection conn = null;
        QueueSession session = null;
        ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getByName("localhost"), 9999);
        //TODO Don't do this FakeJndi stuff once we have remote JNDI working
        DeploymentUtils utils = null;
        boolean actionsApplied = false;
        try {
            utils = new DeploymentUtils("fakejndi.sar", FakeJndi.class.getPackage());
            utils.deploy();

            ModelNode op = new ModelNode();
            op.get("operation").set("add");
            op.get("address").add("subsystem", "jms");
            op.get("address").add("queue", QUEUE_NAME);
            op.get("entries").add(QUEUE_NAME);
            applyUpdate(op, client);
            actionsApplied = true;

            QueueConnectionFactory qcf = lookup(utils, "RemoteConnectionFactory", QueueConnectionFactory.class);
            Queue queue = lookup(utils, QUEUE_NAME, Queue.class);

            conn = qcf.createQueueConnection();
            conn.start();
            session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);

            // Set the async listener
            QueueReceiver recv = session.createReceiver(queue);
            recv.setMessageListener(new MessageListener() {

                @Override
                public void onMessage(Message message) {
                    TextMessage msg = (TextMessage)message;
                    try {
                        System.out.println("---->Received: " + msg.getText());
                    } catch (JMSException e) {
                        e.printStackTrace();
                    }
                }
            });

            QueueSender sender = session.createSender(queue);
            for (int i = 0 ; i < 10 ; i++) {
                String s = "Test" + i;
                System.out.println("----> Sending: " +s );
                TextMessage msg = session.createTextMessage(s);
                sender.send(msg);
            }

            Thread.sleep(1000);

        } finally {
            try {
                conn.stop();
            } catch (Exception ignore) {
            }
            try {
                session.close();
            } catch (Exception ignore) {
            }
            try {
                conn.close();
            } catch (Exception ignore) {
            }

            if(utils != null) {
                utils.undeploy();
View Full Code Here

Examples of javax.jms.QueueConnection

*/
public class ExampleRunner {

    public static void main(String[] args) throws Exception {
        DeploymentUtils utils = null;
        QueueConnection conn = null;
        QueueSession session = null;
        //TODO Don't do this FakeJndi stuff once we have remote JNDI working
        try {
            utils = new DeploymentUtils("fakejndi.sar", FakeJndi.class.getPackage());
            utils.addWarDeployment("webapp-example.war", SimpleServlet.class.getPackage());
            utils.deploy();

            QueueConnectionFactory qcf = lookup(utils, "RemoteConnectionFactory", QueueConnectionFactory.class);
            Queue queue = lookup(utils, "queue/test", Queue.class);
            conn = qcf.createQueueConnection();
            conn.start();
            session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);

            // Set the async listener
            QueueReceiver recv = session.createReceiver(queue);
            recv.setMessageListener(new MessageListener() {

                @Override
                public void onMessage(Message message) {
                    TextMessage msg = (TextMessage)message;
                    try {
                        System.out.println("---->Received from queue: " + msg.getText());
                    } catch (JMSException e) {
                        e.printStackTrace();
                    }
                }
            });


            connect("other?value=One");
            connect("simple?value=Two");
            connect("other?value=Three");
        } finally {
            utils.undeploy();
            safeClose(utils);
            if(conn != null) {
                conn.close();
            }
        }
    }
View Full Code Here

Examples of javax.jms.QueueConnection

    * created.
    */
   public void testQueueConnectionFactory() throws Exception
   {
      QueueConnectionFactory qcf = (QueueConnectionFactory)ic.lookup("/ConnectionFactory");
      QueueConnection qc = qcf.createQueueConnection();
      qc.close();
   }
View Full Code Here

Examples of javax.jms.QueueConnection

        filteredQueue.remove( work );
      }
    }
    if ( filteredQueue.size() == 0) return;
    factory.prepareJMSTools();
    QueueConnection cnn = null;
    QueueSender sender;
    QueueSession session;
    try {
      cnn = factory.getJMSFactory().createQueueConnection();
      //TODO make transacted parameterized
      session = cnn.createQueueSession( false, QueueSession.AUTO_ACKNOWLEDGE );

      ObjectMessage message = session.createObjectMessage();
      message.setObject( (Serializable) filteredQueue );

      sender = session.createSender( factory.getJmsQueue() );
      sender.send( message );

      session.close();
    }
    catch (JMSException e) {
      throw new HibernateException( "Unable to send Search work to JMS queue: " + factory.getJmsQueueName(), e );
    }
    finally {
      try {
        if (cnn != null)
          cnn.close();
        }
      catch ( JMSException e ) {
        log.warn( "Unable to close JMS connection for " + factory.getJmsQueueName(), e );
      }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.