Package javax.jms

Examples of javax.jms.QueueConnection


    }

    @Override
    protected void initializeForeignConnection() throws NamingException, JMSException {

        final QueueConnection newConnection;

        if (foreignConnection.get() == null) {
            // get the connection factories
            if (outboundQueueConnectionFactory == null) {
                // look it up from JNDI
                if (outboundQueueConnectionFactoryName != null) {
                    outboundQueueConnectionFactory = (QueueConnectionFactory)jndiOutboundTemplate
                        .lookup(outboundQueueConnectionFactoryName, QueueConnectionFactory.class);
                    if (outboundUsername != null) {
                        newConnection = outboundQueueConnectionFactory
                            .createQueueConnection(outboundUsername, outboundPassword);
                    } else {
                        newConnection = outboundQueueConnectionFactory.createQueueConnection();
                    }
                } else {
                    throw new JMSException("Cannot create foreignConnection - no information");
                }
            } else {
                if (outboundUsername != null) {
                    newConnection = outboundQueueConnectionFactory
                        .createQueueConnection(outboundUsername, outboundPassword);
                } else {
                    newConnection = outboundQueueConnectionFactory.createQueueConnection();
                }
            }
        } else {
            // Clear if for now in case something goes wrong during the init.
            newConnection = (QueueConnection) foreignConnection.getAndSet(null);
        }

        if (outboundClientId != null && outboundClientId.length() > 0) {
            newConnection.setClientID(getOutboundClientId());
        }
        newConnection.start();

        outboundMessageConvertor.setConnection(newConnection);

        // Configure the bridges with the new Outbound connection.
        initializeInboundDestinationBridgesOutboundSide(newConnection);
        initializeOutboundDestinationBridgesOutboundSide(newConnection);

        // Register for any async error notifications now so we can reset in the
        // case where there's not a lot of activity and a connection drops.
        newConnection.setExceptionListener(new ExceptionListener() {
            @Override
            public void onException(JMSException exception) {
                handleConnectionFailure(newConnection);
            }
        });
View Full Code Here


    }

    @Override
    protected void initializeLocalConnection() throws NamingException, JMSException {

        final QueueConnection newConnection;

        if (localConnection.get() == null) {
            // get the connection factories
            if (localQueueConnectionFactory == null) {
                if (embeddedConnectionFactory == null) {
                    // look it up from JNDI
                    if (localConnectionFactoryName != null) {
                        localQueueConnectionFactory = (QueueConnectionFactory)jndiLocalTemplate
                            .lookup(localConnectionFactoryName, QueueConnectionFactory.class);
                        if (localUsername != null) {
                            newConnection = localQueueConnectionFactory
                                .createQueueConnection(localUsername, localPassword);
                        } else {
                            newConnection = localQueueConnectionFactory.createQueueConnection();
                        }
                    } else {
                        throw new JMSException("Cannot create localConnection - no information");
                    }
                } else {
                    newConnection = embeddedConnectionFactory.createQueueConnection();
                }
            } else {
                if (localUsername != null) {
                    newConnection = localQueueConnectionFactory.
                            createQueueConnection(localUsername, localPassword);
                } else {
                    newConnection = localQueueConnectionFactory.createQueueConnection();
                }
            }

        } else {
            // Clear if for now in case something goes wrong during the init.
            newConnection = (QueueConnection) localConnection.getAndSet(null);
        }

        if (localClientId != null && localClientId.length() > 0) {
            newConnection.setClientID(getLocalClientId());
        }
        newConnection.start();

        inboundMessageConvertor.setConnection(newConnection);

        // Configure the bridges with the new Local connection.
        initializeInboundDestinationBridgesLocalSide(newConnection);
        initializeOutboundDestinationBridgesLocalSide(newConnection);

        // Register for any async error notifications now so we can reset in the
        // case where there's not a lot of activity and a connection drops.
        newConnection.setExceptionListener(new ExceptionListener() {
            @Override
            public void onException(JMSException exception) {
                handleConnectionFailure(newConnection);
            }
        });
View Full Code Here

    private void addAQDestinationContext(Context context) throws NamingException {

        // lookup and cache the queues
        QueueConnectionFactory queueFactory;
        QueueConnection queueConnection = null;
        TopicConnectionFactory topicFactory;
        TopicConnection topicConnection = null;
        AQjmsSession session = null;
        try {
            // create a datasource to use - datasources can keep the
            // username/password for later use
            DataSource ds = null;
            XADataSource xaDs = null;
            try {
                if (aqConnectionUrl != null)
                {
                    ds = AQUtil.getSQLDataSource(aqConnectionUrl, dbuser, dbpass);
                    xaDs = AQUtil.getXASQLDataSource(aqConnectionUrl, dbuser, dbpass);
                }
                else
                {
                    ds = AQUtil.getSQLDataSource( aqServerName, aqServerDBInst, aqServerPortNumber, aqDBDriver, dbuser, dbpass);
                    xaDs = AQUtil.getXASQLDataSource(aqServerName, aqServerDBInst, aqServerPortNumber, aqDBDriver, dbuser, dbpass);
                }
            } catch (SQLException e) {
                throw new RuntimeException(e.getMessage());
            }

            XAConnectionFactory factory = AQjmsFactory.getXAConnectionFactory(xaDs);
            context.rebind(XA_CONNECTION_FACTORY, factory);
            context.rebind("KURTSTAM", new String("hello"));

            // create the connection factory
            ConnectionFactory connectionFactory = AQjmsFactory.getConnectionFactory(ds);
            context.rebind(CONNECTION_FACTORY, connectionFactory);

            // create the queue connection factory
            queueFactory = AQjmsFactory.getQueueConnectionFactory(ds);
            context.rebind(QUEUE_CONNECTION_FACTORY, queueFactory);
            queueConnection = queueFactory.createQueueConnection();
            session = (AQjmsSession) queueConnection.createQueueSession(false,
                    Session.AUTO_ACKNOWLEDGE);

            // create the queue XA connection factory
            XAQueueConnectionFactory xaQueueConnectionFactory = AQjmsFactory.getXAQueueConnectionFactory(xaDs);
            context.rebind(XA_QUEUE_CONNECTION_FACTORY, xaQueueConnectionFactory);

//          create the topic XA connection factory
            XATopicConnectionFactory xaTopicConnectionFactory = AQjmsFactory.getXATopicConnectionFactory(xaDs);
            context.rebind(XA_TOPIC_CONNECTION_FACTORY, xaTopicConnectionFactory);

            // create the topic connection factory
            topicFactory = AQjmsFactory.getTopicConnectionFactory(ds);
            context.rebind(TOPIC_CONNECTION_FACTORY, topicFactory);
            topicConnection = topicFactory.createTopicConnection();
            session = (AQjmsSession) topicConnection.createTopicSession(false,
                    Session.AUTO_ACKNOWLEDGE);
            List<DestinationInfo> list = AQUtil.getDestinationInfoList(ds, aqSchemaName);
            // for each queue
            Iterator<DestinationInfo> iter = list.iterator();
            while (iter.hasNext()) {
                DestinationInfo di = iter.next();
                if(log.isDebugEnabled()) log.debug("Loading Destination: " + di);
                // register normal queue
                registerDestination(context, session, di);
            }
        } catch (JMSException e) {
            log.error("JMSException exception", e);
            throw new RuntimeException("JMSException exception", e);
        } finally {
            try {
                if (session != null)
                    session.close();
                if (queueConnection != null)
                    queueConnection.close();
                if (topicConnection != null)
                    topicConnection.close();
            } catch (JMSException e) {
                log.error("JMSEx while cleaning up", e);
            }
View Full Code Here

  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());
     send.send(tm);       
     send.close();
    
     conn.stop();
     session.close();
     conn.close();
    
     return message;
  }
View Full Code Here

      
    public static void sendMessage(Message esbMessage,String newDestination) throws Exception {
      if (esbMessage == null || newDestination == null)
        throw new Exception("Message and JMS Destination are required");
   
      QueueConnection conn;
        QueueSession session;
        Queue que;
       
      InitialContext iniCtx = new InitialContext();
      Object tmp = iniCtx.lookup("ConnectionFactory");
      QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
      conn = qcf.createQueueConnection();
      que = (Queue) iniCtx.lookup("queue/" + newDestination);
      session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
      conn.start();

      String newMsg = (String) esbMessage.getBody().get();
     
      QueueSender send = session.createSender(que);       
        TextMessage tm = session.createTextMessage(newMsg);
        send.send(tm);
       

      conn.stop();
    }   
View Full Code Here

       
        // If the queue is "OK" - send the incoming message to that queue
        if (theValue.equals("OK")) {
         
          // Set up the connection
          QueueConnection conn1 = null;
          Queue que;
          QueueSession session;
          InitialContext iniCtx = new InitialContext();
          Object tmp = iniCtx.lookup("ConnectionFactory");
          QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
          conn1 = qcf.createQueueConnection();
          que = (Queue) iniCtx.lookup(theKey);
          session = conn1.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
          conn1.start();

                    // Send the message                           
          QueueSender send = session.createSender(que);
          tm = session.createTextMessage(message.getBody().get().toString());
          send.send(tm);
                   
          // Close the connection
          send.close();
          conn1.stop();
          session.close();
          conn1.close();
        }
      }
    }
    catch (Throwable t) {
      t.printStackTrace();
View Full Code Here

      
    public static void sendMessage(Message esbMessage,String newDestination) throws JMSException, NamingException, Exception {
      if (esbMessage == null || newDestination == null)
        throw new Exception("Message and JMS Destination are required");
   
      QueueConnection conn;
        QueueSession session;
        Queue que;
       
      InitialContext iniCtx = new InitialContext();
      Object tmp = iniCtx.lookup("ConnectionFactory");
      QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
      conn = qcf.createQueueConnection();
      que = (Queue) iniCtx.lookup("queue/" + newDestination);
      session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
      conn.start();

              
      String newMsg = (String) esbMessage.getBody().get();

     
      QueueSender send = session.createSender(que);       
        TextMessage tm = session.createTextMessage(newMsg);
        send.send(tm);
       

      conn.stop();
    }   
View Full Code Here

      
    public static void sendMessage(Message esbMessage,String newDestination, final ConfigTree config) throws JMSException, NamingException, Exception {
      if (esbMessage == null || newDestination == null)
        throw new Exception("Message and JMS Destination are required");
   
      QueueConnection conn;
        QueueSession session;
        Queue que;
       
        final Hashtable<String, String>env = new Hashtable<String, String>();
        final String providerURL = config.getAttribute(JMSEpr.JNDI_URL_TAG) ;
        if (providerURL != null)
        {
            env.put(Context.PROVIDER_URL, providerURL) ;
        }
        final String initialContextFactory = config.getAttribute(JMSEpr.JNDI_CONTEXT_FACTORY_TAG) ;
        if (initialContextFactory != null)
        {
            env.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory) ;
        }
       
        final String urlPkgPrefixes = config.getAttribute(JMSEpr.JNDI_PKG_PREFIX_TAG) ;
        if (urlPkgPrefixes != null)
        {
            env.put(Context.URL_PKG_PREFIXES, urlPkgPrefixes) ;
        }
       
      InitialContext iniCtx = new InitialContext(env);
      Object tmp = iniCtx.lookup("ConnectionFactory");
      QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
      conn = qcf.createQueueConnection();
      que = (Queue) iniCtx.lookup("queue/" + newDestination);
      session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
      conn.start();

              
      String newMsg = (String) esbMessage.getBody().get();

     
      QueueSender send = session.createSender(que);       
        TextMessage tm = session.createTextMessage(newMsg);
        send.send(tm);
       
        session.close();
      conn.stop();
      conn.close();
    }   
