-
Notifications
You must be signed in to change notification settings - Fork 1
/
reader.cc
52 lines (41 loc) · 1.54 KB
/
reader.cc
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
#include <iostream>
#include <pulsar/Client.h>
using namespace pulsar;
using namespace std;
int main() {
std::string token = "eyJhbGciOiJSUzI Pulsar JWT";
std::string serviceURL = "pulsar+ssl://useast2.aws.kafkaesque.io:6651";
std::string topicName = "persistent://ming-luo/local-useast2-aws/test-topic2";
AuthenticationPtr auth = pulsar::AuthToken::createWithToken(token);
ClientConfiguration config = ClientConfiguration();
config.setAuth(auth);
config.setTlsTrustCertsFilePath("/etc/ssl/certs/ca-bundle.crt");
/**
*Use default CA certs for your environment
* RHEL/CentOS:
* trust_certs='/etc/ssl/certs/ca-bundle.crt'
* Debian/Ubuntu:
* trust_certs='/etc/ssl/certs/ca-certificates.crt'
*/
Client client(serviceURL, config);
ReaderConfiguration readerConf;
Reader reader;
Result result = client.createReader(topicName, MessageId::earliest(), readerConf, reader);
if (result != ResultOk) {
cout << "Failed to subscribe: " << result << endl;
return -1;
}
Message msg;
Result res;
while (true) {
res = reader.readNext(msg, 1000);
if (res != ResultTimeout) {
// In case of timeout we keep calling receive() to simulate a
// blocking call until a message is available, while breaking
// every once in a while to check the Python signal status
break;
}
cout << "Received: " << msg << " with payload '" << msg.getDataAsString() << "'" << endl;
}
client.close();
}