예제 #1
0
int main(int argc, char** argv)
{
  Connection::Configuration configuration;
  configuration.auto_connect = true;
  configuration.client_id = "libkafka_asio_example";
  configuration.socket_timeout = 2000;
  configuration.SetBrokerFromString("192.168.59.104:49156");

  boost::asio::io_service ios;
  Connection connection(ios, configuration);

  // Request the latest offset for partition 1 of topic 'mytopic' on the
  // configured broker.
  using libkafka_asio::constants::kOffsetTimeLatest;
  OffsetRequest request;
  request.FetchTopicOffset("mytopic", 1, kOffsetTimeLatest);

  connection.AsyncRequest(
    request,
    [&](const Connection::ErrorCodeType& err,
        const OffsetResponse::OptionalType& response)
    {
      if (err || !response)
      {
        std::cerr
          << "Error: " << boost::system::system_error(err).what()
          << std::endl;
        return;
      }
      auto offset = response->TopicPartitionOffset("mytopic", 1);
      if (!offset || offset->offsets.empty())
      {
        std::cerr << "Failed to fetch offset!" << std::endl;
        return;
      }
      std::cout
        << "Received latest offset: " << offset->offsets[0]
        << std::endl;
    });

  ios.run();
  return 0;
}
예제 #2
0
int main(int argc, char** argv)
{
  Connection::Configuration configuration;
  configuration.auto_connect = true;
  configuration.client_id = "libkafka_asio_example";
  configuration.socket_timeout = 2000;
  configuration.SetBrokerFromString("192.168.59.104:49156");

  boost::asio::io_service ios;
  Connection connection(ios, configuration);

  // Request the latest offset for partition 1 of topic 'mytopic' on the
  // configured broker.
  using libkafka_asio::constants::kOffsetTimeLatest;
  OffsetRequest request;
  request.FetchTopicOffset("mytopic", 1, kOffsetTimeLatest);

  connection.AsyncRequest(request, &HandleRequest);

  ios.run();
  return 0;
}