lnk commit front code
This commit is contained in:
43
json/kafka_producer.h
Normal file
43
json/kafka_producer.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#ifndef _FEKAFKA_PRODUCER_
|
||||
#define _FEKAFKA_PRODUCER_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
#include "rdkafkacpp.h"
|
||||
|
||||
class FeKafkaProducer
|
||||
{
|
||||
public:
|
||||
FeKafkaProducer();
|
||||
~FeKafkaProducer();
|
||||
|
||||
public:
|
||||
bool init(const std::string &brokerlist, const bool &async = true, const int &size = 0x7fffffff);
|
||||
int send(const char *data,
|
||||
const int &size,
|
||||
const std::string &topic,
|
||||
const int &partition = 0,
|
||||
const std::string *key = NULL,
|
||||
const int &timeout = 0);
|
||||
int send_batch(const std::vector<std::pair<const char *, const int &> > &data,
|
||||
const std::string &topic,
|
||||
const int &partition = 0,
|
||||
const int &timeout = 0);
|
||||
bool create_topic(const std::string &topic);
|
||||
void close();
|
||||
|
||||
private:
|
||||
void read_config(const char *path);
|
||||
RdKafka::Topic* get_topic(const std::string &topic);
|
||||
|
||||
private:
|
||||
RdKafka::Producer* producer_;
|
||||
RdKafka::Conf* conf_;
|
||||
RdKafka::Conf* tconf_;
|
||||
std::map<std::string, RdKafka::Topic*> topics_;
|
||||
};
|
||||
|
||||
#endif // _KAFKA_PRODUCER_
|
||||
Reference in New Issue
Block a user