ActiveMQConnection::start() doesn't work when host is wrong

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

ActiveMQConnection::start() doesn't work when host is wrong

rafal_rr
This post has NOT been accepted by the mailing list yet.
hello.
there is a part of my code:
[code]bool SimpleAsyncConsumer::runConsumer()
{
    try
    {
        connectionFactory = new ActiveMQConnectionFactory(brokerURI);
        connectionFactory->setSendTimeout(3000) ;
        std::cout << "connection factory created\n";
               
        try
        {
            connection = connectionFactory->createConnection();
        }
        catch (CMSException &e)
        {
            cout << "wyjatek w connection = connectionFactory->createConnection();\n" ;
            cout << e.getMessage()<<endl ;
            return 0 ;
        }
        std::cout << "connection to [" << brokerURI << "] created\n";
        ActiveMQConnection* amqConnection = dynamic_cast<ActiveMQConnection*>(connection);
                cout<<"nu\n" ;
        if (amqConnection != NULL)
        {
            amqConnection->addTransportListener(this);
        }
                cout<<"nu\n" ;
        connection->start();
        std::cout << "connection started\n";
        connection->setExceptionListener(this);
        std::cout << "exception listener set\n";
        session = connection->createSession(Session::AUTO_ACKNOWLEDGE);
        std::cout << "session created\n";
        destination = session->createTopic(destURI);
        std::cout << "topic [" << destURI << "] created\n";
        std::string selector("JMSType = 'req'");
        consumer = session->createConsumer(destination, selector);
        std::cout << "consumer for selector [" << selector << "] created\n";
        consumer->setMessageListener(this);
        std::cout << "message listener set\n";
    }
    catch (CMSException& e)
    {
        cout<<"wyjatek! w create connection\n" ;
        cout << e.getMessage()<<endl ;
        //e.printStackTrace();
        return 0 ;
    }
    return 1 ;
}[/code]

my code stops is connection->start() ;



[code]void ActiveMQConnection::start() throw ( cms::CMSException ) {
    try{

        checkClosed();
        ensureConnectionInfoSent();

        // This starts or restarts the delivery of all incoming messages
        // messages delivered while this connection is stopped are dropped
        // and not acknowledged.
        if( this->started.compareAndSet( false, true ) ) {

            // Start all the sessions.
            std::vector<ActiveMQSession*> sessions = activeSessions.toArray();
            for( unsigned int ix=0; ix<sessions.size(); ++ix ) {
                sessions[ix]->start();
            }
        }
    }
    AMQ_CATCH_ALL_THROW_CMSEXCEPTION()
}
[/code]

ensureConnectionInfoSent(); cause a problem.


application works right when host is right.

how can i protect my application against wrong host ? timeouts?