This is an automated email from the ASF dual-hosted git repository.

lizhanhui pushed a commit to branch v5.0-rc2
in repository https://gitbox.apache.org/repos/asf/rocketmq-client-cpp.git

commit 2e09b49097260c959f4cc3631b00c06dae3f1b90
Author: Li Zhanhui <[email protected]>
AuthorDate: Mon Aug 8 17:04:31 2022 +0800

    Use gRPC with SSL context
---
 CMakeLists.txt                                  |  2 +-
 examples/CMakeLists.txt                         |  7 +++++++
 examples/rocketmq/CMakeLists.txt                |  0
 src/main/cpp/client/ClientManagerImpl.cpp       | 28 +++++--------------------
 src/main/cpp/client/include/ClientManagerImpl.h |  3 ---
 5 files changed, 13 insertions(+), 27 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 21a1a54..cc883d1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -30,5 +30,5 @@ if (BUILD_EXAMPLES)
     list(APPEND CMAKE_PREFIX_PATH $ENV{HOME}/gflags)
     find_package(gflags REQUIRED)
     find_package(ZLIB REQUIRED)
-    add_subdirectory(examples/rocketmq)
+    add_subdirectory(examples)
 endif ()
\ No newline at end of file
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
new file mode 100644
index 0000000..fb5fbfd
--- /dev/null
+++ b/examples/CMakeLists.txt
@@ -0,0 +1,7 @@
+function(add_example name file)
+    add_executable(${name} ${file})
+    target_link_libraries(${name} PRIVATE api ZLIB::ZLIB rocketmq)
+endfunction()
+
+add_example(ons_example_producer ons/ExampleProducer.cpp)
+add_example(ons_example_push_consumer ons/ExamplePushConsumer.cpp)
\ No newline at end of file
diff --git a/examples/rocketmq/CMakeLists.txt b/examples/rocketmq/CMakeLists.txt
deleted file mode 100644
index e69de29..0000000
diff --git a/src/main/cpp/client/ClientManagerImpl.cpp 
b/src/main/cpp/client/ClientManagerImpl.cpp
index d165d4e..476fce7 100644
--- a/src/main/cpp/client/ClientManagerImpl.cpp
+++ b/src/main/cpp/client/ClientManagerImpl.cpp
@@ -53,24 +53,9 @@ ClientManagerImpl::ClientManagerImpl(std::string 
resource_namespace)
       latency_histogram_("Message-Latency", 11) {
   spdlog::set_level(spdlog::level::trace);
   assignLabels(latency_histogram_);
-//  server_authorization_check_config_ = 
std::make_shared<grpc::experimental::TlsServerAuthorizationCheckConfig>(
-//      std::make_shared<TlsServerAuthorizationChecker>());
-
-  // Make use of encryption only at the moment.
-  std::vector<grpc::experimental::IdentityKeyCertPair> identity_key_cert_list;
-  grpc::experimental::IdentityKeyCertPair pair{};
-  pair.private_key = TlsHelper::client_private_key;
-  pair.certificate_chain = TlsHelper::client_certificate_chain;
-
-  identity_key_cert_list.emplace_back(pair);
-  certificate_provider_ =
-      
std::make_shared<grpc::experimental::StaticDataCertificateProvider>(TlsHelper::CA,
 identity_key_cert_list);
-//  
tls_channel_credential_options_.set_server_verification_option(GRPC_TLS_SKIP_ALL_SERVER_VERIFICATION);
-  
tls_channel_credential_options_.set_certificate_provider(certificate_provider_);
-//  
tls_channel_credential_options_.set_server_authorization_check_config(server_authorization_check_config_);
-  tls_channel_credential_options_.watch_root_certs();
-  tls_channel_credential_options_.watch_identity_key_cert_pairs();
-  channel_credential_ = 
grpc::experimental::TlsCredentials(tls_channel_credential_options_);
+
+  grpc::SslCredentialsOptions options = {};
+  channel_credential_ = grpc::SslCredentials(options);
 
   // Use unlimited receive message size.
   channel_arguments_.SetMaxReceiveMessageSize(-1);
@@ -522,9 +507,7 @@ bool ClientManagerImpl::send(const std::string& 
target_host, const Metadata& met
 std::shared_ptr<grpc::Channel> ClientManagerImpl::createChannel(const 
std::string& target_host) {
   
std::vector<std::unique_ptr<grpc::experimental::ClientInterceptorFactoryInterface>>
 interceptor_factories;
   
interceptor_factories.emplace_back(absl::make_unique<LogInterceptorFactory>());
-  auto channel = grpc::experimental::CreateCustomChannelWithInterceptors(
-      target_host, channel_credential_, channel_arguments_, 
std::move(interceptor_factories));
-  return channel;
+  return grpc::CreateCustomChannel(target_host, channel_credential_, 
channel_arguments_);
 }
 
 RpcClientSharedPtr ClientManagerImpl::getRpcClient(const std::string& 
target_host, bool need_heartbeat) {
@@ -540,8 +523,7 @@ RpcClientSharedPtr ClientManagerImpl::getRpcClient(const 
std::string& target_hos
       }
       
std::vector<std::unique_ptr<grpc::experimental::ClientInterceptorFactoryInterface>>
 interceptor_factories;
       
interceptor_factories.emplace_back(absl::make_unique<LogInterceptorFactory>());
-      auto channel = grpc::experimental::CreateCustomChannelWithInterceptors(
-          target_host, channel_credential_, channel_arguments_, 
std::move(interceptor_factories));
+      auto channel = createChannel(target_host);
       client = std::make_shared<RpcClientImpl>(completion_queue_, channel, 
need_heartbeat);
       rpc_clients_.insert_or_assign(target_host, client);
     } else {
diff --git a/src/main/cpp/client/include/ClientManagerImpl.h 
b/src/main/cpp/client/include/ClientManagerImpl.h
index 473e7db..5f63359 100644
--- a/src/main/cpp/client/include/ClientManagerImpl.h
+++ b/src/main/cpp/client/include/ClientManagerImpl.h
@@ -265,9 +265,6 @@ private:
   /**
    * TLS configuration
    */
-//  std::shared_ptr<grpc::experimental::TlsServerAuthorizationCheckConfig> 
server_authorization_check_config_;
-  std::shared_ptr<grpc::experimental::CertificateProviderInterface> 
certificate_provider_;
-  grpc::experimental::TlsChannelCredentialsOptions 
tls_channel_credential_options_;
   std::shared_ptr<grpc::ChannelCredentials> channel_credential_;
   grpc::ChannelArguments channel_arguments_;
 

Reply via email to