Skip to content

Bid request pipeline

Sirma Cagil Altay edited this page May 9, 2016 · 7 revisions

Overview

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:

How to implement a custom bid request pipeline

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 and postBidRequest functions
  • provide an AtInit structure, so it can be loaded dynamically

Example: custom_pipeline.h

#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

Example: custom_pipeline.cc

#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)

Example: request_pipeline.mk

$(eval $(call library,my_custom_pipeline,custom_pipeline.cc,rtb))

How to configure the custom bid request pipeline

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)

Example: my_exchange_configuration.json

{
   \* A first exchange *\
   ...
}
{
   "exchangeType": "myExchange",
   "pipeline": 
   {
       "type": "my_custom"
   }
}

How to load the custom pipeline

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

Clone this wiki locally