Package javax.jms

Examples of javax.jms.QueueConnection


  protected ConfigTree  _config;
  private Logger logger = Logger.getLogger(SimpleJMSNotifier.class);
  String queueName = "quickstart_helloworld_Request_gw";
 
  public Message process(Message message) throws Exception
     QueueConnection conn;
     QueueSession session;
     Queue que; 
    
     Properties properties1 = new Properties();
     properties1.put(Context.INITIAL_CONTEXT_FACTORY,
     "org.jnp.interfaces.NamingContextFactory");
     properties1.put(Context.URL_PKG_PREFIXES,
     "org.jboss.naming:org.jnp.interfaces");
     properties1.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099");
     InitialContext iniCtx = new InitialContext(properties1);

     Object tmp = iniCtx.lookup("ConnectionFactory");
     QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
     conn = qcf.createQueueConnection();
     que = (Queue) iniCtx.lookup("queue/" + queueName);
     session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
     conn.start();
     //logger.info("Connection Started");
    
     QueueSender send = session.createSender(que);       
     TextMessage tm = session.createTextMessage((String)message.getBody().get());
  tm.setStringProperty(StoreMessageToFile.PROPERTY_JBESB_FILENAME, "BPMOrchestration3Test.log");
     send.send(tm);       
     send.close();
    
     conn.stop();
     session.close();
     conn.close();
    
     return message;
  }
View Full Code Here


      environment.setProperty(Context.PROVIDER_URL, Environment.JBOSS_PROVIDER_URL);
      environment.setProperty(Context.INITIAL_CONTEXT_FACTORY, Environment.JBOSS_INITIAL_CONTEXT_FACTORY);
      environment.setProperty(Context.URL_PKG_PREFIXES, Environment.JBOSS_URL_PKG_PREFIX);
      final Context oCtx = NamingContextPool.getNamingContext(environment);
      try {
  QueueConnection oQconn = null;
  QueueSession   oQsess = null;
  QueueConnectionFactory qcf = (QueueConnectionFactory) oCtx
    .lookup("ConnectionFactory");

  oQconn = qcf.createQueueConnection();
  oQsess = oQconn.createQueueSession(false
      ,QueueSession.AUTO_ACKNOWLEDGE);
    Queue oQueue
      = (Queue) oCtx.lookup(p_sJndi);
    QueueReceiver oRcv = oQsess.createReceiver(oQueue);
    oQconn.start();
    return oRcv;
      } finally {
          NamingContextPool.releaseNamingContext(oCtx) ;
      }
  } //__________________________________
View Full Code Here

        m_oCmdSrc = oSess.createSubscriber(oTopic, sMsgSelector, true);
      }
      else
      {
        QueueConnectionFactory qcf = (QueueConnectionFactory) oFactCls;
        QueueConnection oQC = qcf.createQueueConnection();
        QueueSession oSess = oQC.createQueueSession(false,
            TopicSession.AUTO_ACKNOWLEDGE);
        javax.jms.Queue oQ = null;
        try
        {
          oQ = (javax.jms.Queue) oJndiCtx.lookup(sJndiName);
        }
        catch (NamingException ne)
        {
          oQ = oSess.createQueue(sJndiName);
        }
        oQC.start();
        m_oJmsConn = oQC;
        m_oJmsSess = oSess;
        m_oCmdSrc = oSess.createReceiver(oQ, sMsgSelector);
      }
      }
