-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
also add libpulsarwithdeps.a together with libpulsar.a into cpp clien…
…t release
- Loading branch information
Showing
6 changed files
with
115 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* Copyright (c) 2007 EntIT Software LLC, a Micro Focus company */ | ||
|
||
#include <algorithm> | ||
#include <array> | ||
#include <chrono> | ||
#include <list> | ||
#include <map> | ||
#include <memory> | ||
#include <utility> | ||
#include <sstream> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include <pulsar/Client.h> | ||
#include <pulsar/ClientConfiguration.h> | ||
#include <pulsar/Consumer.h> | ||
#include <pulsar/Message.h> | ||
#include <pulsar/Result.h> | ||
#include <pulsar/Authentication.h> | ||
|
||
#include <boost/asio/ssl.hpp> | ||
|
||
int main(int argc, char **argv) { | ||
|
||
boost::asio::ssl::context ctx(boost::asio::ssl::context::tlsv12_client); | ||
|
||
/** | ||
ClientConfiguration config = ClientConfiguration(); | ||
config.setUseTls(true); | ||
std::string certfile = "/tmp/RIC_ca.crt"; | ||
ParamMap params; | ||
params["tlsCertFile"] = "/tmp/server.cert"; | ||
params["tlsKeyFile"] = "/tmp/server.key"; | ||
config.setTlsTrustCertsFilePath(certfile); | ||
config.setTlsAllowInsecureConnection(false); | ||
AuthenticationPtr auth = pulsar::AuthFactory::create("libauthtls.so", params); | ||
config.setAuth(auth); | ||
**/ | ||
|
||
pulsar::ClientConfiguration conf; | ||
pulsar::AuthenticationPtr auth; | ||
auth = pulsar::AuthTls::create("/tmp/server.crt", "/tmp/server.key"); | ||
conf.setAuth(auth); | ||
conf.setUseTls(true); | ||
conf.setTlsTrustCertsFilePath("/tmp/RIC_ca.crt"); | ||
conf.setTlsAllowInsecureConnection(false); | ||
|
||
// char service[] = "pulsar://localhost:6650"; | ||
char service[] = "pulsar+ssl://opsbsac0130mast-01.swinfra.net:31051"; | ||
char topic[] = "public/default/test-topic-1"; | ||
char subscription[] = "consumer-1"; | ||
|
||
pulsar::Client *client_ = new pulsar::Client(service, conf); | ||
pulsar::Consumer *consumer_ = new pulsar::Consumer(); | ||
pulsar::Result result = client_->subscribe(topic , subscription, *consumer_); | ||
if (result != pulsar::ResultOk) { | ||
|
||
std::cout << "ERROR: failed to subscribe(" | ||
<< subscription | ||
<< ") to " | ||
<< service | ||
<< "/" | ||
<< topic | ||
<< "=" | ||
<< pulsar::strResult(result) | ||
<< std::endl; | ||
|
||
return 1; | ||
} else { | ||
|
||
std::cout << "SUCCESS: subscribe(" | ||
<< subscription | ||
<< ") to " | ||
<< service | ||
<< "/" | ||
<< topic | ||
<< "=" | ||
<< pulsar::strResult(result) | ||
<< std::endl; | ||
} | ||
|
||
pulsar::Message message = pulsar::Message(); | ||
result = consumer_->receive(message); | ||
if (result != pulsar::ResultOk) { | ||
std::cout << "ERROR receive:" << pulsar::strResult(result) << std::endl; | ||
return 1; | ||
} else { | ||
std::cout << "SUCCESS" << std::endl; | ||
} | ||
result = consumer_->acknowledge(message); | ||
if (result != pulsar::ResultOk) { | ||
std::cout << "ERROR receive:" << pulsar::strResult(result) << std::endl; | ||
return 1; | ||
} else { | ||
std::cout << "ACK " << message.getDataAsString() << std::endl; | ||
} | ||
|
||
|
||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.