-
Notifications
You must be signed in to change notification settings - Fork 1
/
consumer.cc
45 lines (34 loc) · 1.21 KB
/
consumer.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
#include <iostream>
#include <pulsar/Client.h>
using namespace pulsar;
using namespace std;
int main() {
std::string token = "eyJhbGciOiJ 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);
Consumer consumer;
Result result = client.subscribe(topicName, "consumer-name", consumer);
if (result != ResultOk) {
cout << "Failed to subscribe: " << result << endl;
return -1;
}
Message msg;
while (true) {
consumer.receive(msg);
cout << "Received: " << msg << " with payload '" << msg.getDataAsString() << "'" << endl;
consumer.acknowledge(msg);
}
client.close();
}