View Full Code Here

        String password = server.getAttribute("password");
        String clientId = server.getAttribute("client-id");

        InitialContext jndi = null;
        QueueConnectionFactory factory = null;
        QueueConnection con = null;

        try {
            jndi = JNDIContextFactory.getInitialContext(serverName);
            factory = (QueueConnectionFactory) jndi.lookup(jndiName);
        } catch (GeneralException ge) {
            throw new GenericServiceException("Problems getting JNDI InitialContext.", ge.getNested());
        } catch (NamingException ne) {
            JNDIContextFactory.clearInitialContext(serverName);
            try {
                jndi = JNDIContextFactory.getInitialContext(serverName);
                factory = (QueueConnectionFactory) jndi.lookup(jndiName);
            } catch (GeneralException ge2) {
                throw new GenericServiceException("Problems getting JNDI InitialContext.", ge2.getNested());
            } catch (NamingException ne2) {
                throw new GenericServiceException("JNDI lookup problem.", ne2);
            }
        }

        try {
            con = factory.createQueueConnection(userName, password);

            if (clientId != null && clientId.length() > 1)
                con.setClientID(clientId);
            con.start();

            QueueSession session = con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
            Queue queue = (Queue) jndi.lookup(queueName);
            QueueSender sender = session.createSender(queue);

            // create/send the message
            Message message = makeMessage(session, modelService, context);

            sender.send(message);
            if (Debug.verboseOn()) Debug.logVerbose("Sent JMS Message to " + queueName, module);

            // close the connections
            sender.close();
            session.close();
            con.close();
        } catch (NamingException ne) {
            throw new GenericServiceException("Problems with JNDI lookup.", ne);
        } catch (JMSException je) {
            throw new GenericServiceException("JMS Internal Error.", je);
        }
View Full Code Here

        }
    }

    private void sendTextMessage( String queueName, int i ) throws JMSException, NamingException {
        QueueConnectionFactory connectionFactory        = new ActiveMQConnectionFactory("vm://test");
        QueueConnection queueConnection                 = null;
        QueueSession session                            = null;
        QueueSender sender                              = null;
        Queue queue                                     = null;
        TextMessage message                                 = null;

        try {

            // Create the queue connection
            queueConnection = connectionFactory.createQueueConnection();

            session = queueConnection.createQueueSession( false, QueueSession.AUTO_ACKNOWLEDGE );
            queue = session.createQueue(TEST_QUEUE_NAME);
            sender = session.createSender( queue );
            sender.setDeliveryMode( DeliveryMode.PERSISTENT );

            message = session.createTextMessage( String.valueOf(i) );

            // send the message
            sender.send( message );

            if( session.getTransacted()) {
                session.commit();
            }
            if (i%1000 == 0) {
                logger.info( "Message successfully sent to : " + queue.getQueueName( ) + " messageid: " + message.getJMSMessageID( )
                        + " content:" + message.getText());
            }
        } finally {
            if( sender!=null ) {
                sender.close();
            }
            if( session!=null ) {
                session.close();
            }
            if( queueConnection!=null ) {
                queueConnection.close();
            }
        }
    }
