Skip to content

Commit

Permalink
also add libpulsarwithdeps.a together with libpulsar.a into cpp clien…
Browse files Browse the repository at this point in the history
…t release
  • Loading branch information
jiazhai committed Mar 11, 2020
1 parent c3672a2 commit a4dc4e8
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 7 deletions.
102 changes: 102 additions & 0 deletions pulsar-client-cpp/PulsarTest.cpp
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;
}

2 changes: 1 addition & 1 deletion pulsar-client-cpp/docker/build-client-lib-within-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ cmake . -DBUILD_TESTS=OFF -DLINK_STATIC=ON \
-DPYTHON_INCLUDE_DIR=/opt/python/$PYTHON_SPEC/include/python$PYTHON_VERSION \
-DPYTHON_LIBRARY=/opt/python/$PYTHON_SPEC/lib \

make pulsarShared pulsarStatic -j4
make pulsarShared pulsarStatic pulsarStaticWithDeps -j4
9 changes: 5 additions & 4 deletions pulsar-client-cpp/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ if (MSVC)
endif()

# When linking statically, install a libpulsar.a that contains all the
# required dependencies
# required dependencies except ssl
if (LINK_STATIC)
if (MSVC)

Expand All @@ -98,8 +98,10 @@ if (LINK_STATIC)
set_target_properties(pulsarStaticWithDeps PROPERTIES STATIC_LIBRARY_FLAGS_DEBUG ${DEBUG_STATIC_LIBS} STATIC_LIBRARY_FLAGS_RELEASE ${STATIC_LIBS} OUTPUT_NAME ${LIB_NAME}WithDeps VERSION ${LIBRARY_VERSION})
install(TARGETS pulsarStaticWithDeps DESTINATION lib)
else()
# Build a list of the requird .a libs to merge
# Build a list of the requird .a libs (except ssl) to merge
SET(STATIC_LIBS "")
LIST(REMOVE_ITEM COMMON_LIBS ${OPENSSL_SSL_LIBRARY})
LIST(REMOVE_ITEM COMMON_LIBS ${OPENSSL_CRYPTO_LIBRARY})
foreach (LIB IN LISTS COMMON_LIBS)
if (${LIB} MATCHES ".+\\.a$")
set(STATIC_LIBS "${STATIC_LIBS} ${LIB}")
Expand All @@ -109,10 +111,9 @@ if (LINK_STATIC)
add_custom_target(pulsarStaticWithDeps
ALL
BYPRODUCTS merged-library
COMMAND ./build-support/merge_archives.sh libpulsar.a $<TARGET_FILE:pulsarStatic> ${STATIC_LIBS}
COMMAND ./build-support/merge_archives.sh libpulsar.a $<TARGET_FILE:pulsarStatic> ${STATIC_LIBS} && mv merged-library/libpulsar.a lib/libpulsarwithdeps.a
DEPENDS pulsarStatic
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
install(FILES ../merged-library/libpulsar.a DESTINATION lib)
endif(MSVC)
else()
# Install regular libpulsar.a
Expand Down
5 changes: 4 additions & 1 deletion pulsar-client-cpp/pkg/deb/build-deb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ tar xfz $SRC_ROOT_DIR/distribution/server/target/apache-pulsar-$POM_VERSION-src.
pushd $CPP_DIR

cmake . -DBUILD_TESTS=OFF -DLINK_STATIC=ON
make pulsarShared pulsarStatic -j 3
make pulsarShared pulsarStatic pulsarStaticWithDeps -j 3
popd

DEST_DIR=apache-pulsar-client
Expand Down Expand Up @@ -68,8 +68,11 @@ mkdir -p $DEVEL_DEST_DIR/usr/include
mkdir -p $DEST_DIR/usr/share/doc/pulsar-client-$VERSION
mkdir -p $DEVEL_DEST_DIR/usr/share/doc/pulsar-client-dev-$VERSION

ls $CPP_DIR/lib/libpulsar*

cp -ar $CPP_DIR/include/pulsar $DEVEL_DEST_DIR/usr/include/
cp $CPP_DIR/lib/libpulsar.a $DEVEL_DEST_DIR/usr/lib
cp $CPP_DIR/lib/libpulsarwithdeps.a $DEVEL_DEST_DIR/usr/lib
cp $CPP_DIR/lib/libpulsar.so.$POM_VERSION $DEST_DIR/usr/lib
pushd $DEST_DIR/usr/lib
ln -s libpulsar.so.$POM_VERSION libpulsar.so
Expand Down
4 changes: 3 additions & 1 deletion pulsar-client-cpp/pkg/rpm/SPECS/pulsar-client.spec
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static library.
%build
cd pulsar-client-cpp
cmake . -DBUILD_TESTS=OFF -DLINK_STATIC=ON -DBUILD_PYTHON_WRAPPER=OFF
make pulsarShared pulsarStatic -j 3
make pulsarShared pulsarStatic pulsarStaticWithDeps -j 3

%install
cd pulsar-client-cpp
Expand All @@ -65,6 +65,7 @@ mkdir -p $INCLUDE_DIR $LIB_DIR $DOC_DIR $DOC_DEVEL_DIR

cp -ar include/pulsar $INCLUDE_DIR
cp lib/libpulsar.a $LIB_DIR
cp lib/libpulsarwithdeps.a $LIB_DIR
cp lib/libpulsar.so.%{pom_version} $LIB_DIR

# Copy LICENSE files
Expand All @@ -85,5 +86,6 @@ ln -s libpulsar.so.%{pom_version} libpulsar.so
%files devel
%defattr(-,root,root)
/usr/lib/libpulsar.a
/usr/lib/libpulsarwithdeps.a
/usr/include/pulsar
/usr/share/doc/pulsar-client-devel-%{version}
Binary file added pulsar-client-cpp/test
Binary file not shown.

0 comments on commit a4dc4e8

Please sign in to comment.