Пример #1
0
 void subscribeToSource(SubscriptionManager manager)
 {
     sourceSettings.autoAck = 0;//will accept once at the end of the batch
     sourceSettings.flowControl = FlowControl::messageCredit(expected);
     sourceSubscription = manager.subscribe(*this, source, sourceSettings);
     QPID_LOG(info, "Subscribed to source: " << source << " expecting: " << expected);
 }
Пример #2
0
/*
FUNCTION : prepareQueue
DESC: not used!
*/
void Listener::prepareQueue(std::string queue, std::string exchange, std::string routing_key) {

  std::cout << "Subscribing to queue " << queue << std::endl;
  //subscriptions.subscribe(*this, queue);
  // Will not acquire messages but instead browse them.
  //  subscriptions.setAcquireMode(message::ACQUIRE_MODE_NOT_ACQUIRED);
  subscriptions.subscribe(local_queue, string("condor_queue"));
}
Пример #3
0
void Listener::dequeue() {
  subscriptions.subscribe(local_queue, string("condor_queue"));   
  Message lMsg;
  int size = 10;
  size = local_queue.size();

  local_queue.get(lMsg,10000);
  newMessage = lMsg.getData();
}
Пример #4
0
 /** Process messages from queue by applying a functor. */
 void process(size_t n, string queue,
              boost::function<void (const string&)> msgFn)
 {
     if (!opts.summary)
         cout << "Processing " << n << " messages from "
              << queue << " " << flush;
     LocalQueue lq;
     subs.setFlowControl(n, SubscriptionManager::UNLIMITED, false);
     subs.subscribe(lq, queue);
     for (size_t i = 0; i < n; ++i) {
         if (!opts.summary) cout << "." << flush;
         msgFn(lq.pop().getData());
     }
     if (!opts.summary) cout << " done." << endl;
 }
Пример #5
0
bool Listener::initListen() {
  // Receive messages
  //Added to test for init on recovery ***********************
  subscriptions.subscribe(local_queue, string("condor_queue"),SubscriptionSettings(FlowControl::unlimited(), ACCEPT_MODE_NONE, ACQUIRE_MODE_NOT_ACQUIRED));   
  Message lMsg;
  // sleep so that the local queue can get the message from the main condor
  // queue
  sleep(2);
  int size = 10;
  size = local_queue.size();
  local_queue.get(lMsg,10000);
  newMessage = lMsg.getData();
  subscriptions.stop();
  subscriptions.cancel(lMsg.getDestination());
  cout << "\n initListen(): size of the queue is : " << size <<endl;
  if(size > 0){
    //message queue has unprocessed message
    return false;
  }
  else{
    // message queue is empty:read from the file and send to the main condor_queue
    return true;
  }
}
Пример #6
0
    void run() {                // Controller
        try {
            // Wait for subscribers to be ready.
            process(opts.totalSubs, fqn("sub_ready"), boost::bind(expect, _1, "ready"));

            LocalQueue pubDone;
            LocalQueue subDone;
            subs.setFlowControl(0, SubscriptionManager::UNLIMITED, false);
            subs.subscribe(pubDone, fqn("pub_done"));
            subs.subscribe(subDone, fqn("sub_done"));

            double txrateTotal(0);
            double mbytesTotal(0);
            double pubRateTotal(0);
            double subRateTotal(0);

            for (size_t j = 0; j < opts.iterations; ++j) {
                AbsTime start=now();
                send(opts.totalPubs, fqn("pub_start"), "start"); // Start publishers
                if (j) {
                    send(opts.totalSubs, fqn("sub_iteration"), "next"); // Start subscribers on next iteration
                }

                Stats pubRates;
                Stats subRates;

                process(opts.totalPubs, pubDone, fqn("pub_done"), boost::ref(pubRates));
                process(opts.totalSubs, subDone, fqn("sub_done"), boost::ref(subRates));

                AbsTime end=now();
                double time=secs(start, end);
		if (time <= 0.0) {
		  throw Exception("ERROR: Test completed in zero seconds. Try again with a larger message count.");
		}
                double txrate=opts.transfers/time;
                double mbytes=(txrate*opts.size)/(1024*1024);

                if (!opts.summary) {
                    cout << endl << "Total " << opts.transfers << " transfers of "
                         << opts.size << " bytes in "
                         << time << " seconds." << endl;
                    cout << endl << "Publish transfers/sec:    " << endl;
                    pubRates.print(cout);
                    cout << endl << "Subscribe transfers/sec:  " << endl;
                    subRates.print(cout);
                    cout << endl
                         << "Total transfers/sec:      " << txrate << endl
                         << "Total Mbytes/sec: " << mbytes << endl;
                }
                else {
                    cout << pubRates.mean() << "\t"
                         << subRates.mean() << "\t"
                         << txrate << "\t"
                         << mbytes << endl;
                }

                txrateTotal += txrate;
                mbytesTotal += mbytes;
                pubRateTotal += pubRates.mean();
                subRateTotal += subRates.mean();
            }
            if (opts.iterations > 1) {
                cout << "Averages: "<< endl
                     << (pubRateTotal / opts.iterations) << "\t"
                     << (subRateTotal / opts.iterations) << "\t"
                     << (txrateTotal / opts.iterations) << "\t"
                     << (mbytesTotal / opts.iterations) << endl;
            }
        }
        catch (const std::exception& e) {
            cout << "Controller exception: " << e.what() << endl;
        }
    }
