Skip to content

Client API

Mark Papadakis edited this page Jun 30, 2016 · 25 revisions

There is currently a low level client available. There will be high-level level clients available in the future. This page describes the low level client API.

To use the tank client

#include <tank.h>

and link against libtank

$> clang++ -std=c++14 app.cpp -ltank

Issuing Requests

  • produce() Use the produce() method to send messages to Tank. it accepts a single argument; a std::vector<> of std::pair<topic_partition, std::vector<TankClient::msg>> topic_partition defined as
using topic_partition = std::pair<strwlen8_t, uint16_t>;

and the first element of it is the topic name and the second the partition index

whereas msg is defined as

struct msg
{
        strwlen32_t content;
        uint64_t ts;
        strwlen8_t key;
};

this should be self explanatory. content is the content of the message, ts the creation timestamp in milliseconds, and key(optional) the key for the message.

This method returns an ID that identifies the request, or 0 for error. See later for request ID semantics.

Example call:

const auto reqId = client.produce(
        {       
                {{"notifications", 0},
                        {       
                                {"new order", Timings::Milliseconds::SysTime()},
                                {"out of stock product", Timings::Milliseconds::SysTime()},
                                {"150", Timings::Milliseconds::SysTime(), "orders_today"}
                        }       
                }       
        });   

In this example, we publish to topic "notifications", partition 0, 3 messages. Notice that the third has a key("orders_today") whereas the other do not. When you use produce(), all messages for each topic/partition you specify are placed together in a bundle. See later for bundle semantics.

  • consume() Use the consume() method to consume messages from Tank. (WIP)

Getting results

Clone this wiki locally