View Full Code Here

      
    public static void sendMessage(Message esbMessage,String newDestination) throws JMSException, NamingException, Exception {
      if (esbMessage == null || newDestination == null)
        throw new Exception("Message and JMS Destination are required");
   
      QueueConnection conn;
        QueueSession session;
        Queue que;
       
      InitialContext iniCtx = new InitialContext();
      Object tmp = iniCtx.lookup("ConnectionFactory");
      QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
      conn = qcf.createQueueConnection();
      que = (Queue) iniCtx.lookup("queue/" + newDestination);
      session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
      conn.start();

              
      String newMsg = (String) esbMessage.getBody().get();

     
      QueueSender send = session.createSender(que);       
        TextMessage tm = session.createTextMessage(newMsg);
        send.send(tm);
       

        session.close();
      conn.stop();
      conn.close();
    }   
View Full Code Here

  private Logger logger = Logger.getLogger(SimpleJMSNotifier.class);
  String queueName = "quickstart_bpm_orchestration4_monitor";
  String prependedText = "";
  String bodyKey ="";
  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);
     String msg = "";
    
     if (bodyKey == null || bodyKey.equals("")) {
         msg = prependedText + "\n" + message.getBody().get();
     } else {
         msg = prependedText+ "\n" + message.getBody().get(bodyKey);
     }
    
     TextMessage tm = session.createTextMessage(msg);
     send.send(tm);       
     send.close();
    
     conn.stop();
     session.close();
     conn.close();
    
     return message;
  }
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.