Пример #7
0
 void subscribeToControl(SubscriptionManager manager)
 {
     controlSettings.flowControl = FlowControl::messageCredit(1);
     controlSubscription = manager.subscribe(*this, control, controlSettings);
     QPID_LOG(info, "Subscribed to job queue");
 }
Пример #8
0
/*
 *  argv[1] host
 *  argv[2] port
 *  argv[3] server name
 *  argv[4] command name
 *  argv[5..N] args to the command
 */
int
main ( int argc, char ** argv )
{
    const char* host = argv[1];
    int port = atoi(argv[2]);


    Connection connection;

    try
    {
        connection.open ( host, port );
        Session session = connection.newSession ( );

        // Make a queue and bind it to fanout.
        string myQueue = session.getId().getName();

        session.queueDeclare ( arg::queue=myQueue,
                               arg::exclusive=true,
                               arg::autoDelete=true
                             );

        session.exchangeBind ( arg::exchange="amq.fanout",
                               arg::queue=myQueue,
                               arg::bindingKey="my-key"
                             );

        // Get ready to listen for the wait-response.
        // or maybe a get-response.
        // ( Although this may not be one of those types
        // of command, get ready anyway.
        SubscriptionManager subscriptions ( session );
        ResponseListener responseListener ( subscriptions );
        subscriptions.subscribe ( responseListener, myQueue );

        bool response_command = false;
        if(! strcmp("exec_wait", argv[4] ))
            response_command = true;
        else
        if(! strcmp("exited", argv[4] ))
            response_command = true;
        else
        if(! strcmp("get", argv[4] ))
            response_command = true;

        // Send the payload message.
        // Skip "qrsh host_name port"
        Message message;
        stringstream ss;
        for ( int i = 3; i < argc; ++ i )
            ss << argv[i] << ' ';

        message.setData ( ss.str() );

        session.messageTransfer(arg::content=message,
                                arg::destination="amq.fanout");

        if ( response_command )
            subscriptions.run();

        session.close();
        connection.close();
        return responseListener.exitCode;
    }
    catch ( exception const & e)
    {
        cerr << e.what() << endl;
    }

    return 1;
}
Пример #9
0
void Listener::browse() 
{ 
  subscriptions.subscribe(*this, "condor_queue", SubscriptionSettings(FlowControl::unlimited(), ACCEPT_MODE_NONE, ACQUIRE_MODE_NOT_ACQUIRED));     
  subscriptions.run(); 
}