Esempio n. 1
0
/*
 * Removes interest on the subject. Asynchronous subscription may still have
 * a callback in progress, in that case, the subscription will still be valid
 * until the callback returns.
 */
natsStatus
natsSubscription_Unsubscribe(natsSubscription *sub)
{
    natsStatus s = _unsubscribe(sub, 0);
    return NATS_UPDATE_ERR_STACK(s);
}
Esempio n. 2
0
/*
 * This call issues an automatic natsSubscription_Unsubscribe that is
 * processed by the server when 'max' messages have been received.
 * This can be useful when sending a request to an unknown number
 * of subscribers.
 */
natsStatus
natsSubscription_AutoUnsubscribe(natsSubscription *sub, int max)
{
    natsStatus s = _unsubscribe(sub, max);
    return NATS_UPDATE_ERR_STACK(s);
}
int main (int argc, char ** argv)
{
    try
    {
        CIMClient client;

        //
        //  Connect to CIM Server
        //
        try
        {
            client.connectLocal ();
        }

        catch(Exception& e)
        {
            cerr << "Exception thown by client.connectLocal(): " 
                << e.getMessage() << endl;
            return -1;
        }


        if (argc > 2)
        {
            _usage ();
            return 1;
        }

        else if (argc == 1)
        {
            try
            {
                _subscribe (client);
            }
            catch(Exception& e)
            {
                cerr << "Exception thrown by _subscribe method: " 
                    << e.getMessage() << endl;
                return -1;
            }

            Sint32 result = _sendTestIndications (client);

            if (result == 0)
            {
                cout << "Successfully sent test indications" << endl;
            }
            else
            {
                cerr << "Failed to send test indications" << endl;
            }

            try
            {
                _unsubscribe (client);
            }
            catch(Exception& e)
            {
                cerr << "Exception thrown by _unsubscribe method: " 
                    << e.getMessage() << endl;
                return -1;
            }
        }

        else
        {
            const char * opt = argv [1];

            if (String::equalNoCase (opt, "subscribe"))
            {
                try
                {
                    _subscribe (client);
                }
                catch(Exception& e)
                {
                    cerr << "Exception thrown by _subscribe method: "
                         << e.getMessage() << endl;
                    return -1;
                }
            }
            else if (String::equalNoCase (opt, "sendTestIndications"))
            {
                Sint32 result = _sendTestIndications (client);

                if (result == 0)
                {
                    cout << "Successfully sent test indications" << endl;
                }
                else
                {
                    cerr << "Failed to send test indications" << endl;
                }
            }
            else if (String::equalNoCase (opt, "unsubscribe"))
            {
                try
                {
                    _unsubscribe (client);
                }
                catch(Exception& e)
                {
                    cerr << "Exception thrown by _unsubscribe method: "
                         << e.getMessage() << endl;
                    return -1;
                }
            }
            else
            {
                cerr << "Invalid option: " << opt << endl;
                _usage ();
                return -1;
            }
        }
    }
    catch (Exception & e)
    {
        cerr << "SendTestIndications failed: " << e.getMessage () << endl;
        return -1;
    }

    return 0;
}