-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathkafkaProducerFacade.hxx
67 lines (50 loc) · 1.89 KB
/
kafkaProducerFacade.hxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/** © Copyright 2019 CERN
*
* This software is distributed under the terms of the
* GNU Lesser General Public Licence version 3 (LGPL Version 3),
* copied verbatim in the file “LICENSE”
*
* In applying this licence, CERN does not waive the privileges
* and immunities granted to it by virtue of its status as an
* Intergovernmental Organization or submit itself to any jurisdiction.
*
* Author: Alexandru Savulescu (HSE-CEN-CO)
*
**/
#ifndef KAFKAPRODUCERFACADE_HXX
#define KAFKAPRODUCERFACADE_HXX
#include <string>
#include <stdexcept>
#include <iostream>
#include <memory>
#include <cppkafka/utils/buffered_producer.h>
using std::string;
using cppkafka::BufferedProducer;
using statsCallback = std::function<void(const std::string&)>;
using errorCallback = std::function<void(int error, const std::string& reason)>;
using successCallback = statsCallback;
/**
* @brief The kafkaProducerFacade class is a facade and encompasses all the producer interaction with librdkafka and cppkafka
*/
class kafkaProducerFacade
{
public:
/**
* @brief kafkaProducerFacade constructor
* @param errorCallbackConsumer : an error callback for underlying kafka errors
* @param statsCallbackConsumer : a callback for handling producer statistics
*/
kafkaProducerFacade(errorCallback, statsCallback);
~kafkaProducerFacade();
kafkaProducerFacade(const kafkaProducerFacade& ) = delete;
kafkaProducerFacade& operator=(const kafkaProducerFacade& ) = delete;
void stream(const std::string& topic, int partition, const std::string&, std::string&& message);
void stream(const std::string& topic, const std::string&, std::string&& message);
void setProducerSuccessCallback(successCallback);
void poll();
private:
std::unique_ptr<BufferedProducer<std::string>> _buffProducer;
errorCallback _errorCB;
statsCallback _statsCB;
};
#endif // KAFKAPRODUCERFACADE_HXX