-
Notifications
You must be signed in to change notification settings - Fork 406
Bid request pipeline
Bid request pipeline plug-in is used for implementing custom actions prior and after parsing the bid request in http exchange connector. And that without changing the main code of http exchange connector nor the one of http auction handler. The main class used to implement a request pipeline is BidRequestPipeline. When the user does no provide any bid request pipeline plug-in, a null bid request pipeline is used. This pipeline does not add anything extra to the code. The two main functions of a bid request pipeline are:
- [preBidRequest] (https://github.com/rtbkit/rtbkit/blob/master/rtbkit/common/bid_request_pipeline.h#L45) called [before parsing] (https://github.com/rtbkit/rtbkit/blob/master/rtbkit/plugins/exchange/http_auction_handler.cc#L391)
- [postBidRequest] (https://github.com/rtbkit/rtbkit/blob/master/rtbkit/common/bid_request_pipeline.h#L51) called [after parsing] (https://github.com/rtbkit/rtbkit/blob/master/rtbkit/plugins/exchange/http_auction_handler.cc#L415)
You can create a new bid request pipeline under the folder rtbkit/plugins/request_pipeline
. The custom pipeline should:
- derive from the class
BidRequestPipeline
- define a constructor with the same parameters as the one of
BidRequestPipeline
- overload
preBidRequest
andpostBidRequest
functions - provide an
AtInit
structure, so it can be loaded dynamically
#pragma once
#include "rtbkit/common/bid_request_pipeline.h"
namespace CUSTOM {
class CustomPipeline : public RTBKIT::BidRequestPipeline {
public:
CustomPipeline(
std::shared_ptr<Datacratic::ServiceProxies> proxies,
std::string serviceName,
const Json::Value& json);
RTBKIT::PipelineStatus
preBidRequest(
const RTBKIT::ExchangeConnector* exchange,
const Datacratic::HttpHeader& header,
const std::string& payload);
RTBKIT::PipelineStatus
postBidRequest(
const RTBKIT::ExchangeConnector* exchange,
const std::shared_ptr<RTBKIT::Auction>& auction);
};
} // namespace CUSTOM
#include "custom_pipeline.h"
using namespace Datacratic;
using namespace RTBKIT;
namespace CUSTOM {
CustomPipeline::CustomPipeline(
std::shared_ptr<ServiceProxies> proxies, std::string serviceName,
const Json::Value& json)
: BidRequestPipeline(std::move(proxies), std::move(serviceName))
{ }
PipelineStatus
CustomPipeline::preBidRequest(
const ExchangeConnector* exchange,
const HttpHeader& header,
const std::string& payload)
{
/* custom code */
return PipelineStatus::Continue;
}
PipelineStatus
CustomPipeline::postBidRequest(
const ExchangeConnector* exchange,
const std::shared_ptr<Auction>& auction)
{
/* custom code */
return PipelineStatus::Continue;
}
} // namespace CUSTOM
namespace {
struct AtInit {
AtInit()
{
PluginInterface<BidRequestPipeline>::registerPlugin("my_custom",
[](std::string serviceName,
std::shared_ptr<ServiceProxies> proxies,
Json::Value const &json)
{
return new CUSTOM::CustomPipeline(std::move(proxies),
std::move(serviceName),
json);
});
}
} atInit;
}
Once the plugin is ready, you can add it to [local .mk file] (https://github.com/rtbkit/rtbkit/blob/master/rtbkit/plugins/request_pipeline/request_pipeline.mk)
$(eval $(call library,my_custom_pipeline,custom_pipeline.cc,rtb))
The json configuration file used to configure different exchanges is given to router_runner process as a command line option --exchange-configuration,x
. This file may contain many exchange configurations (as Json objects). We need to add a "pipeline"
field under the exchange to which we want to apply the bid request pipeline. In its turn this "pipeline"
field should contain the "type"
of the pipeline. Note that the type
field should match the library name under which custom_pipeline.cc is compiled (ie: in this example the library name is libmy_custom_pipeline.so). If your exchange connector derives from an HttpExchangeConnector, the json value contained under "pipeline" field will be passed to [HttpExchangeConnector::configurePipeline] (https://github.com/rtbkit/rtbkit/blob/master/rtbkit/plugins/exchange/http_exchange_connector.cc#L120-L131)
{
\* A first exchange *\
...
}
{
"exchangeType": "myExchange",
"pipeline":
{
"type": "my_custom"
}
}
Once the plug-in library libmy_custom_pipeline.so is compiled under build/x86_64/bin
directory, the plug-in will be automatically loaded during run-time
- Getting Started
- Pull Request Guidelines
- Coding Standards
- Demo Stack
- How to compile static filters test
- RTBkit Binary Package
- Architecture
- Bid Request Lifecycle
- ZooKeeper Nodes
- Load Shedding
- Banker
- Post Auction Loop State Machine
- Post-Auction Loop Sharding
- ZMQ Endpoints