-
Notifications
You must be signed in to change notification settings - Fork 1
/
producer.cc
40 lines (32 loc) · 1.17 KB
/
producer.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
#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);
Producer producer;
Result result = client.createProducer(topicName, producer);
if (result != ResultOk) {
cout << "Error creating producer: " << result << endl;
return -1;
}
// Send synchronously
Message msg = MessageBuilder().setContent("content").build();
Result res = producer.send(msg);
cout << "Message sent: " << res << endl;
client.close();
}