Package javax.jms

Examples of javax.jms.QueueSession


      Queue queue = (Queue) ictx.lookup("queue");
      QueueConnectionFactory qcf = (QueueConnectionFactory) ictx.lookup("qcf");
      ictx.close();

      QueueConnection qc = qcf.createQueueConnection();
      QueueSession qs = qc.createQueueSession(true, 0);
      QueueSender qsend = qs.createSender(queue);
      TextMessage msg = qs.createTextMessage();

      qc.start();
      int i;
      for (i = 0; i < 10; i++) {
        msg.setText("Test number " + i);
        qsend.send(msg);
      }

      qs.commit();
      System.out.println(i + " messages sent.");
     
      qc.close();
    }
View Full Code Here


        Debug.print( "sendToJMSQueue(" + queueName + "," + obj + "," + transacted + ")" );

        InitialContext  ic = null;
        QueueConnection cnn = null;
        QueueSender     sender = null;
        QueueSession    session = null;

        try
        {
            ic = new InitialContext(  );

            Queue                  queue = ( Queue ) ic.lookup( queueName );

            QueueConnectionFactory factory = ( QueueConnectionFactory ) ic.lookup( JNDINames.QUEUE_CONNECTION_FACTORY );
            cnn     = factory.createQueueConnection(  );
            session = cnn.createQueueSession( transacted, QueueSession.AUTO_ACKNOWLEDGE );

            ObjectMessage msg = session.createObjectMessage( obj );

            sender = session.createSender( queue );
            sender.send( msg );
        }
        finally
        {
            if ( sender != null )
            {
                sender.close(  );
            }

            if ( session != null )
            {
                session.close(  );
            }

            if ( cnn != null )
            {
                cnn.close(  );
View Full Code Here

                    // queue and consumer
                    //
                    ret = sendOnlySessionCache.poll();

                    if (ret != null) {
                        QueueSession session = (QueueSession)ret.session();
                        Queue destination = null;
                        String selector = null;
                       
                        if (null != theReplyDestination || null != replyDest) {
                            destination = null != replyDest ? (Queue) replyDest : (Queue)theReplyDestination;
                           
                            selector = "JMSCorrelationID = '" + generateUniqueSelector(ret) + "'";
                        }
                       
                        ret.destination(destination);
                        MessageConsumer consumer = session.createReceiver(destination, selector);
                        ret.consumer(consumer);
                    } else {
                        // no pooled session available in either cache => create one in
                        // in the reply capable cache
                        //
View Full Code Here

     * @param consumer true iff consuming
     * @param destination the target destination
     * @return an appropriate pooled session
     */
    PooledSession createPointToPointReplyCapableSession() throws JMSException {
        QueueSession session =
            ((QueueConnection)theConnection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        Destination destination = null;
        String selector = null;
       
        if (null != theReplyDestination) {
            destination = theReplyDestination;
           
            selector =  "JMSCorrelationID = '" + generateUniqueSelector(session) + "'";
           
           
        } else {
            destination = session.createTemporaryQueue();
        }
       
        MessageConsumer consumer = session.createReceiver((Queue)destination, selector);
        return new PooledSession(session,
                                 destination,
                                 session.createSender(null),
                                 consumer);
    }
View Full Code Here

     * Helper method to create a point-to-point pooled session.
     *
     * @return an appropriate pooled session
     */
    PooledSession createPointToPointSendOnlySession() throws JMSException {
        QueueSession session =
            ((QueueConnection)theConnection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

        return new PooledSession(session, null, session.createSender(null), null);
    }
View Full Code Here

     *
     * @param destination the target destination
     * @return an appropriate pooled session
     */
    private PooledSession createPointToPointServerSession(Destination destination) throws JMSException {
        QueueSession session =
            ((QueueConnection)theConnection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);


        return new PooledSession(session, destination, session.createSender(null),
                                 session.createReceiver((Queue)destination,
                                 jmsServerPolicy.getMessageSelector()));
    }
View Full Code Here

    private void sendMessage() throws Exception {
        // Create connection
        QueueConnection queueConnection = queueConnectionFactory.createQueueConnection();

        // Create session
        QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

        // Create sender
        QueueSender queueSender = queueSession.createSender(timerQueue);

        // Send message
        TextMessage message = queueSession.createTextMessage();
        message.setText("Sending a message");
        queueSender.send(message);
        System.out.println(" SLSB -> Message sent");

        // Close JMS objects
        queueSender.close();
        queueSession.close();
        queueConnection.close();

    }
View Full Code Here

        // Create connection
        QueueConnection queueConnection = queueConnectionFactory.createQueueConnection();

        // Create session
        QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

        // Create sender
        QueueSender queueSender = queueSession.createSender(queue);

        // Create sender for context MDB
        QueueSender queueSenderContext = queueSession.createSender(queueContext);

        // Send messages
        TextMessage message = null;
        for (int i = 0; i < NUMBER_MESSAGES; i++) {
            message = queueSession.createTextMessage();
            String text = "Message_" + i;
            message.setText(text);
            queueSender.send(message);
            System.out.println("Message [" + message.getJMSMessageID() + ", text:" + text + "] sent");
        }

        message = queueSession.createTextMessage();
        message.setText("Message that should be accepted after several attempts");
        queueSenderContext.send(message);

        // Close JMS objects
        queueSender.close();
        queueSenderContext.close();
        queueSession.close();
        queueConnection.close();

    }
View Full Code Here

   {
      QueueConnectionFactory qcf = (QueueConnectionFactory)ic.lookup("/ConnectionFactory");
      Queue queue = (Queue)ic.lookup("/queue/Queue");

      QueueConnection qc =  qcf.createQueueConnection();
      QueueSession qs = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

      QueueReceiver qreceiver = qs.createReceiver(queue, "targetMessage = TRUE");

      qc.start();

      TextMessage m = qs.createTextMessage();
      m.setText("one");
      m.setBooleanProperty("targetMessage", false);

      QueueSender qsender = qs.createSender(queue);

      qsender.send(m);

      m.setText("two");
      m.setBooleanProperty("targetMessage", true);
View Full Code Here

   public void testQueueRequestor() throws Exception
   {
      // Set up the requestor
      QueueConnection conn1 = cf.createQueueConnection();
      QueueSession sess1 = conn1.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
      QueueRequestor requestor = new QueueRequestor(sess1, queue);
      conn1.start();
     

      // And the responder
      QueueConnection conn2 = cf.createQueueConnection();
      QueueSession sess2 = conn2.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
      TestMessageListener listener = new TestMessageListener(sess2);
      QueueReceiver receiver = sess2.createReceiver(queue);
      receiver.setMessageListener(listener);
      conn2.start();
     
      Message m1 = sess1.createMessage();
      log.trace("Sending request message");
View Full Code Here

TOP

Related Classes of javax.jms.QueueSession

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.