How to configure an Exchange Connector - datacratic/rtbkit GitHub Wiki
The router can be configured by passing in a JSON payload per exchange that contains the configuration parameters for that exchange.
The JSON file is read in by the RouterRunner struct when its init()
method is called, from a file named in its exchangeConfigurationFile
field. The JSON is stored in its exchangeConfig
field.
When the RouterRunner calls start()
it in turn calls the startExchange()
method for each exchange being supported, passing the config as an argument.
void
RouterRunner::
start()
{
banker->start();
router->start();
// Start all exchanges
for (auto & exchange: exchangeConfig)
ExchangeConnector::startExchange(router, exchange);
}
The connector then internally calls configure()
and loads the JSON config.
void
ExchangeConnector::
startExchange(std::shared_ptr<Router> router,
const std::string & exchangeType,
const Json::Value & exchangeConfig)
{
auto exchange = ExchangeConnector::
create(exchangeType, router, exchangeType);
exchange->configure(exchangeConfig);
exchange->start();
router->addExchange(std::move(exchange));
}
All Exchange Connectors will derive from the abstract base class ExchangeConnector
. The configure()
method is abstract in this class:
/** Configure the exchange connector. The JSON provided is entirely
interpreted by the exchange connector itself.
*/
virtual void configure(const Json::Value & parameters) = 0;
Derived classes must therefore implement configure(). For example, RTBKit ships with an HttpExchangeConnector
, and it's configure()
looks like this.
configure(const Json::Value & parameters)
{
getParam(parameters, numThreads, "numThreads");
getParam(parameters, listenPort, "listenPort");
getParam(parameters, bindHost, "bindHost");
getParam(parameters, performNameLookup, "performNameLookup");
getParam(parameters, backlog, "connectionBacklog");
getParam(parameters, auctionResource, "auctionResource");
getParam(parameters, auctionVerb, "auctionVerb");
getParam(parameters, pingTimesByHostMs, "pingTimesByHostMs");
getParam(parameters, pingTimeUnknownHostsMs, "pingTimeUnknownHostsMs");
}
This code also shows you the parameters, and their JSON key names, which the HTTPExchangeConnector
supports.