]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab ft=cpp | |
3 | ||
4 | #pragma once | |
5 | ||
6 | #include <string> | |
7 | #include <functional> | |
8 | #include <boost/smart_ptr/intrusive_ptr.hpp> | |
9 | #include <boost/optional.hpp> | |
10 | ||
11 | #include "include/common_fwd.h" | |
12 | ||
13 | namespace rgw::kafka { | |
14 | // forward declaration of connection object | |
15 | struct connection_t; | |
16 | ||
17 | typedef boost::intrusive_ptr<connection_t> connection_ptr_t; | |
18 | ||
19 | // required interfaces needed so that connection_t could be used inside boost::intrusive_ptr | |
20 | void intrusive_ptr_add_ref(const connection_t* p); | |
21 | void intrusive_ptr_release(const connection_t* p); | |
22 | ||
23 | // the reply callback is expected to get an integer parameter | |
24 | // indicating the result, and not to return anything | |
25 | typedef std::function<void(int)> reply_callback_t; | |
26 | ||
27 | // initialize the kafka manager | |
28 | bool init(CephContext* cct); | |
29 | ||
30 | // shutdown the kafka manager | |
31 | void shutdown(); | |
32 | ||
33 | // connect to a kafka endpoint | |
34 | connection_ptr_t connect(const std::string& url, bool use_ssl, bool verify_ssl, boost::optional<const std::string&> ca_location); | |
35 | ||
36 | // publish a message over a connection that was already created | |
37 | int publish(connection_ptr_t& conn, | |
38 | const std::string& topic, | |
39 | const std::string& message); | |
40 | ||
41 | // publish a message over a connection that was already created | |
42 | // and pass a callback that will be invoked (async) when broker confirms | |
43 | // receiving the message | |
44 | int publish_with_confirm(connection_ptr_t& conn, | |
45 | const std::string& topic, | |
46 | const std::string& message, | |
47 | reply_callback_t cb); | |
48 | ||
49 | // convert the integer status returned from the "publish" function to a string | |
50 | std::string status_to_string(int s); | |
51 | ||
52 | // number of connections | |
53 | size_t get_connection_count(); | |
54 | ||
55 | // return the number of messages that were sent | |
56 | // to broker, but were not yet acked/nacked/timedout | |
57 | size_t get_inflight(); | |
58 | ||
59 | // running counter of successfully queued messages | |
60 | size_t get_queued(); | |
61 | ||
62 | // running counter of dequeued messages | |
63 | size_t get_dequeued(); | |
64 | ||
65 | // number of maximum allowed connections | |
66 | size_t get_max_connections(); | |
67 | ||
68 | // number of maximum allowed inflight messages | |
69 | size_t get_max_inflight(); | |
70 | ||
71 | // maximum number of messages in the queue | |
72 | size_t get_max_queue(); | |
73 | ||
74 | // disconnect from a kafka broker | |
75 | bool disconnect(connection_ptr_t& conn); | |
76 | ||
77 | // display connection as string | |
78 | std::string to_string(const connection_ptr_t& conn); | |
79 | ||
80 | } | |
81 |