View Full Code Here

            this.handler        = handler;
        }

        public void run( ) {

            QueueConnection queueConnection                 = null;
            QueueSession session                            = null;
            QueueReceiver receiver                          = null;
            Queue queue                                     = null;
            Message message                                 = null;
            try {
                try {

                    queueConnection = connectionFactory.createQueueConnection( );
                    // create a transacted session
                    session = queueConnection.createQueueSession( TRANSACTED_RECEIVE, QueueSession.AUTO_ACKNOWLEDGE );
                    queue = session.createQueue(TEST_QUEUE_NAME);
                    receiver = session.createReceiver( queue );

                    // start the connection
                    queueConnection.start( );

                    logger.info( "Receiver " + Thread.currentThread().getName() + " connected." );

                    // start receive loop
                    while( ! ( shouldStop.get() || Thread.currentThread().isInterrupted()) ) {
                        try {
                            message = receiver.receive( 200 );
                        } catch( Exception e) {
                            //
                            // ignore interrupted exceptions
                            //
                            if( e instanceof InterruptedException || e.getCause() instanceof InterruptedException ) {
                                /* ignore */
                            } else {
                                throw e;
                            }
                        }

                        if( message!=null && this.handler!=null ) {
                            this.handler.onMessage(message);
                        }

                        // commit session on successful handling of message
                        if( session.getTransacted()) {
                            session.commit();
                        }
                    }

                    logger.info( "Receiver " + Thread.currentThread().getName() + " shutting down." );

                } finally {
                    if( receiver!=null ) {
                        try {
                            receiver.close();
                        } catch (JMSException e)  {
                            logger.warn(e);
                        }
                    }
                    if( session!=null ) {
                        try {
                            session.close();
                        } catch (JMSException e)  {
                            logger.warn(e);
                        }
                    }
                    if( queueConnection!=null ) {
                        queueConnection.close();
                    }
                }
            } catch ( JMSException e ) {
                logger.error(e);
                e.printStackTrace();
View Full Code Here

    public void close() throws WSIFException {
        Trc.entry(this);
        try {
            QueueSender sndr = sender;
            QueueSession sssn = session;
            QueueConnection cnnctn = connection;

            sender = null; // Ensure these are nulled (flagging the close()),
            session = null; // even if a close() throws a JMSException
            connection = null;

            if (sndr != null)
                sndr.close();
            if (sssn != null)
                sssn.close();
            if (cnnctn != null)
                cnnctn.close();
        } catch (JMSException je) {
            Trc.exception(je);
            throw WSIFJMSConstants.ToWsifException(je);
        }
        Trc.exit();
View Full Code Here

        QueueConnectionFactory factory = (QueueConnectionFactory)jndiContext.lookup("titan-QueueFactory");
       
        Queue reservationQueue = (Queue)jndiContext.lookup("titan-ReservationQueue");
        Queue ticketQueue = (Queue)jndiContext.lookup("titan-TicketQueue");

        QueueConnection connect = factory.createQueueConnection();

        QueueSession session = connect.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);

        QueueSender sender = session.createSender(reservationQueue);
              
        for (int i = 0; i < count; i++) {

            MapMessage message = session.createMapMessage();
           
      message.setJMSReplyTo(ticketQueue)// Used in ReservationProcessor to send Tickets back out

      message.setStringProperty("MessageFormat", "Version 3.4");

            message.setInt("CruiseID", cruiseID.intValue());
            message.setInt("CustomerID",i%2+1)// either Customer 1 or 2, all we've got in database
            message.setInt("CabinID",i%10+100)// cabins 100-109 only
            message.setDouble("Price", (double)1000+i);
           
            // the card expires in about 30 days
            Date expDate = new Date(System.currentTimeMillis()+43200000);
           
            message.setString("CreditCardNum", "923830283029");
            message.setLong("CreditCardExpDate", expDate.getTime());
            message.setString("CreditCardType", CreditCardDO.MASTER_CARD);
           
      System.out.println("Sending reservation message #"+i);
            sender.send(message);          
        }
       
        connect.close();
    }
View Full Code Here

      jndiContext.lookup("titan-QueueFactory");
       
        Queue ticketQueue = (Queue)
      jndiContext.lookup("titan-TicketQueue");

        QueueConnection connect = factory.createQueueConnection();

        QueueSession session =
      connect.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
       
        QueueReceiver receiver = session.createReceiver(ticketQueue);

        receiver.setMessageListener(this);
       
    System.out.println("Listening for messages on titan-TicketQueue...");
        connect.start();
    }
View Full Code Here

                        "wsif.jms2httpbridge.jndiconnectionfactoryname"),
                null,
                null);

        QueueConnectionFactory factory = finder.getFactory();
        QueueConnection connection = factory.createQueueConnection();
        connection.start();
        QueueSession session =
            connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue readQ = session.createQueue(queueName);
        QueueReceiver receiver =
            session.createReceiver(readQ, "JMSCorrelationID='" + id + "'");
        return receiver.receive(WSIFProperties.getAsyncTimeout());
    }
View Full Code Here

TOP

Related Classes of javax.jms.QueueConnection

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.