Package javax.jms

Examples of javax.jms.TopicConnection


                    return connections.get(JMSType.TOPIC);
                }
                else
                {
                    TopicConnectionFactory ccf = (TopicConnectionFactory) createOrReturnConnectionFactory();
                    TopicConnection qc = ccf.createTopicConnection();
                    connections.put(JMSType.TOPIC, qc);

                    return qc;
                }
View Full Code Here


    }

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

        final TopicConnection newConnection;

        if (foreignConnection.get() == null) {
            // get the connection factories
            if (outboundTopicConnectionFactory == null) {
                // look it up from JNDI
                if (outboundTopicConnectionFactoryName != null) {
                    outboundTopicConnectionFactory = (TopicConnectionFactory)jndiOutboundTemplate
                        .lookup(outboundTopicConnectionFactoryName, TopicConnectionFactory.class);
                    if (outboundUsername != null) {
                        newConnection = outboundTopicConnectionFactory
                            .createTopicConnection(outboundUsername, outboundPassword);
                    } else {
                        newConnection = outboundTopicConnectionFactory.createTopicConnection();
                    }
                } else {
                    throw new JMSException("Cannot create foreignConnection - no information");
                }
            } else {
                if (outboundUsername != null) {
                    newConnection = outboundTopicConnectionFactory
                        .createTopicConnection(outboundUsername, outboundPassword);
                } else {
                    newConnection = outboundTopicConnectionFactory.createTopicConnection();
                }
            }
        } else {
            // Clear if for now in case something goes wrong during the init.
            newConnection = (TopicConnection) 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 TopicConnection newConnection;

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

        } else {
            // Clear if for now in case something goes wrong during the init.
            newConnection = (TopicConnection) 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

        // 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

      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 {
  TopicConnection oTconn = null;
  TopicSession   oTsess = null;
  TopicConnectionFactory qcf = (TopicConnectionFactory) oCtx
    .lookup("ConnectionFactory");

  oTconn = qcf.createTopicConnection();
  oTsess = oTconn.createTopicSession(false
      ,QueueSession.AUTO_ACKNOWLEDGE);
    Topic oT = (Topic) oCtx.lookup(p_sJndi);
    TopicSubscriber oRcv = oTsess.createSubscriber(oT);
    oTconn.start();
    return oRcv;
      } finally {
          NamingContextPool.releaseNamingContext(oCtx) ;
      }
  } //__________________________________
View Full Code Here

      boolean bIsTopic = Boolean.parseBoolean(obtainAtt(p_oP,
          COMMAND_IS_TOPIC, "false"));
      if (bIsTopic)
      {
        TopicConnectionFactory tcf = (TopicConnectionFactory) oFactCls;
        TopicConnection oTC = tcf.createTopicConnection();
        TopicSession oSess = oTC.createTopicSession(false,
            TopicSession.AUTO_ACKNOWLEDGE);
        Topic oTopic = null;
        try
        {
          oTopic = (Topic) oJndiCtx.lookup(sJndiName);
        }
        catch (NamingException ne)
        {
          oTopic = oSess.createTopic(sJndiName);
        }
        m_oJmsConn = oTC;
        m_oJmsSess = oSess;
        oTC.start();
        m_oCmdSrc = oSess.createSubscriber(oTopic, sMsgSelector, true);
      }
      else
      {
        QueueConnectionFactory qcf = (QueueConnectionFactory) oFactCls;
View Full Code Here

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

        InitialContext jndi = null;
        TopicConnectionFactory factory = null;
        TopicConnection con = null;

        try {
            jndi = JNDIContextFactory.getInitialContext(serverName);
            factory = (TopicConnectionFactory) 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 = (TopicConnectionFactory) jndi.lookup(jndiName);
            } catch (GeneralException ge2) {
                throw new GenericServiceException("Problems getting JNDI InitialContext.", ge2.getNested());
            } catch (NamingException ne2) {
                throw new GenericServiceException("JNDI lookup problems.", ne);
            }
        }

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

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

            TopicSession session = con.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
            Topic topic = (Topic) jndi.lookup(topicName);
            TopicPublisher publisher = session.createPublisher(topic);

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

            publisher.publish(message);
            if (Debug.verboseOn()) Debug.logVerbose("Sent JMS Message to " + topicName, module);

            // close the connections
            publisher.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

        conn1.close();
        conn2.close();
    }

    private void produceMessages() throws Exception {
        TopicConnection connection = createConnection();
        TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        Topic topic = session.createTopic(TOPICNAME);
        TopicPublisher producer = session.createPublisher(topic);
        connection.start();
        producer.setDeliveryMode(DeliveryMode.PERSISTENT);
        long tStamp = System.currentTimeMillis();
        BytesMessage message = session2.createBytesMessage();
        for (int i = 1; i <= MSG_COUNT; i++)
        {
View Full Code Here

    private TopicConnection createConnection() throws Exception
    {
        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
        connectionFactory.setBrokerURL(connectionUri);
        TopicConnection conn = connectionFactory.createTopicConnection();
        return conn;
    }
View Full Code Here

    private class MessagePublisher implements Runnable{
        private final boolean shouldPublish = true;
       
        public void run(){
            TopicConnectionFactory topicConnectionFactory = null;
            TopicConnection topicConnection = null;
            TopicSession topicSession = null;
            Topic topic = null;
            TopicPublisher topicPublisher = null;
            Message message = null;
           
            topicConnectionFactory = new ActiveMQConnectionFactory(CONNECTION_URL);
            try {
                topic = new ActiveMQTopic(TOPIC_NAME);
                topicConnection = topicConnectionFactory.createTopicConnection();
                topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
                topicPublisher = topicSession.createPublisher(topic);
                message = topicSession.createMessage();
            } catch (Exception ex) {
                exceptions.add(ex);
            }
View Full Code Here

TOP

Related Classes of javax.jms.TopicConnection

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.