├── LICENSE ├── README.md ├── demo-async-client ├── CMakeLists.txt ├── config │ └── dfzq-grpc-config.properties ├── demo-async-client.cpp ├── helloworld.grpc.pb.cc ├── helloworld.grpc.pb.h ├── helloworld.pb.cc ├── helloworld.pb.h └── helloworld.proto ├── demo-async-server ├── CMakeLists.txt ├── config │ └── dfzq-grpc-config.properties ├── demo-async-server.cpp ├── helloworld.grpc.pb.cc ├── helloworld.grpc.pb.h ├── helloworld.pb.cc ├── helloworld.pb.h └── helloworld.proto ├── demo-sync-client ├── CMakeLists.txt ├── config │ └── dfzq-grpc-config.properties ├── demo-sync-client.cpp ├── helloworld.grpc.pb.cc ├── helloworld.grpc.pb.h ├── helloworld.pb.cc ├── helloworld.pb.h └── helloworld.proto └── demo-sync-server ├── CMakeLists.txt ├── config └── dfzq-grpc-config.properties ├── demo-sync-server.cpp ├── helloworld.grpc.pb.cc ├── helloworld.grpc.pb.h ├── helloworld.pb.cc ├── helloworld.pb.h └── helloworld.proto /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # grpc-nebula-samples-c 2 | 微服务治理框架使用示例(C++版本) 3 | -------------------------------------------------------------------------------- /demo-async-client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # CMake 最低版本号要求 2 | cmake_minimum_required (VERSION 2.8) 3 | 4 | # 项目信息 5 | project (demo-async-client CXX) 6 | 7 | # 版本信息 8 | set (Demo_VERSION_MAJOR 1) 9 | set (Demo_VERSION_MINOR 0) 10 | 11 | 12 | # 编译参数 13 | set (CMAKE_BUILE_TYPE RELEASE) 14 | add_definitions(-DRELEASE) 15 | 16 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC -pthread") 17 | 18 | 19 | # 查找当前目录下的所有源文件 20 | # 并将名称保存到 DIR_LIB_SRCS 变量 21 | aux_source_directory(. DIR_LIB_SRCS) 22 | #aux_source_directory(model DIR_LIB_SRCS) 23 | 24 | set (EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}) 25 | #设置proto工具目录 26 | get_filename_component(proto_tool "${PROJECT_SOURCE_DIR}/../../libs/protobuf" ABSOLUTE) 27 | #生成PB 28 | execute_process(COMMAND ${proto_tool}/protoc -I ${PROJECT_SOURCE_DIR} --cpp_out=${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/helloworld.proto) 29 | execute_process(COMMAND ${proto_tool}/protoc -I ${PROJECT_SOURCE_DIR} --grpc_out=${PROJECT_SOURCE_DIR} 30 | --plugin=protoc-gen-grpc=${proto_tool}/grpc_cpp_plugin ${PROJECT_SOURCE_DIR}/helloworld.proto) 31 | 32 | # 链接库目录 33 | link_directories ("${PROJECT_SOURCE_DIR}/../../libs/opt" 34 | "${PROJECT_SOURCE_DIR}/../../libs/lib" 35 | "${PROJECT_SOURCE_DIR}/../../libs/protobuf" 36 | "${PROJECT_SOURCE_DIR}/../../libs/zookeeper") 37 | 38 | # 添加包含目录 39 | include_directories("${PROJECT_SOURCE_DIR}" 40 | "${PROJECT_SOURCE_DIR}/../../include/orientsec_grpc" 41 | "${PROJECT_SOURCE_DIR}/../../include/include" 42 | "${PROJECT_SOURCE_DIR}/../../include/third_party/protobuf/src/" 43 | "${PROJECT_SOURCE_DIR}/../../include/third_party/protobuf" 44 | "${PROJECT_SOURCE_DIR}/model") 45 | 46 | 47 | # 生成链接库 48 | add_executable (demo-async-client ${DIR_LIB_SRCS}) 49 | 50 | # 添加链接库 51 | target_link_libraries(demo-async-client libgpr.so) 52 | target_link_libraries(demo-async-client libgrpc.so) 53 | target_link_libraries(demo-async-client libgrpc++.so) 54 | target_link_libraries(demo-async-client libprotobuf.a) 55 | target_link_libraries(demo-async-client libssl.so) 56 | target_link_libraries(demo-async-client liborientsec_common.a) 57 | target_link_libraries(demo-async-client liborientsec_provider.a) 58 | target_link_libraries(demo-async-client liborientsec_consumer.a) 59 | target_link_libraries(demo-async-client liborientsec_registry.a) 60 | target_link_libraries(demo-async-client libzookeeper_mt.so) 61 | 62 | -------------------------------------------------------------------------------- /demo-async-client/config/dfzq-grpc-config.properties: -------------------------------------------------------------------------------- 1 | # 配置信息分为五类: 2 | # 1. common config (公共配置) 3 | # 2. provider config (服务提供者需要填写) 4 | # 3. consumer config (服务消费者需要填写) 5 | # 4. kafka config (提供者、消费者都需要配置) 6 | # 5. zookeeper config (提供者、消费者都需要配置) 7 | 8 | # 配置文件的放置路径:class文件根目录 9 | # (请参照:使用log4j记日志的项目中 log4j.properties 文件的路径) 10 | 11 | 12 | # ------------ begin of common config ------------ 13 | 14 | # 必填,类型string,说明:当前应用名称 15 | common.application=grpc-test-app 16 | 17 | # 必填,类型string,说明:grpc版本号 18 | common.grpc=1.2.4 19 | 20 | #选填,默认是 grpc-test-app,说明:grpc项目名监控 21 | common.project=grpc-java 22 | 23 | # 选填,类型string,说明:服务注册根路径,默认值/Application/grpc 24 | #common.root=/Application/grpc/c++ 25 | 26 | 27 | # 必填,类型string,说明:项目负责人,员工工号,多个工号之间使用英文逗号 28 | common.owner=A9001,A9002,A9003 29 | 30 | # 可选,类型string,说明:服务注册使用的IP地址 31 | # 如果不配置该参数值,当前服务器的IP地址为"非127.0.0.1的第一个网卡的IP地址" 32 | # 使用场合:一台服务器安装有多个网卡,如果需要指定不是第一个网卡的IP地址为服务注册的IP地址 33 | #common.localhost.ip=192.168.2.123 34 | 35 | # ------------ end of common config ------------ 36 | 37 | 38 | 39 | 40 | # ------------ begin of provider config ------------ 41 | 42 | # 必填,类型string,说明:服务的版本信息,一般表示服务接口的版本号 43 | provider.version=2.0 44 | 45 | # 必填,类型String,固定值provider,说明:provider表示服务提供端,consumer表示服务消费端 46 | provider.side=provider 47 | 48 | # ---------------------------------------- 49 | 50 | # 可选,类型string,说明:当前模块名称 51 | # provider.module= 52 | 53 | # 可选,类型string,说明:服务分组信息,一般用来区分一个服务接口的多种实现(provider) 54 | # provider.group= 55 | 56 | # 可选,类型int,缺省值1000,说明:远程服务调用超时时间(毫秒) 57 | # provider.default.timeout= 58 | 59 | # 可选,类型int,缺省值2,说明:远程服务调用重试次数,不包括第一次调用,不需要重试则设置为0 60 | # provider.default.reties= 61 | 62 | # 可选,类型int,缺省值0,说明:对每个provider最大连接次数,默认最大连接数 63 | #provider.default.connections=1 64 | 65 | # 可选,类型string,缺省值round_robin,说明:负载均衡策略,可选值:pick_first、round_robin,weight_round_robin,可扩展实现其他策略 66 | # provider.default.loadbalance= 67 | 68 | # 可选,类型Boolean,缺省值false,说明:是否缺省异步执行,如果true则可直接忽略返回值,不阻塞线程 69 | # provider.default.async= 70 | #Max request 71 | #provider.default.requests=1 72 | # dataflow control 73 | #provider.default.connections=1 74 | 75 | #route rule 76 | #provider.access.protected=true 77 | 78 | 79 | # 可选,类型sting/Boolean,缺省值false,说明:令牌验证,为空表示不开启,为true则随机生成动态令牌,否则使用镜头令牌 80 | # provider.token= 81 | 82 | # 可选,类型boolean,缺省值false,说明:服务是否过时,如果为true则应用该服务时日志error告警 83 | # provider.deprecated=true 84 | 85 | # 可选,类型boolean,缺省值ture,说明:服务是否动态注册,如果为false则注册后将显示为disable状态, 86 | # 需要人工启用,且服务停止时需手动注销 87 | # provider.dynamic= 88 | 89 | # 可选,类型string/boolean,缺省值false,说明:设为true,将向logger中输出访问日志,也可填写访问 90 | # 日志文件路径,直接把访问日志输出到指定文件 91 | # provider.accesslog= 92 | 93 | # 可选,类型string,说明:服务负责人,填写负责人公司邮箱前缀 94 | # provider.owner= 95 | 96 | # 可选,类型int,缺省值100,说明:服务provider权重,是服务provider的容量,在负载均衡基于权重的选择算法中用到 97 | # provider.weight= 98 | 99 | # 可选,类型string,缺省值failover,说明:集群方式,可选:failover/failfast/failback/forking 100 | # provider.default.cluster= 101 | 102 | # 可选,类型string,说明:应用版本号 103 | # provider.application.version= 104 | 105 | # 可选,类型string,说明:组织名(BU或部门) 106 | # provider.organization= 107 | 108 | # 可选,类型string,说明:应用环境,如:develop/test/product 109 | # provider.environment= 110 | 111 | # 可选,类型string,说明:模块的版本号 112 | # provider.module.version= 113 | 114 | # 可选,类型boolean,缺省值false,说明:表示是否为跨主机访问 115 | # provider.anyhost= 116 | 117 | # 可选,类型string,说明:dubbo版本号,缺省值为grpc的版本号 118 | # provider.dubbo= 119 | 120 | # 可选, 类型boolean, 缺省值false, 说明:服务是否处于访问保护状态 121 | # 属性的可选值为false 、true ,分别表示不受保护、受保护,缺省值为false (不受保护) 122 | #provider.access.protected=true 123 | 124 | # ------------ end of provider config ------------ 125 | 126 | 127 | 128 | 129 | # ------------ begin of consumer config ------------ 130 | 131 | # 必填,类型boolean,缺省值true,说明:启动时检查提供者是否存在,true报错,false忽略 132 | consumer.check=true 133 | 134 | # 必填,类型int,固定值1000,说明:远程服务调用超时时间(毫秒) 135 | consumer.default.timeout=1000 136 | 137 | # 必填,类型String,默认值consumers,说明:所属范畴 138 | consumer.category=consumers 139 | 140 | # 必填,类型String,固定值consumer,说明:provider表示服务提供端,consumer表示服务消费端 141 | consumer.side=consumer 142 | 143 | # -------------------------- 144 | # 可选,类型string,说明:服务提供者的版本号 145 | # 指定了服务提供者的版本号之后,程序会优先选择具有指定版本的服务;如果注册中心没有该版本的服务,则不限制版本重新选择服务提供者。 146 | # 使用场景为:注册中心上同一个服务多版本共存,并且服务的高版本与低版本不兼容,而当前应用由于特殊原因只能调用低版本的服务 147 | # 如果当前应用只调用一个服务,属性值直接配置版本号,例如1.0.0 148 | # 如果当前应用需要调用多个服务,属性值按照冒号逗号的方式分隔,例如com.dfzq.examples.Greeter:1.0.0,com.dfzq.examples.Hello:1.2.1 149 | # 如果当前应用需要调用多个服务,建议在服务治理平台维护该属性,只有一个版本的服务可以不维护 150 | #consumer.service.version=helloworld.Greeter:1.0,com.dfzq.grpc.helloworld.Greeter:1.0.2 151 | 152 | # 可选,类型string,说明:应用版本号 153 | # consumer.application.version= 154 | 155 | # 可选,类型String,说明:服务消费方远程调用过程拦截器名称,多个名称用逗号分隔 156 | # consumer.default.reference.filter= 157 | 158 | # 可选,类型String,缺省值slf4j,说明:日志输出方式,可选:slf4j,jcl,log4j,jdk 159 | # consumer.logger= 160 | 161 | # 可选,类型String,说明:调用服务负责人,用于服务治理,请填写负责人公司邮箱前缀 162 | # consumer.owner= 163 | 164 | # 可选,类型string,说明:组织名(BU或部门) 165 | # consumer.organization= 166 | 167 | # 可选,类型int,缺省值2,说明:远程服务调用重试次数 168 | # consumer.default.retries= 169 | 170 | # 可选,类型string,缺省值connection,说明:负载均衡模式 171 | # 可选值为 connection 和 request,分别表示“连接负载均衡”、“请求负载均衡” 172 | # “连接负载均衡”适用于大部分业务场景,服务端和客户端消耗的资源较小。 173 | # “请求负载均衡”适用于服务端业务逻辑复杂、并有多台服务器提供相同服务的场景。 174 | consumer.loadbalance.mode=request 175 | #consumer.loadbalance.mode=connection 176 | 177 | 178 | # 可选,类型string,缺省值round_robin,说明:调度策略,可选范围:pick_first、round_robin、weight_round_robin、consistent_hash 179 | consumer.default.loadbalance=round_robin 180 | 181 | #the weight of provider 182 | provider.weight=1 183 | 184 | 185 | # 可选,类型string,负载均衡策略选择是consistent_hash(一致性Hash),配置进行hash运算的参数名称的列表 186 | # 多个参数之间使用英文逗号分隔,例如 id,name 187 | # 如果负载均衡策略选择是consistent_hash,但是该参数未配置参数值、或者参数值列表不正确,则随机取一个值来做散列运算 188 | 189 | consumer.consistent.hash.arguments=name,no 190 | 191 | # 可选,类型int,缺省值100,说明:每个服务对外最大连接数 192 | # consumer.default.connections= 193 | 194 | # 可选,类型string,缺省值failover,说明:集群方式,可选:failover/failfast/failback/forking 195 | # consumer.default.cluster= 196 | 197 | # 可选,类型integer,缺省值5,说明:连续多少次请求出错,自动切换到提供相同服务的新服务器 198 | consumer.switchover.threshold=5 199 | 200 | # 可选,类型为long,单位为秒,缺省值为60,说明:服务提供者不可用时的惩罚时间,即多次请求出错的服务提供者一段时间内不再去请求 201 | # 属性值大于或等于0,等于0表示没有惩罚时间,如果客户端只剩下一个服务提供者,即使服务提供者不可用,也不做剔除操作。 202 | consumer.unavailable.provider.punish.time=60 203 | # ------------ end of consumer config ------------ 204 | 205 | 206 | 207 | 208 | # ------------ begin of kafka.producer config ------------ 209 | 210 | # 转发服务跟踪信息给kafka的服务提供者的IP地址和端口 211 | # 服务跟踪信息先发送给KafkaSenderServer(一个基于原生grpc的服务),然后由KafkaSenderServer转发给kafka 212 | # 多个服务提供者之间使用英文逗号分隔,IP地址和端口使用英文冒号分隔 213 | # kafka.sender.servers=192.168.0.1:50080,192.168.0.2:50080,192.168.0.3:50080 214 | #kafka.sender.servers=127.0.0.1:50080 215 | #kafka.sender.servers=127.0.0.1:9093 216 | #kafka.sender.servers=160.6.78.133:50080 217 | 218 | # 可选,采样频率,指的是每秒采集服务链的数据条数(这里的一条理解为traceId相同的多个json串); 219 | # 默认值为空,表示所有服务链都发送到kafka; 220 | # 如果采样率的数值不为空,并且数值大于0,根据指定的采样率采集数据 221 | # 配置值可以为正整数、小数(例如0.5)、分数(例如3/1024) 222 | # kafka.sampling.frequency= 223 | 224 | # 可选, 将服务跟踪信息发送给KafkaSenderServer的线程个数 225 | # 配置值为正整数,默认值为1 226 | # kafka.sender.number=1 227 | 228 | # 可选, 服务跟踪信息消息队列的容量 229 | # 配置值为正整数,默认值为50000 230 | # message.queue.capacity=50000 231 | # -------------------------- 232 | 233 | # 可选,每个RecordBatch可以缓存的最大字节数 234 | # kafka.producer.batch.size=16384 235 | 236 | # 可选,所有RecordBatch的总共最大字节数 237 | # kafka.producer.buffer.memory=33554432 238 | 239 | # 可选,每个RecordBatch的最长延迟发送时间 240 | # kafka.producer.linger.ms=1 241 | 242 | # 可选,每个RecordBatch的最长阻塞时间 243 | # kafka.producer.max.block.ms=1 244 | 245 | # 可选,消息发送失败重试的次数 246 | # kafka.producer.retries=0 247 | 248 | # 可选,失败补偿时间,每次失败重试的时间间隔,不可设置太短,避免第一条消息的响应还没返回,第二条消息又发出去了,造成逻辑错误 249 | # kafka.producer.retry.backoff.ms 250 | 251 | # 可选,同一时间,producer到broker的一个连接上允许的最大未确认请求数,默认为5 252 | # kafka.producer.max.in.flight.requests.per.connection=5 253 | 254 | # 可选,采样频率,指的是每秒向kafka写服务链的数据条数(这里的一条理解为traceId相同的多个json串); 255 | # 默认值为空,表示所有服务链都发送到kafka; 256 | # 如果采样率的数值不为空,并且数值大于0,根据指定的采样率采集数据 257 | # 配置值可以为正整数、小数(例如0.5)、分数(例如3/1024) 258 | #kafka.sampling.frequency=0.5 259 | 260 | # ------------ end of kafka.producer config ------------ 261 | 262 | 263 | 264 | 265 | # ------------ begin of zookeeper config ------------ 266 | 267 | # zookeeper主机列表 268 | #zookeeper.host.server=192.168.207.4:2181,192.168.207.6:2181 269 | zookeeper.host.server=192.168.2.103:2181 270 | #zookeeper.host.server=160.6.78.133:2181 271 | 272 | #重试次数 273 | zookeeper.retryNum=5 274 | 275 | #连接超时时间 276 | zookeeper.connectiontimeout=5000 277 | 278 | 279 | # 可选,类型string,访问控制用户名 280 | zookeeper.acl.username=admin 281 | 282 | # 可选,类型string,访问控制密码 283 | # 这里的密码配置的是密文,使用com.orientsec.grpc.common.util.DesEncryptUtils#encrypt(String plaintext)进行加密 284 | #zookeeper.acl.password=9b579c35ca6cc74230f1eed29064d10a 285 | zookeeper.acl.password=9883c580ae8226f0dd8200620e4bc899 286 | 287 | 288 | 289 | # ------------ end of zookeeper config ------------ 290 | 291 | -------------------------------------------------------------------------------- /demo-async-client/demo-async-client.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grpc-nebula/grpc-nebula-samples-c/25d83e54d065c036dcda041ea9c5a1958587884b/demo-async-client/demo-async-client.cpp -------------------------------------------------------------------------------- /demo-async-client/helloworld.grpc.pb.cc: -------------------------------------------------------------------------------- 1 | // Generated by the gRPC C++ plugin. 2 | // If you make any local change, they will be lost. 3 | // source: helloworld.proto 4 | 5 | #include "helloworld.pb.h" 6 | #include "helloworld.grpc.pb.h" 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | namespace helloworld { 20 | 21 | static const char* Greeter_method_names[] = { 22 | "/helloworld.Greeter/SayHello", 23 | }; 24 | 25 | std::unique_ptr< Greeter::Stub> Greeter::NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options) { 26 | (void)options; 27 | std::unique_ptr< Greeter::Stub> stub(new Greeter::Stub(channel)); 28 | return stub; 29 | } 30 | 31 | Greeter::Stub::Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel) 32 | : channel_(channel), rpcmethod_SayHello_(Greeter_method_names[0], ::grpc::internal::RpcMethod::NORMAL_RPC, channel) 33 | {} 34 | 35 | ::grpc::Status Greeter::Stub::SayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::helloworld::HelloReply* response) { 36 | return ::grpc::internal::BlockingUnaryCall(channel_.get(), rpcmethod_SayHello_, context, request, response); 37 | } 38 | 39 | void Greeter::Stub::experimental_async::SayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response, std::function f) { 40 | return ::grpc::internal::CallbackUnaryCall(stub_->channel_.get(), stub_->rpcmethod_SayHello_, context, request, response, std::move(f)); 41 | } 42 | 43 | ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>* Greeter::Stub::AsyncSayHelloRaw(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) { 44 | return ::grpc::internal::ClientAsyncResponseReaderFactory< ::helloworld::HelloReply>::Create(channel_.get(), cq, rpcmethod_SayHello_, context, request, true); 45 | } 46 | 47 | ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>* Greeter::Stub::PrepareAsyncSayHelloRaw(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) { 48 | return ::grpc::internal::ClientAsyncResponseReaderFactory< ::helloworld::HelloReply>::Create(channel_.get(), cq, rpcmethod_SayHello_, context, request, false); 49 | } 50 | 51 | Greeter::Service::Service() { 52 | AddMethod(new ::grpc::internal::RpcServiceMethod( 53 | Greeter_method_names[0], 54 | ::grpc::internal::RpcMethod::NORMAL_RPC, 55 | new ::grpc::internal::RpcMethodHandler< Greeter::Service, ::helloworld::HelloRequest, ::helloworld::HelloReply>( 56 | std::mem_fn(&Greeter::Service::SayHello), this))); 57 | } 58 | 59 | Greeter::Service::~Service() { 60 | } 61 | 62 | ::grpc::Status Greeter::Service::SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response) { 63 | (void) context; 64 | (void) request; 65 | (void) response; 66 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 67 | } 68 | 69 | 70 | } // namespace helloworld 71 | 72 | -------------------------------------------------------------------------------- /demo-async-client/helloworld.grpc.pb.h: -------------------------------------------------------------------------------- 1 | // Generated by the gRPC C++ plugin. 2 | // If you make any local change, they will be lost. 3 | // source: helloworld.proto 4 | // Original file comments: 5 | // Copyright 2015 gRPC authors. 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | #ifndef GRPC_helloworld_2eproto__INCLUDED 20 | #define GRPC_helloworld_2eproto__INCLUDED 21 | 22 | #include "helloworld.pb.h" 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | namespace grpc { 38 | class CompletionQueue; 39 | class Channel; 40 | class ServerCompletionQueue; 41 | class ServerContext; 42 | } // namespace grpc 43 | 44 | namespace helloworld { 45 | 46 | // The greeting service definition. 47 | class Greeter final { 48 | public: 49 | static constexpr char const* service_full_name() { 50 | return "helloworld.Greeter"; 51 | } 52 | class StubInterface { 53 | public: 54 | virtual ~StubInterface() {} 55 | // Sends a greeting 56 | virtual ::grpc::Status SayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::helloworld::HelloReply* response) = 0; 57 | std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::helloworld::HelloReply>> AsyncSayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) { 58 | return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::helloworld::HelloReply>>(AsyncSayHelloRaw(context, request, cq)); 59 | } 60 | std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::helloworld::HelloReply>> PrepareAsyncSayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) { 61 | return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::helloworld::HelloReply>>(PrepareAsyncSayHelloRaw(context, request, cq)); 62 | } 63 | class experimental_async_interface { 64 | public: 65 | virtual ~experimental_async_interface() {} 66 | // Sends a greeting 67 | virtual void SayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response, std::function) = 0; 68 | }; 69 | virtual class experimental_async_interface* experimental_async() { return nullptr; } 70 | private: 71 | virtual ::grpc::ClientAsyncResponseReaderInterface< ::helloworld::HelloReply>* AsyncSayHelloRaw(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) = 0; 72 | virtual ::grpc::ClientAsyncResponseReaderInterface< ::helloworld::HelloReply>* PrepareAsyncSayHelloRaw(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) = 0; 73 | }; 74 | class Stub final : public StubInterface { 75 | public: 76 | Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel); 77 | ::grpc::Status SayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::helloworld::HelloReply* response) override; 78 | std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>> AsyncSayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) { 79 | return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>>(AsyncSayHelloRaw(context, request, cq)); 80 | } 81 | std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>> PrepareAsyncSayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) { 82 | return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>>(PrepareAsyncSayHelloRaw(context, request, cq)); 83 | } 84 | class experimental_async final : 85 | public StubInterface::experimental_async_interface { 86 | public: 87 | void SayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response, std::function) override; 88 | private: 89 | friend class Stub; 90 | explicit experimental_async(Stub* stub): stub_(stub) { } 91 | Stub* stub() { return stub_; } 92 | Stub* stub_; 93 | }; 94 | class experimental_async_interface* experimental_async() override { return &async_stub_; } 95 | 96 | private: 97 | std::shared_ptr< ::grpc::ChannelInterface> channel_; 98 | class experimental_async async_stub_{this}; 99 | ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>* AsyncSayHelloRaw(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) override; 100 | ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>* PrepareAsyncSayHelloRaw(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) override; 101 | const ::grpc::internal::RpcMethod rpcmethod_SayHello_; 102 | }; 103 | static std::unique_ptr NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options = ::grpc::StubOptions()); 104 | 105 | class Service : public ::grpc::Service { 106 | public: 107 | Service(); 108 | virtual ~Service(); 109 | // Sends a greeting 110 | virtual ::grpc::Status SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response); 111 | }; 112 | template 113 | class WithAsyncMethod_SayHello : public BaseClass { 114 | private: 115 | void BaseClassMustBeDerivedFromService(const Service *service) {} 116 | public: 117 | WithAsyncMethod_SayHello() { 118 | ::grpc::Service::MarkMethodAsync(0); 119 | } 120 | ~WithAsyncMethod_SayHello() override { 121 | BaseClassMustBeDerivedFromService(this); 122 | } 123 | // disable synchronous version of this method 124 | ::grpc::Status SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response) override { 125 | abort(); 126 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 127 | } 128 | void RequestSayHello(::grpc::ServerContext* context, ::helloworld::HelloRequest* request, ::grpc::ServerAsyncResponseWriter< ::helloworld::HelloReply>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { 129 | ::grpc::Service::RequestAsyncUnary(0, context, request, response, new_call_cq, notification_cq, tag); 130 | } 131 | }; 132 | typedef WithAsyncMethod_SayHello AsyncService; 133 | template 134 | class ExperimentalWithCallbackMethod_SayHello : public BaseClass { 135 | private: 136 | void BaseClassMustBeDerivedFromService(const Service *service) {} 137 | public: 138 | ExperimentalWithCallbackMethod_SayHello() { 139 | ::grpc::Service::experimental().MarkMethodCallback(0, 140 | new ::grpc::internal::CallbackUnaryHandler< ExperimentalWithCallbackMethod_SayHello, ::helloworld::HelloRequest, ::helloworld::HelloReply>( 141 | [this](::grpc::ServerContext* context, 142 | const ::helloworld::HelloRequest* request, 143 | ::helloworld::HelloReply* response, 144 | ::grpc::experimental::ServerCallbackRpcController* controller) { 145 | this->SayHello(context, request, response, controller); 146 | }, this)); 147 | } 148 | ~ExperimentalWithCallbackMethod_SayHello() override { 149 | BaseClassMustBeDerivedFromService(this); 150 | } 151 | // disable synchronous version of this method 152 | ::grpc::Status SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response) override { 153 | abort(); 154 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 155 | } 156 | virtual void SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response, ::grpc::experimental::ServerCallbackRpcController* controller) { controller->Finish(::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "")); } 157 | }; 158 | typedef ExperimentalWithCallbackMethod_SayHello ExperimentalCallbackService; 159 | template 160 | class WithGenericMethod_SayHello : public BaseClass { 161 | private: 162 | void BaseClassMustBeDerivedFromService(const Service *service) {} 163 | public: 164 | WithGenericMethod_SayHello() { 165 | ::grpc::Service::MarkMethodGeneric(0); 166 | } 167 | ~WithGenericMethod_SayHello() override { 168 | BaseClassMustBeDerivedFromService(this); 169 | } 170 | // disable synchronous version of this method 171 | ::grpc::Status SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response) override { 172 | abort(); 173 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 174 | } 175 | }; 176 | template 177 | class WithRawMethod_SayHello : public BaseClass { 178 | private: 179 | void BaseClassMustBeDerivedFromService(const Service *service) {} 180 | public: 181 | WithRawMethod_SayHello() { 182 | ::grpc::Service::MarkMethodRaw(0); 183 | } 184 | ~WithRawMethod_SayHello() override { 185 | BaseClassMustBeDerivedFromService(this); 186 | } 187 | // disable synchronous version of this method 188 | ::grpc::Status SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response) override { 189 | abort(); 190 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 191 | } 192 | void RequestSayHello(::grpc::ServerContext* context, ::grpc::ByteBuffer* request, ::grpc::ServerAsyncResponseWriter< ::grpc::ByteBuffer>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { 193 | ::grpc::Service::RequestAsyncUnary(0, context, request, response, new_call_cq, notification_cq, tag); 194 | } 195 | }; 196 | template 197 | class ExperimentalWithRawCallbackMethod_SayHello : public BaseClass { 198 | private: 199 | void BaseClassMustBeDerivedFromService(const Service *service) {} 200 | public: 201 | ExperimentalWithRawCallbackMethod_SayHello() { 202 | ::grpc::Service::experimental().MarkMethodRawCallback(0, 203 | new ::grpc::internal::CallbackUnaryHandler< ExperimentalWithRawCallbackMethod_SayHello, ::grpc::ByteBuffer, ::grpc::ByteBuffer>( 204 | [this](::grpc::ServerContext* context, 205 | const ::grpc::ByteBuffer* request, 206 | ::grpc::ByteBuffer* response, 207 | ::grpc::experimental::ServerCallbackRpcController* controller) { 208 | this->SayHello(context, request, response, controller); 209 | }, this)); 210 | } 211 | ~ExperimentalWithRawCallbackMethod_SayHello() override { 212 | BaseClassMustBeDerivedFromService(this); 213 | } 214 | // disable synchronous version of this method 215 | ::grpc::Status SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response) override { 216 | abort(); 217 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 218 | } 219 | virtual void SayHello(::grpc::ServerContext* context, const ::grpc::ByteBuffer* request, ::grpc::ByteBuffer* response, ::grpc::experimental::ServerCallbackRpcController* controller) { controller->Finish(::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "")); } 220 | }; 221 | template 222 | class WithStreamedUnaryMethod_SayHello : public BaseClass { 223 | private: 224 | void BaseClassMustBeDerivedFromService(const Service *service) {} 225 | public: 226 | WithStreamedUnaryMethod_SayHello() { 227 | ::grpc::Service::MarkMethodStreamed(0, 228 | new ::grpc::internal::StreamedUnaryHandler< ::helloworld::HelloRequest, ::helloworld::HelloReply>(std::bind(&WithStreamedUnaryMethod_SayHello::StreamedSayHello, this, std::placeholders::_1, std::placeholders::_2))); 229 | } 230 | ~WithStreamedUnaryMethod_SayHello() override { 231 | BaseClassMustBeDerivedFromService(this); 232 | } 233 | // disable regular version of this method 234 | ::grpc::Status SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response) override { 235 | abort(); 236 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 237 | } 238 | // replace default version of method with streamed unary 239 | virtual ::grpc::Status StreamedSayHello(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer< ::helloworld::HelloRequest,::helloworld::HelloReply>* server_unary_streamer) = 0; 240 | }; 241 | typedef WithStreamedUnaryMethod_SayHello StreamedUnaryService; 242 | typedef Service SplitStreamedService; 243 | typedef WithStreamedUnaryMethod_SayHello StreamedService; 244 | }; 245 | 246 | } // namespace helloworld 247 | 248 | 249 | #endif // GRPC_helloworld_2eproto__INCLUDED 250 | -------------------------------------------------------------------------------- /demo-async-client/helloworld.pb.h: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: helloworld.proto 3 | 4 | #ifndef PROTOBUF_INCLUDED_helloworld_2eproto 5 | #define PROTOBUF_INCLUDED_helloworld_2eproto 6 | 7 | #include 8 | 9 | #include 10 | 11 | #if GOOGLE_PROTOBUF_VERSION < 3006001 12 | #error This file was generated by a newer version of protoc which is 13 | #error incompatible with your Protocol Buffer headers. Please update 14 | #error your headers. 15 | #endif 16 | #if 3006001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 17 | #error This file was generated by an older version of protoc which is 18 | #error incompatible with your Protocol Buffer headers. Please 19 | #error regenerate this file with a newer version of protoc. 20 | #endif 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include // IWYU pragma: export 31 | #include // IWYU pragma: export 32 | #include 33 | // @@protoc_insertion_point(includes) 34 | #define PROTOBUF_INTERNAL_EXPORT_protobuf_helloworld_2eproto 35 | 36 | namespace protobuf_helloworld_2eproto { 37 | // Internal implementation detail -- do not use these members. 38 | struct TableStruct { 39 | static const ::google::protobuf::internal::ParseTableField entries[]; 40 | static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; 41 | static const ::google::protobuf::internal::ParseTable schema[2]; 42 | static const ::google::protobuf::internal::FieldMetadata field_metadata[]; 43 | static const ::google::protobuf::internal::SerializationTable serialization_table[]; 44 | static const ::google::protobuf::uint32 offsets[]; 45 | }; 46 | void AddDescriptors(); 47 | } // namespace protobuf_helloworld_2eproto 48 | namespace helloworld { 49 | class HelloReply; 50 | class HelloReplyDefaultTypeInternal; 51 | extern HelloReplyDefaultTypeInternal _HelloReply_default_instance_; 52 | class HelloRequest; 53 | class HelloRequestDefaultTypeInternal; 54 | extern HelloRequestDefaultTypeInternal _HelloRequest_default_instance_; 55 | } // namespace helloworld 56 | namespace google { 57 | namespace protobuf { 58 | template<> ::helloworld::HelloReply* Arena::CreateMaybeMessage<::helloworld::HelloReply>(Arena*); 59 | template<> ::helloworld::HelloRequest* Arena::CreateMaybeMessage<::helloworld::HelloRequest>(Arena*); 60 | } // namespace protobuf 61 | } // namespace google 62 | namespace helloworld { 63 | 64 | // =================================================================== 65 | 66 | class HelloRequest : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:helloworld.HelloRequest) */ { 67 | public: 68 | HelloRequest(); 69 | virtual ~HelloRequest(); 70 | 71 | HelloRequest(const HelloRequest& from); 72 | 73 | inline HelloRequest& operator=(const HelloRequest& from) { 74 | CopyFrom(from); 75 | return *this; 76 | } 77 | #if LANG_CXX11 78 | HelloRequest(HelloRequest&& from) noexcept 79 | : HelloRequest() { 80 | *this = ::std::move(from); 81 | } 82 | 83 | inline HelloRequest& operator=(HelloRequest&& from) noexcept { 84 | if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { 85 | if (this != &from) InternalSwap(&from); 86 | } else { 87 | CopyFrom(from); 88 | } 89 | return *this; 90 | } 91 | #endif 92 | static const ::google::protobuf::Descriptor* descriptor(); 93 | static const HelloRequest& default_instance(); 94 | 95 | static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY 96 | static inline const HelloRequest* internal_default_instance() { 97 | return reinterpret_cast( 98 | &_HelloRequest_default_instance_); 99 | } 100 | static constexpr int kIndexInFileMessages = 101 | 0; 102 | 103 | void Swap(HelloRequest* other); 104 | friend void swap(HelloRequest& a, HelloRequest& b) { 105 | a.Swap(&b); 106 | } 107 | 108 | // implements Message ---------------------------------------------- 109 | 110 | inline HelloRequest* New() const final { 111 | return CreateMaybeMessage(NULL); 112 | } 113 | 114 | HelloRequest* New(::google::protobuf::Arena* arena) const final { 115 | return CreateMaybeMessage(arena); 116 | } 117 | void CopyFrom(const ::google::protobuf::Message& from) final; 118 | void MergeFrom(const ::google::protobuf::Message& from) final; 119 | void CopyFrom(const HelloRequest& from); 120 | void MergeFrom(const HelloRequest& from); 121 | void Clear() final; 122 | bool IsInitialized() const final; 123 | 124 | size_t ByteSizeLong() const final; 125 | bool MergePartialFromCodedStream( 126 | ::google::protobuf::io::CodedInputStream* input) final; 127 | void SerializeWithCachedSizes( 128 | ::google::protobuf::io::CodedOutputStream* output) const final; 129 | ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( 130 | bool deterministic, ::google::protobuf::uint8* target) const final; 131 | int GetCachedSize() const final { return _cached_size_.Get(); } 132 | 133 | private: 134 | void SharedCtor(); 135 | void SharedDtor(); 136 | void SetCachedSize(int size) const final; 137 | void InternalSwap(HelloRequest* other); 138 | private: 139 | inline ::google::protobuf::Arena* GetArenaNoVirtual() const { 140 | return NULL; 141 | } 142 | inline void* MaybeArenaPtr() const { 143 | return NULL; 144 | } 145 | public: 146 | 147 | ::google::protobuf::Metadata GetMetadata() const final; 148 | 149 | // nested types ---------------------------------------------------- 150 | 151 | // accessors ------------------------------------------------------- 152 | 153 | // string name = 1; 154 | void clear_name(); 155 | static const int kNameFieldNumber = 1; 156 | const ::std::string& name() const; 157 | void set_name(const ::std::string& value); 158 | #if LANG_CXX11 159 | void set_name(::std::string&& value); 160 | #endif 161 | void set_name(const char* value); 162 | void set_name(const char* value, size_t size); 163 | ::std::string* mutable_name(); 164 | ::std::string* release_name(); 165 | void set_allocated_name(::std::string* name); 166 | 167 | // @@protoc_insertion_point(class_scope:helloworld.HelloRequest) 168 | private: 169 | 170 | ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; 171 | ::google::protobuf::internal::ArenaStringPtr name_; 172 | mutable ::google::protobuf::internal::CachedSize _cached_size_; 173 | friend struct ::protobuf_helloworld_2eproto::TableStruct; 174 | }; 175 | // ------------------------------------------------------------------- 176 | 177 | class HelloReply : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:helloworld.HelloReply) */ { 178 | public: 179 | HelloReply(); 180 | virtual ~HelloReply(); 181 | 182 | HelloReply(const HelloReply& from); 183 | 184 | inline HelloReply& operator=(const HelloReply& from) { 185 | CopyFrom(from); 186 | return *this; 187 | } 188 | #if LANG_CXX11 189 | HelloReply(HelloReply&& from) noexcept 190 | : HelloReply() { 191 | *this = ::std::move(from); 192 | } 193 | 194 | inline HelloReply& operator=(HelloReply&& from) noexcept { 195 | if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { 196 | if (this != &from) InternalSwap(&from); 197 | } else { 198 | CopyFrom(from); 199 | } 200 | return *this; 201 | } 202 | #endif 203 | static const ::google::protobuf::Descriptor* descriptor(); 204 | static const HelloReply& default_instance(); 205 | 206 | static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY 207 | static inline const HelloReply* internal_default_instance() { 208 | return reinterpret_cast( 209 | &_HelloReply_default_instance_); 210 | } 211 | static constexpr int kIndexInFileMessages = 212 | 1; 213 | 214 | void Swap(HelloReply* other); 215 | friend void swap(HelloReply& a, HelloReply& b) { 216 | a.Swap(&b); 217 | } 218 | 219 | // implements Message ---------------------------------------------- 220 | 221 | inline HelloReply* New() const final { 222 | return CreateMaybeMessage(NULL); 223 | } 224 | 225 | HelloReply* New(::google::protobuf::Arena* arena) const final { 226 | return CreateMaybeMessage(arena); 227 | } 228 | void CopyFrom(const ::google::protobuf::Message& from) final; 229 | void MergeFrom(const ::google::protobuf::Message& from) final; 230 | void CopyFrom(const HelloReply& from); 231 | void MergeFrom(const HelloReply& from); 232 | void Clear() final; 233 | bool IsInitialized() const final; 234 | 235 | size_t ByteSizeLong() const final; 236 | bool MergePartialFromCodedStream( 237 | ::google::protobuf::io::CodedInputStream* input) final; 238 | void SerializeWithCachedSizes( 239 | ::google::protobuf::io::CodedOutputStream* output) const final; 240 | ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( 241 | bool deterministic, ::google::protobuf::uint8* target) const final; 242 | int GetCachedSize() const final { return _cached_size_.Get(); } 243 | 244 | private: 245 | void SharedCtor(); 246 | void SharedDtor(); 247 | void SetCachedSize(int size) const final; 248 | void InternalSwap(HelloReply* other); 249 | private: 250 | inline ::google::protobuf::Arena* GetArenaNoVirtual() const { 251 | return NULL; 252 | } 253 | inline void* MaybeArenaPtr() const { 254 | return NULL; 255 | } 256 | public: 257 | 258 | ::google::protobuf::Metadata GetMetadata() const final; 259 | 260 | // nested types ---------------------------------------------------- 261 | 262 | // accessors ------------------------------------------------------- 263 | 264 | // string message = 1; 265 | void clear_message(); 266 | static const int kMessageFieldNumber = 1; 267 | const ::std::string& message() const; 268 | void set_message(const ::std::string& value); 269 | #if LANG_CXX11 270 | void set_message(::std::string&& value); 271 | #endif 272 | void set_message(const char* value); 273 | void set_message(const char* value, size_t size); 274 | ::std::string* mutable_message(); 275 | ::std::string* release_message(); 276 | void set_allocated_message(::std::string* message); 277 | 278 | // @@protoc_insertion_point(class_scope:helloworld.HelloReply) 279 | private: 280 | 281 | ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; 282 | ::google::protobuf::internal::ArenaStringPtr message_; 283 | mutable ::google::protobuf::internal::CachedSize _cached_size_; 284 | friend struct ::protobuf_helloworld_2eproto::TableStruct; 285 | }; 286 | // =================================================================== 287 | 288 | 289 | // =================================================================== 290 | 291 | #ifdef __GNUC__ 292 | #pragma GCC diagnostic push 293 | #pragma GCC diagnostic ignored "-Wstrict-aliasing" 294 | #endif // __GNUC__ 295 | // HelloRequest 296 | 297 | // string name = 1; 298 | inline void HelloRequest::clear_name() { 299 | name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 300 | } 301 | inline const ::std::string& HelloRequest::name() const { 302 | // @@protoc_insertion_point(field_get:helloworld.HelloRequest.name) 303 | return name_.GetNoArena(); 304 | } 305 | inline void HelloRequest::set_name(const ::std::string& value) { 306 | 307 | name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); 308 | // @@protoc_insertion_point(field_set:helloworld.HelloRequest.name) 309 | } 310 | #if LANG_CXX11 311 | inline void HelloRequest::set_name(::std::string&& value) { 312 | 313 | name_.SetNoArena( 314 | &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); 315 | // @@protoc_insertion_point(field_set_rvalue:helloworld.HelloRequest.name) 316 | } 317 | #endif 318 | inline void HelloRequest::set_name(const char* value) { 319 | GOOGLE_DCHECK(value != NULL); 320 | 321 | name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); 322 | // @@protoc_insertion_point(field_set_char:helloworld.HelloRequest.name) 323 | } 324 | inline void HelloRequest::set_name(const char* value, size_t size) { 325 | 326 | name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), 327 | ::std::string(reinterpret_cast(value), size)); 328 | // @@protoc_insertion_point(field_set_pointer:helloworld.HelloRequest.name) 329 | } 330 | inline ::std::string* HelloRequest::mutable_name() { 331 | 332 | // @@protoc_insertion_point(field_mutable:helloworld.HelloRequest.name) 333 | return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 334 | } 335 | inline ::std::string* HelloRequest::release_name() { 336 | // @@protoc_insertion_point(field_release:helloworld.HelloRequest.name) 337 | 338 | return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 339 | } 340 | inline void HelloRequest::set_allocated_name(::std::string* name) { 341 | if (name != NULL) { 342 | 343 | } else { 344 | 345 | } 346 | name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); 347 | // @@protoc_insertion_point(field_set_allocated:helloworld.HelloRequest.name) 348 | } 349 | 350 | // ------------------------------------------------------------------- 351 | 352 | // HelloReply 353 | 354 | // string message = 1; 355 | inline void HelloReply::clear_message() { 356 | message_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 357 | } 358 | inline const ::std::string& HelloReply::message() const { 359 | // @@protoc_insertion_point(field_get:helloworld.HelloReply.message) 360 | return message_.GetNoArena(); 361 | } 362 | inline void HelloReply::set_message(const ::std::string& value) { 363 | 364 | message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); 365 | // @@protoc_insertion_point(field_set:helloworld.HelloReply.message) 366 | } 367 | #if LANG_CXX11 368 | inline void HelloReply::set_message(::std::string&& value) { 369 | 370 | message_.SetNoArena( 371 | &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); 372 | // @@protoc_insertion_point(field_set_rvalue:helloworld.HelloReply.message) 373 | } 374 | #endif 375 | inline void HelloReply::set_message(const char* value) { 376 | GOOGLE_DCHECK(value != NULL); 377 | 378 | message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); 379 | // @@protoc_insertion_point(field_set_char:helloworld.HelloReply.message) 380 | } 381 | inline void HelloReply::set_message(const char* value, size_t size) { 382 | 383 | message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), 384 | ::std::string(reinterpret_cast(value), size)); 385 | // @@protoc_insertion_point(field_set_pointer:helloworld.HelloReply.message) 386 | } 387 | inline ::std::string* HelloReply::mutable_message() { 388 | 389 | // @@protoc_insertion_point(field_mutable:helloworld.HelloReply.message) 390 | return message_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 391 | } 392 | inline ::std::string* HelloReply::release_message() { 393 | // @@protoc_insertion_point(field_release:helloworld.HelloReply.message) 394 | 395 | return message_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 396 | } 397 | inline void HelloReply::set_allocated_message(::std::string* message) { 398 | if (message != NULL) { 399 | 400 | } else { 401 | 402 | } 403 | message_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), message); 404 | // @@protoc_insertion_point(field_set_allocated:helloworld.HelloReply.message) 405 | } 406 | 407 | #ifdef __GNUC__ 408 | #pragma GCC diagnostic pop 409 | #endif // __GNUC__ 410 | // ------------------------------------------------------------------- 411 | 412 | 413 | // @@protoc_insertion_point(namespace_scope) 414 | 415 | } // namespace helloworld 416 | 417 | // @@protoc_insertion_point(global_scope) 418 | 419 | #endif // PROTOBUF_INCLUDED_helloworld_2eproto 420 | -------------------------------------------------------------------------------- /demo-async-client/helloworld.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2015 gRPC authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | option java_multiple_files = true; 18 | option java_package = "io.grpc.examples.helloworld"; 19 | option java_outer_classname = "HelloWorldProto"; 20 | option objc_class_prefix = "HLW"; 21 | 22 | package helloworld; 23 | 24 | // The greeting service definition. 25 | service Greeter { 26 | // Sends a greeting 27 | rpc SayHello (HelloRequest) returns (HelloReply) {} 28 | } 29 | 30 | // The request message containing the user's name. 31 | message HelloRequest { 32 | string name = 1; 33 | } 34 | 35 | // The response message containing the greetings 36 | message HelloReply { 37 | string message = 1; 38 | } 39 | -------------------------------------------------------------------------------- /demo-async-server/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # CMake 最低版本号要求 2 | cmake_minimum_required (VERSION 2.8) 3 | 4 | # 项目信息 5 | project (demo-async-server CXX) 6 | 7 | # 版本信息 8 | set (Demo_VERSION_MAJOR 1) 9 | set (Demo_VERSION_MINOR 0) 10 | 11 | 12 | # 编译参数 13 | set (CMAKE_BUILE_TYPE RELEASE) 14 | add_definitions(-DRELEASE) 15 | 16 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC -pthread") 17 | 18 | 19 | # 查找当前目录下的所有源文件 20 | # 并将名称保存到 DIR_LIB_SRCS 变量 21 | aux_source_directory(. DIR_LIB_SRCS) 22 | #aux_source_directory(model DIR_LIB_SRCS) 23 | 24 | set (EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}) 25 | #设置proto工具目录 26 | get_filename_component(proto_tool "${PROJECT_SOURCE_DIR}/../../libs/protobuf" ABSOLUTE) 27 | #生成PB 28 | execute_process(COMMAND ${proto_tool}/protoc -I ${PROJECT_SOURCE_DIR} --cpp_out=${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/helloworld.proto) 29 | execute_process(COMMAND ${proto_tool}/protoc -I ${PROJECT_SOURCE_DIR} --grpc_out=${PROJECT_SOURCE_DIR} 30 | --plugin=protoc-gen-grpc=${proto_tool}/grpc_cpp_plugin ${PROJECT_SOURCE_DIR}/helloworld.proto) 31 | 32 | # 链接库目录 33 | link_directories ("${PROJECT_SOURCE_DIR}/../../libs/opt" 34 | "${PROJECT_SOURCE_DIR}/../../libs/lib" 35 | "${PROJECT_SOURCE_DIR}/../../libs/protobuf" 36 | "${PROJECT_SOURCE_DIR}/../../libs/zookeeper") 37 | 38 | # 添加包含目录 39 | include_directories("${PROJECT_SOURCE_DIR}" 40 | "${PROJECT_SOURCE_DIR}/../../include/orientsec_grpc" 41 | "${PROJECT_SOURCE_DIR}/../../include/include" 42 | "${PROJECT_SOURCE_DIR}/../../include/third_party/protobuf/src/" 43 | "${PROJECT_SOURCE_DIR}/../../include/third_party/protobuf" 44 | "${PROJECT_SOURCE_DIR}/model") 45 | 46 | 47 | # 生成链接库 48 | add_executable (demo-async-server ${DIR_LIB_SRCS}) 49 | 50 | # 添加链接库 51 | target_link_libraries(demo-async-server libgpr.so) 52 | target_link_libraries(demo-async-server libgrpc.so) 53 | target_link_libraries(demo-async-server libgrpc++.so) 54 | target_link_libraries(demo-async-server libprotobuf.a) 55 | target_link_libraries(demo-async-server libssl.so) 56 | target_link_libraries(demo-async-server liborientsec_common.a) 57 | target_link_libraries(demo-async-server liborientsec_provider.a) 58 | target_link_libraries(demo-async-server liborientsec_consumer.a) 59 | target_link_libraries(demo-async-server liborientsec_registry.a) 60 | target_link_libraries(demo-async-server libzookeeper_mt.so) 61 | 62 | -------------------------------------------------------------------------------- /demo-async-server/config/dfzq-grpc-config.properties: -------------------------------------------------------------------------------- 1 | # 配置信息分为五类: 2 | # 1. common config (公共配置) 3 | # 2. provider config (服务提供者需要填写) 4 | # 3. consumer config (服务消费者需要填写) 5 | # 4. kafka config (提供者、消费者都需要配置) 6 | # 5. zookeeper config (提供者、消费者都需要配置) 7 | 8 | # 配置文件的放置路径:class文件根目录 9 | # (请参照:使用log4j记日志的项目中 log4j.properties 文件的路径) 10 | 11 | 12 | # ------------ begin of common config ------------ 13 | 14 | # 必填,类型string,说明:当前应用名称 15 | common.application=grpc-test-app 16 | 17 | # 必填,类型string,说明:grpc版本号 18 | common.grpc=1.2.4 19 | 20 | #选填,默认是 grpc-test-app,说明:grpc项目名监控 21 | common.project=grpc-java 22 | 23 | # 选填,类型string,说明:服务注册根路径,默认值/Application/grpc 24 | #common.root=/Application/grpc/c++ 25 | 26 | # 必填,类型string,说明:项目负责人,员工工号,多个工号之间使用英文逗号 27 | common.owner=A9001,A9002,A9003 28 | 29 | # 可选,类型string,说明:服务注册使用的IP地址 30 | # 如果不配置该参数值,当前服务器的IP地址为"非127.0.0.1的第一个网卡的IP地址" 31 | # 使用场合:一台服务器安装有多个网卡,如果需要指定不是第一个网卡的IP地址为服务注册的IP地址 32 | #common.localhost.ip=192.168.2.123 33 | 34 | # ------------ end of common config ------------ 35 | 36 | 37 | 38 | 39 | # ------------ begin of provider config ------------ 40 | 41 | # 必填,类型string,说明:服务的版本信息,一般表示服务接口的版本号 42 | provider.version=2.0 43 | 44 | # 必填,类型String,固定值provider,说明:provider表示服务提供端,consumer表示服务消费端 45 | provider.side=provider 46 | 47 | # ---------------------------------------- 48 | 49 | # 可选,类型string,说明:当前模块名称 50 | # provider.module= 51 | 52 | # 可选,类型string,说明:服务分组信息,一般用来区分一个服务接口的多种实现(provider) 53 | # provider.group= 54 | 55 | # 可选,类型int,缺省值1000,说明:远程服务调用超时时间(毫秒) 56 | # provider.default.timeout= 57 | 58 | # 可选,类型int,缺省值2,说明:远程服务调用重试次数,不包括第一次调用,不需要重试则设置为0 59 | # provider.default.reties= 60 | 61 | # 可选,类型int,缺省值0,说明:对每个provider最大连接次数,默认最大连接数 62 | #provider.default.connections=1 63 | 64 | # 可选,类型string,缺省值round_robin,说明:负载均衡策略,可选值:pick_first、round_robin,weight_round_robin,可扩展实现其他策略 65 | # provider.default.loadbalance= 66 | 67 | # 可选,类型Boolean,缺省值false,说明:是否缺省异步执行,如果true则可直接忽略返回值,不阻塞线程 68 | # provider.default.async= 69 | #Max request 70 | #provider.default.requests=1 71 | # dataflow control 72 | #provider.default.connections=1 73 | 74 | #route rule 75 | #provider.access.protected=true 76 | 77 | 78 | # 可选,类型sting/Boolean,缺省值false,说明:令牌验证,为空表示不开启,为true则随机生成动态令牌,否则使用镜头令牌 79 | # provider.token= 80 | 81 | # 可选,类型boolean,缺省值false,说明:服务是否过时,如果为true则应用该服务时日志error告警 82 | # provider.deprecated=true 83 | 84 | # 可选,类型boolean,缺省值ture,说明:服务是否动态注册,如果为false则注册后将显示为disable状态, 85 | # 需要人工启用,且服务停止时需手动注销 86 | # provider.dynamic= 87 | 88 | # 可选,类型string/boolean,缺省值false,说明:设为true,将向logger中输出访问日志,也可填写访问 89 | # 日志文件路径,直接把访问日志输出到指定文件 90 | # provider.accesslog= 91 | 92 | # 可选,类型string,说明:服务负责人,填写负责人公司邮箱前缀 93 | # provider.owner= 94 | 95 | # 可选,类型int,缺省值100,说明:服务provider权重,是服务provider的容量,在负载均衡基于权重的选择算法中用到 96 | # provider.weight= 97 | 98 | # 可选,类型string,缺省值failover,说明:集群方式,可选:failover/failfast/failback/forking 99 | # provider.default.cluster= 100 | 101 | # 可选,类型string,说明:应用版本号 102 | # provider.application.version= 103 | 104 | # 可选,类型string,说明:组织名(BU或部门) 105 | # provider.organization= 106 | 107 | # 可选,类型string,说明:应用环境,如:develop/test/product 108 | # provider.environment= 109 | 110 | # 可选,类型string,说明:模块的版本号 111 | # provider.module.version= 112 | 113 | # 可选,类型boolean,缺省值false,说明:表示是否为跨主机访问 114 | # provider.anyhost= 115 | 116 | # 可选,类型string,说明:dubbo版本号,缺省值为grpc的版本号 117 | # provider.dubbo= 118 | 119 | # 可选, 类型boolean, 缺省值false, 说明:服务是否处于访问保护状态 120 | # 属性的可选值为false 、true ,分别表示不受保护、受保护,缺省值为false (不受保护) 121 | #provider.access.protected=true 122 | 123 | # ------------ end of provider config ------------ 124 | 125 | 126 | 127 | 128 | # ------------ begin of consumer config ------------ 129 | 130 | # 必填,类型boolean,缺省值true,说明:启动时检查提供者是否存在,true报错,false忽略 131 | consumer.check=true 132 | 133 | # 必填,类型int,固定值1000,说明:远程服务调用超时时间(毫秒) 134 | consumer.default.timeout=1000 135 | 136 | # 必填,类型String,默认值consumers,说明:所属范畴 137 | consumer.category=consumers 138 | 139 | # 必填,类型String,固定值consumer,说明:provider表示服务提供端,consumer表示服务消费端 140 | consumer.side=consumer 141 | 142 | # -------------------------- 143 | # 可选,类型string,说明:服务提供者的版本号 144 | # 指定了服务提供者的版本号之后,程序会优先选择具有指定版本的服务;如果注册中心没有该版本的服务,则不限制版本重新选择服务提供者。 145 | # 使用场景为:注册中心上同一个服务多版本共存,并且服务的高版本与低版本不兼容,而当前应用由于特殊原因只能调用低版本的服务 146 | # 如果当前应用只调用一个服务,属性值直接配置版本号,例如1.0.0 147 | # 如果当前应用需要调用多个服务,属性值按照冒号逗号的方式分隔,例如com.dfzq.examples.Greeter:1.0.0,com.dfzq.examples.Hello:1.2.1 148 | # 如果当前应用需要调用多个服务,建议在服务治理平台维护该属性,只有一个版本的服务可以不维护 149 | #consumer.service.version=helloworld.Greeter:1.0,com.dfzq.grpc.helloworld.Greeter:1.0.2 150 | 151 | # 可选,类型string,说明:应用版本号 152 | # consumer.application.version= 153 | 154 | # 可选,类型String,说明:服务消费方远程调用过程拦截器名称,多个名称用逗号分隔 155 | # consumer.default.reference.filter= 156 | 157 | # 可选,类型String,缺省值slf4j,说明:日志输出方式,可选:slf4j,jcl,log4j,jdk 158 | # consumer.logger= 159 | 160 | # 可选,类型String,说明:调用服务负责人,用于服务治理,请填写负责人公司邮箱前缀 161 | # consumer.owner= 162 | 163 | # 可选,类型string,说明:组织名(BU或部门) 164 | # consumer.organization= 165 | 166 | # 可选,类型int,缺省值2,说明:远程服务调用重试次数 167 | # consumer.default.retries= 168 | 169 | # 可选,类型string,缺省值connection,说明:负载均衡模式 170 | # 可选值为 connection 和 request,分别表示“连接负载均衡”、“请求负载均衡” 171 | # “连接负载均衡”适用于大部分业务场景,服务端和客户端消耗的资源较小。 172 | # “请求负载均衡”适用于服务端业务逻辑复杂、并有多台服务器提供相同服务的场景。 173 | consumer.loadbalance.mode=request 174 | #consumer.loadbalance.mode=connection 175 | 176 | 177 | # 可选,类型string,缺省值round_robin,说明:调度策略,可选范围:pick_first、round_robin、weight_round_robin、consistent_hash 178 | consumer.default.loadbalance=consistent_hash 179 | 180 | #the weight of provider 181 | provider.weight=1 182 | 183 | 184 | # 可选,类型string,负载均衡策略选择是consistent_hash(一致性Hash),配置进行hash运算的参数名称的列表 185 | # 多个参数之间使用英文逗号分隔,例如 id,name 186 | # 如果负载均衡策略选择是consistent_hash,但是该参数未配置参数值、或者参数值列表不正确,则随机取一个值来做散列运算 187 | 188 | consumer.consistent.hash.arguments=name,no 189 | 190 | # 可选,类型int,缺省值100,说明:每个服务对外最大连接数 191 | # consumer.default.connections= 192 | 193 | # 可选,类型string,缺省值failover,说明:集群方式,可选:failover/failfast/failback/forking 194 | # consumer.default.cluster= 195 | 196 | # 可选,类型integer,缺省值5,说明:连续多少次请求出错,自动切换到提供相同服务的新服务器 197 | consumer.switchover.threshold=5 198 | 199 | # 可选,类型为long,单位为秒,缺省值为60,说明:服务提供者不可用时的惩罚时间,即多次请求出错的服务提供者一段时间内不再去请求 200 | # 属性值大于或等于0,等于0表示没有惩罚时间,如果客户端只剩下一个服务提供者,即使服务提供者不可用,也不做剔除操作。 201 | consumer.unavailable.provider.punish.time=60 202 | # ------------ end of consumer config ------------ 203 | 204 | 205 | 206 | 207 | # ------------ begin of kafka.producer config ------------ 208 | 209 | # 转发服务跟踪信息给kafka的服务提供者的IP地址和端口 210 | # 服务跟踪信息先发送给KafkaSenderServer(一个基于原生grpc的服务),然后由KafkaSenderServer转发给kafka 211 | # 多个服务提供者之间使用英文逗号分隔,IP地址和端口使用英文冒号分隔 212 | # kafka.sender.servers=192.168.0.1:50080,192.168.0.2:50080,192.168.0.3:50080 213 | #kafka.sender.servers=127.0.0.1:50080 214 | #kafka.sender.servers=127.0.0.1:9093 215 | #kafka.sender.servers=160.6.78.133:50080 216 | 217 | # 可选,采样频率,指的是每秒采集服务链的数据条数(这里的一条理解为traceId相同的多个json串); 218 | # 默认值为空,表示所有服务链都发送到kafka; 219 | # 如果采样率的数值不为空,并且数值大于0,根据指定的采样率采集数据 220 | # 配置值可以为正整数、小数(例如0.5)、分数(例如3/1024) 221 | # kafka.sampling.frequency= 222 | 223 | # 可选, 将服务跟踪信息发送给KafkaSenderServer的线程个数 224 | # 配置值为正整数,默认值为1 225 | # kafka.sender.number=1 226 | 227 | # 可选, 服务跟踪信息消息队列的容量 228 | # 配置值为正整数,默认值为50000 229 | # message.queue.capacity=50000 230 | # -------------------------- 231 | 232 | # 可选,每个RecordBatch可以缓存的最大字节数 233 | # kafka.producer.batch.size=16384 234 | 235 | # 可选,所有RecordBatch的总共最大字节数 236 | # kafka.producer.buffer.memory=33554432 237 | 238 | # 可选,每个RecordBatch的最长延迟发送时间 239 | # kafka.producer.linger.ms=1 240 | 241 | # 可选,每个RecordBatch的最长阻塞时间 242 | # kafka.producer.max.block.ms=1 243 | 244 | # 可选,消息发送失败重试的次数 245 | # kafka.producer.retries=0 246 | 247 | # 可选,失败补偿时间,每次失败重试的时间间隔,不可设置太短,避免第一条消息的响应还没返回,第二条消息又发出去了,造成逻辑错误 248 | # kafka.producer.retry.backoff.ms 249 | 250 | # 可选,同一时间,producer到broker的一个连接上允许的最大未确认请求数,默认为5 251 | # kafka.producer.max.in.flight.requests.per.connection=5 252 | 253 | # 可选,采样频率,指的是每秒向kafka写服务链的数据条数(这里的一条理解为traceId相同的多个json串); 254 | # 默认值为空,表示所有服务链都发送到kafka; 255 | # 如果采样率的数值不为空,并且数值大于0,根据指定的采样率采集数据 256 | # 配置值可以为正整数、小数(例如0.5)、分数(例如3/1024) 257 | #kafka.sampling.frequency=0.5 258 | 259 | # ------------ end of kafka.producer config ------------ 260 | 261 | 262 | 263 | 264 | # ------------ begin of zookeeper config ------------ 265 | 266 | # zookeeper主机列表 267 | #zookeeper.host.server=192.168.207.4:2181,192.168.207.6:2181 268 | zookeeper.host.server=192.168.2.103:2181 269 | #zookeeper.host.server=160.6.78.133:2181 270 | 271 | #重试次数 272 | zookeeper.retryNum=5 273 | 274 | #连接超时时间 275 | zookeeper.connectiontimeout=5000 276 | 277 | 278 | # 可选,类型string,访问控制用户名 279 | zookeeper.acl.username=admin 280 | 281 | # 可选,类型string,访问控制密码 282 | # 这里的密码配置的是密文,使用com.orientsec.grpc.common.util.DesEncryptUtils#encrypt(String plaintext)进行加密 283 | #zookeeper.acl.password=9b579c35ca6cc74230f1eed29064d10a 284 | zookeeper.acl.password=9883c580ae8226f0dd8200620e4bc899 285 | 286 | 287 | 288 | # ------------ end of zookeeper config ------------ 289 | 290 | 291 | writekafka.enabled=false 292 | #kafka.sender.servers=127.0.0.1:50080,192.168.226.128:50080 293 | 294 | kafka.sender.servers=127.0.0.1:50080 295 | -------------------------------------------------------------------------------- /demo-async-server/demo-async-server.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Orient Securities Co., Ltd. 3 | * Copyright 2019 BoCloud Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | #include "helloworld.grpc.pb.h" 27 | 28 | using grpc::Server; 29 | using grpc::ServerAsyncResponseWriter; 30 | using grpc::ServerBuilder; 31 | using grpc::ServerContext; 32 | using grpc::ServerCompletionQueue; 33 | using grpc::Status; 34 | using helloworld::HelloRequest; 35 | using helloworld::HelloReply; 36 | using helloworld::Greeter; 37 | 38 | class ServerImpl final { 39 | public: 40 | ServerImpl(){ 41 | addr = "0.0.0.0:50055"; 42 | 43 | } 44 | ServerImpl(std::string point):addr(point){} 45 | ~ServerImpl() { 46 | server_->Shutdown(); 47 | // Always shutdown the completion queue after the server. 48 | cq_->Shutdown(); 49 | } 50 | 51 | // There is no shutdown handling in this code. 52 | void Run() { 53 | // std::string server_address("0.0.0.0:50055"); 54 | 55 | ServerBuilder builder; 56 | // Listen on the given address without any authentication mechanism. 57 | //builder.AddListeningPort(server_address, grpc::InsecureServerCredentials()); 58 | builder.AddListeningPort(addr, grpc::InsecureServerCredentials()); 59 | // Register "service_" as the instance through which we'll communicate with 60 | // clients. In this case it corresponds to an *asynchronous* service. 61 | builder.RegisterService(&service_); 62 | // Get hold of the completion queue used for the asynchronous communication 63 | // with the gRPC runtime. 64 | cq_ = builder.AddCompletionQueue(); 65 | // Finally assemble the server. 66 | server_ = builder.BuildAndStart(); 67 | std::cout << "Server listening on " << addr << std::endl; 68 | 69 | // Proceed to the server's main loop. 70 | HandleRpcs(); 71 | } 72 | 73 | private: 74 | // Class encompasing the state and logic needed to serve a request. 75 | class CallData { 76 | public: 77 | // Take in the "service" instance (in this case representing an asynchronous 78 | // server) and the completion queue "cq" used for asynchronous communication 79 | // with the gRPC runtime. 80 | CallData(Greeter::AsyncService* service, ServerCompletionQueue* cq) 81 | : service_(service), cq_(cq), responder_(&ctx_), status_(CREATE) { 82 | // Invoke the serving logic right away. 83 | Proceed(); 84 | } 85 | 86 | void Proceed() { 87 | if (status_ == CREATE) { 88 | // Make this instance progress to the PROCESS state. 89 | status_ = PROCESS; 90 | 91 | // As part of the initial CREATE state, we *request* that the system 92 | // start processing SayHello requests. In this request, "this" acts are 93 | // the tag uniquely identifying the request (so that different CallData 94 | // instances can serve different requests concurrently), in this case 95 | // the memory address of this CallData instance. 96 | service_->RequestSayHello(&ctx_, &request_, &responder_, cq_, cq_, 97 | this); 98 | } 99 | else if (status_ == PROCESS) { 100 | // Spawn a new CallData instance to serve new clients while we process 101 | // the one for this CallData. The instance will deallocate itself as 102 | // part of its FINISH state. 103 | new CallData(service_, cq_); 104 | 105 | // The actual processing. 106 | std::string prefix("Hello "); 107 | reply_.set_message(prefix + request_.name()); 108 | std::cout << "\n Service is Called ... " << request_.name() << "\n" << std::endl; 109 | 110 | // And we are done! Let the gRPC runtime know we've finished, using the 111 | // memory address of this instance as the uniquely identifying tag for 112 | // the event. 113 | status_ = FINISH; 114 | responder_.Finish(reply_, Status::OK, this); 115 | } 116 | else { 117 | GPR_ASSERT(status_ == FINISH); 118 | // Once in the FINISH state, deallocate ourselves (CallData). 119 | delete this; 120 | } 121 | } 122 | 123 | private: 124 | // The means of communication with the gRPC runtime for an asynchronous 125 | // server. 126 | Greeter::AsyncService* service_; 127 | // The producer-consumer queue where for asynchronous server notifications. 128 | ServerCompletionQueue* cq_; 129 | // Context for the rpc, allowing to tweak aspects of it such as the use 130 | // of compression, authentication, as well as to send metadata back to the 131 | // client. 132 | ServerContext ctx_; 133 | 134 | // What we get from the client. 135 | HelloRequest request_; 136 | // What we send back to the client. 137 | HelloReply reply_; 138 | 139 | // The means to get back to the client. 140 | ServerAsyncResponseWriter responder_; 141 | 142 | // Let's implement a tiny state machine with the following states. 143 | enum CallStatus { CREATE, PROCESS, FINISH }; 144 | CallStatus status_; // The current serving state. 145 | }; 146 | 147 | // This can be run in multiple threads if needed. 148 | void HandleRpcs() { 149 | // Spawn a new CallData instance to serve new clients. 150 | new CallData(&service_, cq_.get()); 151 | void* tag; // uniquely identifies a request. 152 | bool ok; 153 | while (true) { 154 | // Block waiting to read the next event from the completion queue. The 155 | // event is uniquely identified by its tag, which in this case is the 156 | // memory address of a CallData instance. 157 | // The return value of Next should always be checked. This return value 158 | // tells us whether there is any kind of event or cq_ is shutting down. 159 | GPR_ASSERT(cq_->Next(&tag, &ok)); 160 | GPR_ASSERT(ok); 161 | static_cast(tag)->Proceed(); 162 | } 163 | } 164 | 165 | std::unique_ptr cq_; 166 | Greeter::AsyncService service_; 167 | std::unique_ptr server_; 168 | std::string addr; 169 | }; 170 | 171 | int main(int argc, char** argv) { 172 | if(argc >2 && atoi(argv[2]) >0 ){ 173 | std::string address =std::string(argv[1]) + std::string(":") + argv[2]; 174 | ServerImpl server(address); 175 | server.Run(); 176 | }else{ 177 | ServerImpl server; 178 | server.Run(); 179 | } 180 | 181 | 182 | return 0; 183 | } 184 | -------------------------------------------------------------------------------- /demo-async-server/helloworld.grpc.pb.cc: -------------------------------------------------------------------------------- 1 | // Generated by the gRPC C++ plugin. 2 | // If you make any local change, they will be lost. 3 | // source: helloworld.proto 4 | 5 | #include "helloworld.pb.h" 6 | #include "helloworld.grpc.pb.h" 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | namespace helloworld { 20 | 21 | static const char* Greeter_method_names[] = { 22 | "/helloworld.Greeter/SayHello", 23 | }; 24 | 25 | std::unique_ptr< Greeter::Stub> Greeter::NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options) { 26 | (void)options; 27 | std::unique_ptr< Greeter::Stub> stub(new Greeter::Stub(channel)); 28 | return stub; 29 | } 30 | 31 | Greeter::Stub::Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel) 32 | : channel_(channel), rpcmethod_SayHello_(Greeter_method_names[0], ::grpc::internal::RpcMethod::NORMAL_RPC, channel) 33 | {} 34 | 35 | ::grpc::Status Greeter::Stub::SayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::helloworld::HelloReply* response) { 36 | return ::grpc::internal::BlockingUnaryCall(channel_.get(), rpcmethod_SayHello_, context, request, response); 37 | } 38 | 39 | void Greeter::Stub::experimental_async::SayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response, std::function f) { 40 | return ::grpc::internal::CallbackUnaryCall(stub_->channel_.get(), stub_->rpcmethod_SayHello_, context, request, response, std::move(f)); 41 | } 42 | 43 | ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>* Greeter::Stub::AsyncSayHelloRaw(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) { 44 | return ::grpc::internal::ClientAsyncResponseReaderFactory< ::helloworld::HelloReply>::Create(channel_.get(), cq, rpcmethod_SayHello_, context, request, true); 45 | } 46 | 47 | ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>* Greeter::Stub::PrepareAsyncSayHelloRaw(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) { 48 | return ::grpc::internal::ClientAsyncResponseReaderFactory< ::helloworld::HelloReply>::Create(channel_.get(), cq, rpcmethod_SayHello_, context, request, false); 49 | } 50 | 51 | Greeter::Service::Service() { 52 | AddMethod(new ::grpc::internal::RpcServiceMethod( 53 | Greeter_method_names[0], 54 | ::grpc::internal::RpcMethod::NORMAL_RPC, 55 | new ::grpc::internal::RpcMethodHandler< Greeter::Service, ::helloworld::HelloRequest, ::helloworld::HelloReply>( 56 | std::mem_fn(&Greeter::Service::SayHello), this))); 57 | } 58 | 59 | Greeter::Service::~Service() { 60 | } 61 | 62 | ::grpc::Status Greeter::Service::SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response) { 63 | (void) context; 64 | (void) request; 65 | (void) response; 66 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 67 | } 68 | 69 | 70 | } // namespace helloworld 71 | 72 | -------------------------------------------------------------------------------- /demo-async-server/helloworld.grpc.pb.h: -------------------------------------------------------------------------------- 1 | // Generated by the gRPC C++ plugin. 2 | // If you make any local change, they will be lost. 3 | // source: helloworld.proto 4 | // Original file comments: 5 | // Copyright 2015 gRPC authors. 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | #ifndef GRPC_helloworld_2eproto__INCLUDED 20 | #define GRPC_helloworld_2eproto__INCLUDED 21 | 22 | #include "helloworld.pb.h" 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | namespace grpc { 38 | class CompletionQueue; 39 | class Channel; 40 | class ServerCompletionQueue; 41 | class ServerContext; 42 | } // namespace grpc 43 | 44 | namespace helloworld { 45 | 46 | // The greeting service definition. 47 | class Greeter final { 48 | public: 49 | static constexpr char const* service_full_name() { 50 | return "helloworld.Greeter"; 51 | } 52 | class StubInterface { 53 | public: 54 | virtual ~StubInterface() {} 55 | // Sends a greeting 56 | virtual ::grpc::Status SayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::helloworld::HelloReply* response) = 0; 57 | std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::helloworld::HelloReply>> AsyncSayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) { 58 | return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::helloworld::HelloReply>>(AsyncSayHelloRaw(context, request, cq)); 59 | } 60 | std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::helloworld::HelloReply>> PrepareAsyncSayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) { 61 | return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::helloworld::HelloReply>>(PrepareAsyncSayHelloRaw(context, request, cq)); 62 | } 63 | class experimental_async_interface { 64 | public: 65 | virtual ~experimental_async_interface() {} 66 | // Sends a greeting 67 | virtual void SayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response, std::function) = 0; 68 | }; 69 | virtual class experimental_async_interface* experimental_async() { return nullptr; } 70 | private: 71 | virtual ::grpc::ClientAsyncResponseReaderInterface< ::helloworld::HelloReply>* AsyncSayHelloRaw(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) = 0; 72 | virtual ::grpc::ClientAsyncResponseReaderInterface< ::helloworld::HelloReply>* PrepareAsyncSayHelloRaw(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) = 0; 73 | }; 74 | class Stub final : public StubInterface { 75 | public: 76 | Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel); 77 | ::grpc::Status SayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::helloworld::HelloReply* response) override; 78 | std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>> AsyncSayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) { 79 | return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>>(AsyncSayHelloRaw(context, request, cq)); 80 | } 81 | std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>> PrepareAsyncSayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) { 82 | return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>>(PrepareAsyncSayHelloRaw(context, request, cq)); 83 | } 84 | class experimental_async final : 85 | public StubInterface::experimental_async_interface { 86 | public: 87 | void SayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response, std::function) override; 88 | private: 89 | friend class Stub; 90 | explicit experimental_async(Stub* stub): stub_(stub) { } 91 | Stub* stub() { return stub_; } 92 | Stub* stub_; 93 | }; 94 | class experimental_async_interface* experimental_async() override { return &async_stub_; } 95 | 96 | private: 97 | std::shared_ptr< ::grpc::ChannelInterface> channel_; 98 | class experimental_async async_stub_{this}; 99 | ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>* AsyncSayHelloRaw(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) override; 100 | ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>* PrepareAsyncSayHelloRaw(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) override; 101 | const ::grpc::internal::RpcMethod rpcmethod_SayHello_; 102 | }; 103 | static std::unique_ptr NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options = ::grpc::StubOptions()); 104 | 105 | class Service : public ::grpc::Service { 106 | public: 107 | Service(); 108 | virtual ~Service(); 109 | // Sends a greeting 110 | virtual ::grpc::Status SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response); 111 | }; 112 | template 113 | class WithAsyncMethod_SayHello : public BaseClass { 114 | private: 115 | void BaseClassMustBeDerivedFromService(const Service *service) {} 116 | public: 117 | WithAsyncMethod_SayHello() { 118 | ::grpc::Service::MarkMethodAsync(0); 119 | } 120 | ~WithAsyncMethod_SayHello() override { 121 | BaseClassMustBeDerivedFromService(this); 122 | } 123 | // disable synchronous version of this method 124 | ::grpc::Status SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response) override { 125 | abort(); 126 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 127 | } 128 | void RequestSayHello(::grpc::ServerContext* context, ::helloworld::HelloRequest* request, ::grpc::ServerAsyncResponseWriter< ::helloworld::HelloReply>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { 129 | ::grpc::Service::RequestAsyncUnary(0, context, request, response, new_call_cq, notification_cq, tag); 130 | } 131 | }; 132 | typedef WithAsyncMethod_SayHello AsyncService; 133 | template 134 | class ExperimentalWithCallbackMethod_SayHello : public BaseClass { 135 | private: 136 | void BaseClassMustBeDerivedFromService(const Service *service) {} 137 | public: 138 | ExperimentalWithCallbackMethod_SayHello() { 139 | ::grpc::Service::experimental().MarkMethodCallback(0, 140 | new ::grpc::internal::CallbackUnaryHandler< ExperimentalWithCallbackMethod_SayHello, ::helloworld::HelloRequest, ::helloworld::HelloReply>( 141 | [this](::grpc::ServerContext* context, 142 | const ::helloworld::HelloRequest* request, 143 | ::helloworld::HelloReply* response, 144 | ::grpc::experimental::ServerCallbackRpcController* controller) { 145 | this->SayHello(context, request, response, controller); 146 | }, this)); 147 | } 148 | ~ExperimentalWithCallbackMethod_SayHello() override { 149 | BaseClassMustBeDerivedFromService(this); 150 | } 151 | // disable synchronous version of this method 152 | ::grpc::Status SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response) override { 153 | abort(); 154 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 155 | } 156 | virtual void SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response, ::grpc::experimental::ServerCallbackRpcController* controller) { controller->Finish(::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "")); } 157 | }; 158 | typedef ExperimentalWithCallbackMethod_SayHello ExperimentalCallbackService; 159 | template 160 | class WithGenericMethod_SayHello : public BaseClass { 161 | private: 162 | void BaseClassMustBeDerivedFromService(const Service *service) {} 163 | public: 164 | WithGenericMethod_SayHello() { 165 | ::grpc::Service::MarkMethodGeneric(0); 166 | } 167 | ~WithGenericMethod_SayHello() override { 168 | BaseClassMustBeDerivedFromService(this); 169 | } 170 | // disable synchronous version of this method 171 | ::grpc::Status SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response) override { 172 | abort(); 173 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 174 | } 175 | }; 176 | template 177 | class WithRawMethod_SayHello : public BaseClass { 178 | private: 179 | void BaseClassMustBeDerivedFromService(const Service *service) {} 180 | public: 181 | WithRawMethod_SayHello() { 182 | ::grpc::Service::MarkMethodRaw(0); 183 | } 184 | ~WithRawMethod_SayHello() override { 185 | BaseClassMustBeDerivedFromService(this); 186 | } 187 | // disable synchronous version of this method 188 | ::grpc::Status SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response) override { 189 | abort(); 190 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 191 | } 192 | void RequestSayHello(::grpc::ServerContext* context, ::grpc::ByteBuffer* request, ::grpc::ServerAsyncResponseWriter< ::grpc::ByteBuffer>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { 193 | ::grpc::Service::RequestAsyncUnary(0, context, request, response, new_call_cq, notification_cq, tag); 194 | } 195 | }; 196 | template 197 | class ExperimentalWithRawCallbackMethod_SayHello : public BaseClass { 198 | private: 199 | void BaseClassMustBeDerivedFromService(const Service *service) {} 200 | public: 201 | ExperimentalWithRawCallbackMethod_SayHello() { 202 | ::grpc::Service::experimental().MarkMethodRawCallback(0, 203 | new ::grpc::internal::CallbackUnaryHandler< ExperimentalWithRawCallbackMethod_SayHello, ::grpc::ByteBuffer, ::grpc::ByteBuffer>( 204 | [this](::grpc::ServerContext* context, 205 | const ::grpc::ByteBuffer* request, 206 | ::grpc::ByteBuffer* response, 207 | ::grpc::experimental::ServerCallbackRpcController* controller) { 208 | this->SayHello(context, request, response, controller); 209 | }, this)); 210 | } 211 | ~ExperimentalWithRawCallbackMethod_SayHello() override { 212 | BaseClassMustBeDerivedFromService(this); 213 | } 214 | // disable synchronous version of this method 215 | ::grpc::Status SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response) override { 216 | abort(); 217 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 218 | } 219 | virtual void SayHello(::grpc::ServerContext* context, const ::grpc::ByteBuffer* request, ::grpc::ByteBuffer* response, ::grpc::experimental::ServerCallbackRpcController* controller) { controller->Finish(::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "")); } 220 | }; 221 | template 222 | class WithStreamedUnaryMethod_SayHello : public BaseClass { 223 | private: 224 | void BaseClassMustBeDerivedFromService(const Service *service) {} 225 | public: 226 | WithStreamedUnaryMethod_SayHello() { 227 | ::grpc::Service::MarkMethodStreamed(0, 228 | new ::grpc::internal::StreamedUnaryHandler< ::helloworld::HelloRequest, ::helloworld::HelloReply>(std::bind(&WithStreamedUnaryMethod_SayHello::StreamedSayHello, this, std::placeholders::_1, std::placeholders::_2))); 229 | } 230 | ~WithStreamedUnaryMethod_SayHello() override { 231 | BaseClassMustBeDerivedFromService(this); 232 | } 233 | // disable regular version of this method 234 | ::grpc::Status SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response) override { 235 | abort(); 236 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 237 | } 238 | // replace default version of method with streamed unary 239 | virtual ::grpc::Status StreamedSayHello(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer< ::helloworld::HelloRequest,::helloworld::HelloReply>* server_unary_streamer) = 0; 240 | }; 241 | typedef WithStreamedUnaryMethod_SayHello StreamedUnaryService; 242 | typedef Service SplitStreamedService; 243 | typedef WithStreamedUnaryMethod_SayHello StreamedService; 244 | }; 245 | 246 | } // namespace helloworld 247 | 248 | 249 | #endif // GRPC_helloworld_2eproto__INCLUDED 250 | -------------------------------------------------------------------------------- /demo-async-server/helloworld.pb.h: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: helloworld.proto 3 | 4 | #ifndef PROTOBUF_INCLUDED_helloworld_2eproto 5 | #define PROTOBUF_INCLUDED_helloworld_2eproto 6 | 7 | #include 8 | 9 | #include 10 | 11 | #if GOOGLE_PROTOBUF_VERSION < 3006001 12 | #error This file was generated by a newer version of protoc which is 13 | #error incompatible with your Protocol Buffer headers. Please update 14 | #error your headers. 15 | #endif 16 | #if 3006001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 17 | #error This file was generated by an older version of protoc which is 18 | #error incompatible with your Protocol Buffer headers. Please 19 | #error regenerate this file with a newer version of protoc. 20 | #endif 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include // IWYU pragma: export 31 | #include // IWYU pragma: export 32 | #include 33 | // @@protoc_insertion_point(includes) 34 | #define PROTOBUF_INTERNAL_EXPORT_protobuf_helloworld_2eproto 35 | 36 | namespace protobuf_helloworld_2eproto { 37 | // Internal implementation detail -- do not use these members. 38 | struct TableStruct { 39 | static const ::google::protobuf::internal::ParseTableField entries[]; 40 | static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; 41 | static const ::google::protobuf::internal::ParseTable schema[2]; 42 | static const ::google::protobuf::internal::FieldMetadata field_metadata[]; 43 | static const ::google::protobuf::internal::SerializationTable serialization_table[]; 44 | static const ::google::protobuf::uint32 offsets[]; 45 | }; 46 | void AddDescriptors(); 47 | } // namespace protobuf_helloworld_2eproto 48 | namespace helloworld { 49 | class HelloReply; 50 | class HelloReplyDefaultTypeInternal; 51 | extern HelloReplyDefaultTypeInternal _HelloReply_default_instance_; 52 | class HelloRequest; 53 | class HelloRequestDefaultTypeInternal; 54 | extern HelloRequestDefaultTypeInternal _HelloRequest_default_instance_; 55 | } // namespace helloworld 56 | namespace google { 57 | namespace protobuf { 58 | template<> ::helloworld::HelloReply* Arena::CreateMaybeMessage<::helloworld::HelloReply>(Arena*); 59 | template<> ::helloworld::HelloRequest* Arena::CreateMaybeMessage<::helloworld::HelloRequest>(Arena*); 60 | } // namespace protobuf 61 | } // namespace google 62 | namespace helloworld { 63 | 64 | // =================================================================== 65 | 66 | class HelloRequest : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:helloworld.HelloRequest) */ { 67 | public: 68 | HelloRequest(); 69 | virtual ~HelloRequest(); 70 | 71 | HelloRequest(const HelloRequest& from); 72 | 73 | inline HelloRequest& operator=(const HelloRequest& from) { 74 | CopyFrom(from); 75 | return *this; 76 | } 77 | #if LANG_CXX11 78 | HelloRequest(HelloRequest&& from) noexcept 79 | : HelloRequest() { 80 | *this = ::std::move(from); 81 | } 82 | 83 | inline HelloRequest& operator=(HelloRequest&& from) noexcept { 84 | if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { 85 | if (this != &from) InternalSwap(&from); 86 | } else { 87 | CopyFrom(from); 88 | } 89 | return *this; 90 | } 91 | #endif 92 | static const ::google::protobuf::Descriptor* descriptor(); 93 | static const HelloRequest& default_instance(); 94 | 95 | static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY 96 | static inline const HelloRequest* internal_default_instance() { 97 | return reinterpret_cast( 98 | &_HelloRequest_default_instance_); 99 | } 100 | static constexpr int kIndexInFileMessages = 101 | 0; 102 | 103 | void Swap(HelloRequest* other); 104 | friend void swap(HelloRequest& a, HelloRequest& b) { 105 | a.Swap(&b); 106 | } 107 | 108 | // implements Message ---------------------------------------------- 109 | 110 | inline HelloRequest* New() const final { 111 | return CreateMaybeMessage(NULL); 112 | } 113 | 114 | HelloRequest* New(::google::protobuf::Arena* arena) const final { 115 | return CreateMaybeMessage(arena); 116 | } 117 | void CopyFrom(const ::google::protobuf::Message& from) final; 118 | void MergeFrom(const ::google::protobuf::Message& from) final; 119 | void CopyFrom(const HelloRequest& from); 120 | void MergeFrom(const HelloRequest& from); 121 | void Clear() final; 122 | bool IsInitialized() const final; 123 | 124 | size_t ByteSizeLong() const final; 125 | bool MergePartialFromCodedStream( 126 | ::google::protobuf::io::CodedInputStream* input) final; 127 | void SerializeWithCachedSizes( 128 | ::google::protobuf::io::CodedOutputStream* output) const final; 129 | ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( 130 | bool deterministic, ::google::protobuf::uint8* target) const final; 131 | int GetCachedSize() const final { return _cached_size_.Get(); } 132 | 133 | private: 134 | void SharedCtor(); 135 | void SharedDtor(); 136 | void SetCachedSize(int size) const final; 137 | void InternalSwap(HelloRequest* other); 138 | private: 139 | inline ::google::protobuf::Arena* GetArenaNoVirtual() const { 140 | return NULL; 141 | } 142 | inline void* MaybeArenaPtr() const { 143 | return NULL; 144 | } 145 | public: 146 | 147 | ::google::protobuf::Metadata GetMetadata() const final; 148 | 149 | // nested types ---------------------------------------------------- 150 | 151 | // accessors ------------------------------------------------------- 152 | 153 | // string name = 1; 154 | void clear_name(); 155 | static const int kNameFieldNumber = 1; 156 | const ::std::string& name() const; 157 | void set_name(const ::std::string& value); 158 | #if LANG_CXX11 159 | void set_name(::std::string&& value); 160 | #endif 161 | void set_name(const char* value); 162 | void set_name(const char* value, size_t size); 163 | ::std::string* mutable_name(); 164 | ::std::string* release_name(); 165 | void set_allocated_name(::std::string* name); 166 | 167 | // @@protoc_insertion_point(class_scope:helloworld.HelloRequest) 168 | private: 169 | 170 | ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; 171 | ::google::protobuf::internal::ArenaStringPtr name_; 172 | mutable ::google::protobuf::internal::CachedSize _cached_size_; 173 | friend struct ::protobuf_helloworld_2eproto::TableStruct; 174 | }; 175 | // ------------------------------------------------------------------- 176 | 177 | class HelloReply : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:helloworld.HelloReply) */ { 178 | public: 179 | HelloReply(); 180 | virtual ~HelloReply(); 181 | 182 | HelloReply(const HelloReply& from); 183 | 184 | inline HelloReply& operator=(const HelloReply& from) { 185 | CopyFrom(from); 186 | return *this; 187 | } 188 | #if LANG_CXX11 189 | HelloReply(HelloReply&& from) noexcept 190 | : HelloReply() { 191 | *this = ::std::move(from); 192 | } 193 | 194 | inline HelloReply& operator=(HelloReply&& from) noexcept { 195 | if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { 196 | if (this != &from) InternalSwap(&from); 197 | } else { 198 | CopyFrom(from); 199 | } 200 | return *this; 201 | } 202 | #endif 203 | static const ::google::protobuf::Descriptor* descriptor(); 204 | static const HelloReply& default_instance(); 205 | 206 | static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY 207 | static inline const HelloReply* internal_default_instance() { 208 | return reinterpret_cast( 209 | &_HelloReply_default_instance_); 210 | } 211 | static constexpr int kIndexInFileMessages = 212 | 1; 213 | 214 | void Swap(HelloReply* other); 215 | friend void swap(HelloReply& a, HelloReply& b) { 216 | a.Swap(&b); 217 | } 218 | 219 | // implements Message ---------------------------------------------- 220 | 221 | inline HelloReply* New() const final { 222 | return CreateMaybeMessage(NULL); 223 | } 224 | 225 | HelloReply* New(::google::protobuf::Arena* arena) const final { 226 | return CreateMaybeMessage(arena); 227 | } 228 | void CopyFrom(const ::google::protobuf::Message& from) final; 229 | void MergeFrom(const ::google::protobuf::Message& from) final; 230 | void CopyFrom(const HelloReply& from); 231 | void MergeFrom(const HelloReply& from); 232 | void Clear() final; 233 | bool IsInitialized() const final; 234 | 235 | size_t ByteSizeLong() const final; 236 | bool MergePartialFromCodedStream( 237 | ::google::protobuf::io::CodedInputStream* input) final; 238 | void SerializeWithCachedSizes( 239 | ::google::protobuf::io::CodedOutputStream* output) const final; 240 | ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( 241 | bool deterministic, ::google::protobuf::uint8* target) const final; 242 | int GetCachedSize() const final { return _cached_size_.Get(); } 243 | 244 | private: 245 | void SharedCtor(); 246 | void SharedDtor(); 247 | void SetCachedSize(int size) const final; 248 | void InternalSwap(HelloReply* other); 249 | private: 250 | inline ::google::protobuf::Arena* GetArenaNoVirtual() const { 251 | return NULL; 252 | } 253 | inline void* MaybeArenaPtr() const { 254 | return NULL; 255 | } 256 | public: 257 | 258 | ::google::protobuf::Metadata GetMetadata() const final; 259 | 260 | // nested types ---------------------------------------------------- 261 | 262 | // accessors ------------------------------------------------------- 263 | 264 | // string message = 1; 265 | void clear_message(); 266 | static const int kMessageFieldNumber = 1; 267 | const ::std::string& message() const; 268 | void set_message(const ::std::string& value); 269 | #if LANG_CXX11 270 | void set_message(::std::string&& value); 271 | #endif 272 | void set_message(const char* value); 273 | void set_message(const char* value, size_t size); 274 | ::std::string* mutable_message(); 275 | ::std::string* release_message(); 276 | void set_allocated_message(::std::string* message); 277 | 278 | // @@protoc_insertion_point(class_scope:helloworld.HelloReply) 279 | private: 280 | 281 | ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; 282 | ::google::protobuf::internal::ArenaStringPtr message_; 283 | mutable ::google::protobuf::internal::CachedSize _cached_size_; 284 | friend struct ::protobuf_helloworld_2eproto::TableStruct; 285 | }; 286 | // =================================================================== 287 | 288 | 289 | // =================================================================== 290 | 291 | #ifdef __GNUC__ 292 | #pragma GCC diagnostic push 293 | #pragma GCC diagnostic ignored "-Wstrict-aliasing" 294 | #endif // __GNUC__ 295 | // HelloRequest 296 | 297 | // string name = 1; 298 | inline void HelloRequest::clear_name() { 299 | name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 300 | } 301 | inline const ::std::string& HelloRequest::name() const { 302 | // @@protoc_insertion_point(field_get:helloworld.HelloRequest.name) 303 | return name_.GetNoArena(); 304 | } 305 | inline void HelloRequest::set_name(const ::std::string& value) { 306 | 307 | name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); 308 | // @@protoc_insertion_point(field_set:helloworld.HelloRequest.name) 309 | } 310 | #if LANG_CXX11 311 | inline void HelloRequest::set_name(::std::string&& value) { 312 | 313 | name_.SetNoArena( 314 | &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); 315 | // @@protoc_insertion_point(field_set_rvalue:helloworld.HelloRequest.name) 316 | } 317 | #endif 318 | inline void HelloRequest::set_name(const char* value) { 319 | GOOGLE_DCHECK(value != NULL); 320 | 321 | name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); 322 | // @@protoc_insertion_point(field_set_char:helloworld.HelloRequest.name) 323 | } 324 | inline void HelloRequest::set_name(const char* value, size_t size) { 325 | 326 | name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), 327 | ::std::string(reinterpret_cast(value), size)); 328 | // @@protoc_insertion_point(field_set_pointer:helloworld.HelloRequest.name) 329 | } 330 | inline ::std::string* HelloRequest::mutable_name() { 331 | 332 | // @@protoc_insertion_point(field_mutable:helloworld.HelloRequest.name) 333 | return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 334 | } 335 | inline ::std::string* HelloRequest::release_name() { 336 | // @@protoc_insertion_point(field_release:helloworld.HelloRequest.name) 337 | 338 | return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 339 | } 340 | inline void HelloRequest::set_allocated_name(::std::string* name) { 341 | if (name != NULL) { 342 | 343 | } else { 344 | 345 | } 346 | name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); 347 | // @@protoc_insertion_point(field_set_allocated:helloworld.HelloRequest.name) 348 | } 349 | 350 | // ------------------------------------------------------------------- 351 | 352 | // HelloReply 353 | 354 | // string message = 1; 355 | inline void HelloReply::clear_message() { 356 | message_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 357 | } 358 | inline const ::std::string& HelloReply::message() const { 359 | // @@protoc_insertion_point(field_get:helloworld.HelloReply.message) 360 | return message_.GetNoArena(); 361 | } 362 | inline void HelloReply::set_message(const ::std::string& value) { 363 | 364 | message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); 365 | // @@protoc_insertion_point(field_set:helloworld.HelloReply.message) 366 | } 367 | #if LANG_CXX11 368 | inline void HelloReply::set_message(::std::string&& value) { 369 | 370 | message_.SetNoArena( 371 | &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); 372 | // @@protoc_insertion_point(field_set_rvalue:helloworld.HelloReply.message) 373 | } 374 | #endif 375 | inline void HelloReply::set_message(const char* value) { 376 | GOOGLE_DCHECK(value != NULL); 377 | 378 | message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); 379 | // @@protoc_insertion_point(field_set_char:helloworld.HelloReply.message) 380 | } 381 | inline void HelloReply::set_message(const char* value, size_t size) { 382 | 383 | message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), 384 | ::std::string(reinterpret_cast(value), size)); 385 | // @@protoc_insertion_point(field_set_pointer:helloworld.HelloReply.message) 386 | } 387 | inline ::std::string* HelloReply::mutable_message() { 388 | 389 | // @@protoc_insertion_point(field_mutable:helloworld.HelloReply.message) 390 | return message_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 391 | } 392 | inline ::std::string* HelloReply::release_message() { 393 | // @@protoc_insertion_point(field_release:helloworld.HelloReply.message) 394 | 395 | return message_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 396 | } 397 | inline void HelloReply::set_allocated_message(::std::string* message) { 398 | if (message != NULL) { 399 | 400 | } else { 401 | 402 | } 403 | message_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), message); 404 | // @@protoc_insertion_point(field_set_allocated:helloworld.HelloReply.message) 405 | } 406 | 407 | #ifdef __GNUC__ 408 | #pragma GCC diagnostic pop 409 | #endif // __GNUC__ 410 | // ------------------------------------------------------------------- 411 | 412 | 413 | // @@protoc_insertion_point(namespace_scope) 414 | 415 | } // namespace helloworld 416 | 417 | // @@protoc_insertion_point(global_scope) 418 | 419 | #endif // PROTOBUF_INCLUDED_helloworld_2eproto 420 | -------------------------------------------------------------------------------- /demo-async-server/helloworld.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2015 gRPC authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | option java_multiple_files = true; 18 | option java_package = "io.grpc.examples.helloworld"; 19 | option java_outer_classname = "HelloWorldProto"; 20 | option objc_class_prefix = "HLW"; 21 | 22 | package helloworld; 23 | 24 | // The greeting service definition. 25 | service Greeter { 26 | // Sends a greeting 27 | rpc SayHello (HelloRequest) returns (HelloReply) {} 28 | } 29 | 30 | // The request message containing the user's name. 31 | message HelloRequest { 32 | string name = 1; 33 | } 34 | 35 | // The response message containing the greetings 36 | message HelloReply { 37 | string message = 1; 38 | } 39 | -------------------------------------------------------------------------------- /demo-sync-client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # CMake 最低版本号要求 2 | cmake_minimum_required (VERSION 2.8) 3 | 4 | # 项目信息 5 | project (demo-sync-client CXX) 6 | 7 | # 版本信息 8 | set (Demo_VERSION_MAJOR 1) 9 | set (Demo_VERSION_MINOR 0) 10 | 11 | 12 | # 编译参数 13 | set (CMAKE_BUILE_TYPE RELEASE) 14 | add_definitions(-DRELEASE) 15 | 16 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC -pthread") 17 | 18 | 19 | # 查找当前目录下的所有源文件 20 | # 并将名称保存到 DIR_LIB_SRCS 变量 21 | aux_source_directory(. DIR_LIB_SRCS) 22 | #aux_source_directory(model DIR_LIB_SRCS) 23 | 24 | set (EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}) 25 | #设置proto工具目录 26 | get_filename_component(proto_tool "${PROJECT_SOURCE_DIR}/../../libs/protobuf" ABSOLUTE) 27 | #生成PB 28 | execute_process(COMMAND ${proto_tool}/protoc -I ${PROJECT_SOURCE_DIR} --cpp_out=${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/helloworld.proto) 29 | execute_process(COMMAND ${proto_tool}/protoc -I ${PROJECT_SOURCE_DIR} --grpc_out=${PROJECT_SOURCE_DIR} 30 | --plugin=protoc-gen-grpc=${proto_tool}/grpc_cpp_plugin ${PROJECT_SOURCE_DIR}/helloworld.proto) 31 | 32 | # 链接库目录 33 | link_directories ("${PROJECT_SOURCE_DIR}/../../libs/opt" 34 | "${PROJECT_SOURCE_DIR}/../../libs/lib" 35 | "${PROJECT_SOURCE_DIR}/../../libs/protobuf" 36 | "${PROJECT_SOURCE_DIR}/../../libs/zookeeper") 37 | 38 | # 添加包含目录 39 | include_directories("${PROJECT_SOURCE_DIR}" 40 | "${PROJECT_SOURCE_DIR}/../../include/orientsec_grpc" 41 | "${PROJECT_SOURCE_DIR}/../../include/include" 42 | "${PROJECT_SOURCE_DIR}/../../include/third_party/protobuf/src/" 43 | "${PROJECT_SOURCE_DIR}/../../include/third_party/protobuf" 44 | "${PROJECT_SOURCE_DIR}/model") 45 | 46 | 47 | # 生成链接库 48 | add_executable (demo-sync-client ${DIR_LIB_SRCS}) 49 | 50 | # 添加链接库 51 | target_link_libraries(demo-sync-client libgpr.so) 52 | target_link_libraries(demo-sync-client libgrpc.so) 53 | target_link_libraries(demo-sync-client libgrpc++.so) 54 | target_link_libraries(demo-sync-client libprotobuf.a) 55 | target_link_libraries(demo-sync-client libssl.so) 56 | target_link_libraries(demo-sync-client liborientsec_common.a) 57 | target_link_libraries(demo-sync-client liborientsec_provider.a) 58 | target_link_libraries(demo-sync-client liborientsec_consumer.a) 59 | target_link_libraries(demo-sync-client liborientsec_registry.a) 60 | target_link_libraries(demo-sync-client libzookeeper_mt.so) 61 | 62 | -------------------------------------------------------------------------------- /demo-sync-client/config/dfzq-grpc-config.properties: -------------------------------------------------------------------------------- 1 | # 配置信息分为五类: 2 | # 1. common config (公共配置) 3 | # 2. provider config (服务提供者需要填写) 4 | # 3. consumer config (服务消费者需要填写) 5 | # 4. kafka config (提供者、消费者都需要配置) 6 | # 5. zookeeper config (提供者、消费者都需要配置) 7 | 8 | # 配置文件的放置路径:class文件根目录 9 | # (请参照:使用log4j记日志的项目中 log4j.properties 文件的路径) 10 | 11 | 12 | # ------------ begin of common config ------------ 13 | 14 | # 必填,类型string,说明:当前应用名称 15 | common.application=grpc-test-app 16 | 17 | # 必填,类型string,说明:grpc版本号 18 | common.grpc=1.2.4 19 | 20 | #选填,默认是 grpc-test-app,说明:grpc项目名监控 21 | common.project=grpc-java 22 | 23 | # 选填,类型string,说明:服务注册根路径,默认值/Application/grpc 24 | #common.root=/Application/grpc/c++ 25 | 26 | 27 | # 必填,类型string,说明:项目负责人,员工工号,多个工号之间使用英文逗号 28 | common.owner=A9001,A9002,A9003 29 | 30 | # 可选,类型string,说明:服务注册使用的IP地址 31 | # 如果不配置该参数值,当前服务器的IP地址为"非127.0.0.1的第一个网卡的IP地址" 32 | # 使用场合:一台服务器安装有多个网卡,如果需要指定不是第一个网卡的IP地址为服务注册的IP地址 33 | #common.localhost.ip=192.168.2.123 34 | 35 | # ------------ end of common config ------------ 36 | 37 | 38 | 39 | 40 | # ------------ begin of provider config ------------ 41 | 42 | # 必填,类型string,说明:服务的版本信息,一般表示服务接口的版本号 43 | provider.version=2.0 44 | 45 | # 必填,类型String,固定值provider,说明:provider表示服务提供端,consumer表示服务消费端 46 | provider.side=provider 47 | 48 | # ---------------------------------------- 49 | 50 | # 可选,类型string,说明:当前模块名称 51 | # provider.module= 52 | 53 | # 可选,类型string,说明:服务分组信息,一般用来区分一个服务接口的多种实现(provider) 54 | # provider.group= 55 | 56 | # 可选,类型int,缺省值1000,说明:远程服务调用超时时间(毫秒) 57 | # provider.default.timeout= 58 | 59 | # 可选,类型int,缺省值2,说明:远程服务调用重试次数,不包括第一次调用,不需要重试则设置为0 60 | # provider.default.reties= 61 | 62 | # 可选,类型int,缺省值0,说明:对每个provider最大连接次数,默认最大连接数 63 | #provider.default.connections=1 64 | 65 | # 可选,类型string,缺省值round_robin,说明:负载均衡策略,可选值:pick_first、round_robin,weight_round_robin,可扩展实现其他策略 66 | # provider.default.loadbalance= 67 | 68 | # 可选,类型Boolean,缺省值false,说明:是否缺省异步执行,如果true则可直接忽略返回值,不阻塞线程 69 | # provider.default.async= 70 | #Max request 71 | #provider.default.requests=1 72 | # dataflow control 73 | #provider.default.connections=1 74 | 75 | #route rule 76 | #provider.access.protected=true 77 | 78 | 79 | # 可选,类型sting/Boolean,缺省值false,说明:令牌验证,为空表示不开启,为true则随机生成动态令牌,否则使用镜头令牌 80 | # provider.token= 81 | 82 | # 可选,类型boolean,缺省值false,说明:服务是否过时,如果为true则应用该服务时日志error告警 83 | # provider.deprecated=true 84 | 85 | # 可选,类型boolean,缺省值ture,说明:服务是否动态注册,如果为false则注册后将显示为disable状态, 86 | # 需要人工启用,且服务停止时需手动注销 87 | # provider.dynamic= 88 | 89 | # 可选,类型string/boolean,缺省值false,说明:设为true,将向logger中输出访问日志,也可填写访问 90 | # 日志文件路径,直接把访问日志输出到指定文件 91 | # provider.accesslog= 92 | 93 | # 可选,类型string,说明:服务负责人,填写负责人公司邮箱前缀 94 | # provider.owner= 95 | 96 | # 可选,类型int,缺省值100,说明:服务provider权重,是服务provider的容量,在负载均衡基于权重的选择算法中用到 97 | # provider.weight= 98 | 99 | # 可选,类型string,缺省值failover,说明:集群方式,可选:failover/failfast/failback/forking 100 | # provider.default.cluster= 101 | 102 | # 可选,类型string,说明:应用版本号 103 | # provider.application.version= 104 | 105 | # 可选,类型string,说明:组织名(BU或部门) 106 | # provider.organization= 107 | 108 | # 可选,类型string,说明:应用环境,如:develop/test/product 109 | # provider.environment= 110 | 111 | # 可选,类型string,说明:模块的版本号 112 | # provider.module.version= 113 | 114 | # 可选,类型boolean,缺省值false,说明:表示是否为跨主机访问 115 | # provider.anyhost= 116 | 117 | # 可选,类型string,说明:dubbo版本号,缺省值为grpc的版本号 118 | # provider.dubbo= 119 | 120 | # 可选, 类型boolean, 缺省值false, 说明:服务是否处于访问保护状态 121 | # 属性的可选值为false 、true ,分别表示不受保护、受保护,缺省值为false (不受保护) 122 | #provider.access.protected=true 123 | 124 | # ------------ end of provider config ------------ 125 | 126 | 127 | 128 | 129 | # ------------ begin of consumer config ------------ 130 | 131 | # 必填,类型boolean,缺省值true,说明:启动时检查提供者是否存在,true报错,false忽略 132 | consumer.check=true 133 | 134 | # 必填,类型int,固定值1000,说明:远程服务调用超时时间(毫秒) 135 | consumer.default.timeout=1000 136 | 137 | # 必填,类型String,默认值consumers,说明:所属范畴 138 | consumer.category=consumers 139 | 140 | # 必填,类型String,固定值consumer,说明:provider表示服务提供端,consumer表示服务消费端 141 | consumer.side=consumer 142 | 143 | # -------------------------- 144 | # 可选,类型string,说明:服务提供者的版本号 145 | # 指定了服务提供者的版本号之后,程序会优先选择具有指定版本的服务;如果注册中心没有该版本的服务,则不限制版本重新选择服务提供者。 146 | # 使用场景为:注册中心上同一个服务多版本共存,并且服务的高版本与低版本不兼容,而当前应用由于特殊原因只能调用低版本的服务 147 | # 如果当前应用只调用一个服务,属性值直接配置版本号,例如1.0.0 148 | # 如果当前应用需要调用多个服务,属性值按照冒号逗号的方式分隔,例如com.dfzq.examples.Greeter:1.0.0,com.dfzq.examples.Hello:1.2.1 149 | # 如果当前应用需要调用多个服务,建议在服务治理平台维护该属性,只有一个版本的服务可以不维护 150 | #consumer.service.version=helloworld.Greeter:1.0,com.dfzq.grpc.helloworld.Greeter:1.0.2 151 | 152 | # 可选,类型string,说明:应用版本号 153 | # consumer.application.version= 154 | 155 | # 可选,类型String,说明:服务消费方远程调用过程拦截器名称,多个名称用逗号分隔 156 | # consumer.default.reference.filter= 157 | 158 | # 可选,类型String,缺省值slf4j,说明:日志输出方式,可选:slf4j,jcl,log4j,jdk 159 | # consumer.logger= 160 | 161 | # 可选,类型String,说明:调用服务负责人,用于服务治理,请填写负责人公司邮箱前缀 162 | # consumer.owner= 163 | 164 | # 可选,类型string,说明:组织名(BU或部门) 165 | # consumer.organization= 166 | 167 | # 可选,类型int,缺省值2,说明:远程服务调用重试次数 168 | # consumer.default.retries= 169 | 170 | # 可选,类型string,缺省值connection,说明:负载均衡模式 171 | # 可选值为 connection 和 request,分别表示“连接负载均衡”、“请求负载均衡” 172 | # “连接负载均衡”适用于大部分业务场景,服务端和客户端消耗的资源较小。 173 | # “请求负载均衡”适用于服务端业务逻辑复杂、并有多台服务器提供相同服务的场景。 174 | consumer.loadbalance.mode=request 175 | #consumer.loadbalance.mode=connection 176 | 177 | 178 | # 可选,类型string,缺省值round_robin,说明:调度策略,可选范围:pick_first、round_robin、weight_round_robin、consistent_hash 179 | consumer.default.loadbalance=round_robin 180 | 181 | #the weight of provider 182 | provider.weight=1 183 | 184 | 185 | # 可选,类型string,负载均衡策略选择是consistent_hash(一致性Hash),配置进行hash运算的参数名称的列表 186 | # 多个参数之间使用英文逗号分隔,例如 id,name 187 | # 如果负载均衡策略选择是consistent_hash,但是该参数未配置参数值、或者参数值列表不正确,则随机取一个值来做散列运算 188 | 189 | consumer.consistent.hash.arguments=name,no 190 | 191 | # 可选,类型int,缺省值100,说明:每个服务对外最大连接数 192 | # consumer.default.connections= 193 | 194 | # 可选,类型string,缺省值failover,说明:集群方式,可选:failover/failfast/failback/forking 195 | # consumer.default.cluster= 196 | 197 | # 可选,类型integer,缺省值5,说明:连续多少次请求出错,自动切换到提供相同服务的新服务器 198 | consumer.switchover.threshold=5 199 | 200 | # 可选,类型为long,单位为秒,缺省值为60,说明:服务提供者不可用时的惩罚时间,即多次请求出错的服务提供者一段时间内不再去请求 201 | # 属性值大于或等于0,等于0表示没有惩罚时间,如果客户端只剩下一个服务提供者,即使服务提供者不可用,也不做剔除操作。 202 | consumer.unavailable.provider.punish.time=60 203 | # ------------ end of consumer config ------------ 204 | 205 | 206 | 207 | 208 | # ------------ begin of kafka.producer config ------------ 209 | 210 | # 转发服务跟踪信息给kafka的服务提供者的IP地址和端口 211 | # 服务跟踪信息先发送给KafkaSenderServer(一个基于原生grpc的服务),然后由KafkaSenderServer转发给kafka 212 | # 多个服务提供者之间使用英文逗号分隔,IP地址和端口使用英文冒号分隔 213 | # kafka.sender.servers=192.168.0.1:50080,192.168.0.2:50080,192.168.0.3:50080 214 | #kafka.sender.servers=127.0.0.1:50080 215 | #kafka.sender.servers=127.0.0.1:9093 216 | #kafka.sender.servers=160.6.78.133:50080 217 | 218 | # 可选,采样频率,指的是每秒采集服务链的数据条数(这里的一条理解为traceId相同的多个json串); 219 | # 默认值为空,表示所有服务链都发送到kafka; 220 | # 如果采样率的数值不为空,并且数值大于0,根据指定的采样率采集数据 221 | # 配置值可以为正整数、小数(例如0.5)、分数(例如3/1024) 222 | # kafka.sampling.frequency= 223 | 224 | # 可选, 将服务跟踪信息发送给KafkaSenderServer的线程个数 225 | # 配置值为正整数,默认值为1 226 | # kafka.sender.number=1 227 | 228 | # 可选, 服务跟踪信息消息队列的容量 229 | # 配置值为正整数,默认值为50000 230 | # message.queue.capacity=50000 231 | # -------------------------- 232 | 233 | # 可选,每个RecordBatch可以缓存的最大字节数 234 | # kafka.producer.batch.size=16384 235 | 236 | # 可选,所有RecordBatch的总共最大字节数 237 | # kafka.producer.buffer.memory=33554432 238 | 239 | # 可选,每个RecordBatch的最长延迟发送时间 240 | # kafka.producer.linger.ms=1 241 | 242 | # 可选,每个RecordBatch的最长阻塞时间 243 | # kafka.producer.max.block.ms=1 244 | 245 | # 可选,消息发送失败重试的次数 246 | # kafka.producer.retries=0 247 | 248 | # 可选,失败补偿时间,每次失败重试的时间间隔,不可设置太短,避免第一条消息的响应还没返回,第二条消息又发出去了,造成逻辑错误 249 | # kafka.producer.retry.backoff.ms 250 | 251 | # 可选,同一时间,producer到broker的一个连接上允许的最大未确认请求数,默认为5 252 | # kafka.producer.max.in.flight.requests.per.connection=5 253 | 254 | # 可选,采样频率,指的是每秒向kafka写服务链的数据条数(这里的一条理解为traceId相同的多个json串); 255 | # 默认值为空,表示所有服务链都发送到kafka; 256 | # 如果采样率的数值不为空,并且数值大于0,根据指定的采样率采集数据 257 | # 配置值可以为正整数、小数(例如0.5)、分数(例如3/1024) 258 | #kafka.sampling.frequency=0.5 259 | 260 | # ------------ end of kafka.producer config ------------ 261 | 262 | 263 | 264 | 265 | # ------------ begin of zookeeper config ------------ 266 | 267 | # zookeeper主机列表 268 | #zookeeper.host.server=192.168.207.4:2181,192.168.207.6:2181 269 | zookeeper.host.server=192.168.2.103:2181 270 | #zookeeper.host.server=160.6.78.133:2181 271 | 272 | #重试次数 273 | zookeeper.retryNum=5 274 | 275 | #连接超时时间 276 | zookeeper.connectiontimeout=5000 277 | 278 | 279 | # 可选,类型string,访问控制用户名 280 | zookeeper.acl.username=admin 281 | 282 | # 可选,类型string,访问控制密码 283 | # 这里的密码配置的是密文,使用com.orientsec.grpc.common.util.DesEncryptUtils#encrypt(String plaintext)进行加密 284 | #zookeeper.acl.password=9b579c35ca6cc74230f1eed29064d10a 285 | zookeeper.acl.password=9883c580ae8226f0dd8200620e4bc899 286 | 287 | 288 | 289 | # ------------ end of zookeeper config ------------ 290 | 291 | -------------------------------------------------------------------------------- /demo-sync-client/demo-sync-client.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Orient Securities Co., Ltd. 3 | * Copyright 2019 BoCloud Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #ifdef BAZEL_BUILD 27 | #include "examples/protos/helloworld.grpc.pb.h" 28 | #else 29 | #include "helloworld.grpc.pb.h" 30 | #endif 31 | 32 | static int run_times = 10000; // call times 33 | void *multiple(void* arg); 34 | 35 | using grpc::Channel; 36 | using grpc::ClientContext; 37 | using grpc::Status; 38 | using helloworld::HelloRequest; 39 | using helloworld::HelloReply; 40 | using helloworld::Greeter; 41 | 42 | class GreeterClient { 43 | public: 44 | GreeterClient(std::shared_ptr channel) 45 | : stub_(Greeter::NewStub(channel)) {} 46 | 47 | // Assembles the client's payload, sends it and presents the response back 48 | // from the server. 49 | std::string SayHello(const std::string& user) { 50 | // Data we are sending to the server. 51 | HelloRequest request; 52 | request.set_name(user); 53 | 54 | // Container for the data we expect from the server. 55 | HelloReply reply; 56 | 57 | // Context for the client. It could be used to convey extra information to 58 | // the server and/or tweak certain RPC behaviors. 59 | ClientContext context; 60 | 61 | // The actual RPC. 62 | Status status = stub_->SayHello(&context, request, &reply); 63 | 64 | // Act upon its status. 65 | if (status.ok()) { 66 | return reply.message(); 67 | } 68 | else { 69 | std::cout << status.error_code() << ": " << status.error_message() 70 | << std::endl; 71 | return "RPC failed"; 72 | } 73 | } 74 | 75 | private: 76 | std::unique_ptr stub_; 77 | }; 78 | 79 | 80 | void *multiple(void * arg) 81 | { 82 | #if 0 83 | GreeterClient greeter(grpc::CreateChannel( 84 | "localhost:50051", grpc::InsecureChannelCredentials())); 85 | #else 86 | GreeterClient greeter(grpc::CreateChannel( 87 | "zookeeper:///helloworld.Greeter", grpc::InsecureChannelCredentials())); 88 | #endif 89 | 90 | 91 | // for consistent hash testing 92 | #if 0 93 | int count = 300; 94 | char *name = new char[20]; 95 | memset(name, 0, sizeof(char) * 20); 96 | while (count--) { 97 | std::string user("world"); 98 | char str[10]; 99 | if (!(count % 10)) { 100 | sprintf(str, "%0d", count); 101 | user.append(str); 102 | strcpy(name, user.c_str()); 103 | } 104 | std::string reply = greeter.SayHello(name); 105 | std::cout << "Greeter received: " << reply << std::endl; 106 | } 107 | #else 108 | int count = 10000; 109 | while (count--) { 110 | std::string user("world000"); 111 | char str[10]; 112 | sprintf(str, "%0d", count); 113 | user.append(str); 114 | 115 | std::string reply = greeter.SayHello(user); 116 | std::cout << "Greeter received: " << reply << std::endl; 117 | //Sleep(1000); 118 | } 119 | #endif 120 | 121 | } 122 | int main(int argc, char** argv) { 123 | // Instantiate the client. It requires a channel, out of which the actual RPCs 124 | // are created. This channel models a connection to an endpoint (in this case, 125 | // localhost at port 50051). We indicate that the channel isn't authenticated 126 | // (use of InsecureChannelCredentials()). 127 | //gpr_set_log_verbosity(GPR_LOG_SEVERITY_INFO); 128 | //gpr_set_log_verbosity(GPR_LOG_SEVERITY_ERROR); 129 | //gpr_set_log_verbosity(GPR_LOG_SEVERITY_DEBUG); 130 | 131 | if (argc >= 2) 132 | { 133 | run_times = atoi(argv[1]); 134 | } 135 | 136 | //pthread_t *ids = new pthread_t(3); 137 | pthread_t p1, p2; 138 | 139 | 140 | pthread_create(&p1, NULL, multiple, NULL); 141 | pthread_create(&p2, NULL, multiple, NULL); 142 | pthread_join(p1, NULL); 143 | pthread_join(p2, NULL); 144 | 145 | return 0; 146 | } 147 | -------------------------------------------------------------------------------- /demo-sync-client/helloworld.grpc.pb.cc: -------------------------------------------------------------------------------- 1 | // Generated by the gRPC C++ plugin. 2 | // If you make any local change, they will be lost. 3 | // source: helloworld.proto 4 | 5 | #include "helloworld.pb.h" 6 | #include "helloworld.grpc.pb.h" 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | namespace helloworld { 20 | 21 | static const char* Greeter_method_names[] = { 22 | "/helloworld.Greeter/SayHello", 23 | }; 24 | 25 | std::unique_ptr< Greeter::Stub> Greeter::NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options) { 26 | (void)options; 27 | std::unique_ptr< Greeter::Stub> stub(new Greeter::Stub(channel)); 28 | return stub; 29 | } 30 | 31 | Greeter::Stub::Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel) 32 | : channel_(channel), rpcmethod_SayHello_(Greeter_method_names[0], ::grpc::internal::RpcMethod::NORMAL_RPC, channel) 33 | {} 34 | 35 | ::grpc::Status Greeter::Stub::SayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::helloworld::HelloReply* response) { 36 | return ::grpc::internal::BlockingUnaryCall(channel_.get(), rpcmethod_SayHello_, context, request, response); 37 | } 38 | 39 | void Greeter::Stub::experimental_async::SayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response, std::function f) { 40 | return ::grpc::internal::CallbackUnaryCall(stub_->channel_.get(), stub_->rpcmethod_SayHello_, context, request, response, std::move(f)); 41 | } 42 | 43 | ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>* Greeter::Stub::AsyncSayHelloRaw(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) { 44 | return ::grpc::internal::ClientAsyncResponseReaderFactory< ::helloworld::HelloReply>::Create(channel_.get(), cq, rpcmethod_SayHello_, context, request, true); 45 | } 46 | 47 | ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>* Greeter::Stub::PrepareAsyncSayHelloRaw(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) { 48 | return ::grpc::internal::ClientAsyncResponseReaderFactory< ::helloworld::HelloReply>::Create(channel_.get(), cq, rpcmethod_SayHello_, context, request, false); 49 | } 50 | 51 | Greeter::Service::Service() { 52 | AddMethod(new ::grpc::internal::RpcServiceMethod( 53 | Greeter_method_names[0], 54 | ::grpc::internal::RpcMethod::NORMAL_RPC, 55 | new ::grpc::internal::RpcMethodHandler< Greeter::Service, ::helloworld::HelloRequest, ::helloworld::HelloReply>( 56 | std::mem_fn(&Greeter::Service::SayHello), this))); 57 | } 58 | 59 | Greeter::Service::~Service() { 60 | } 61 | 62 | ::grpc::Status Greeter::Service::SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response) { 63 | (void) context; 64 | (void) request; 65 | (void) response; 66 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 67 | } 68 | 69 | 70 | } // namespace helloworld 71 | 72 | -------------------------------------------------------------------------------- /demo-sync-client/helloworld.grpc.pb.h: -------------------------------------------------------------------------------- 1 | // Generated by the gRPC C++ plugin. 2 | // If you make any local change, they will be lost. 3 | // source: helloworld.proto 4 | // Original file comments: 5 | // Copyright 2015 gRPC authors. 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | #ifndef GRPC_helloworld_2eproto__INCLUDED 20 | #define GRPC_helloworld_2eproto__INCLUDED 21 | 22 | #include "helloworld.pb.h" 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | namespace grpc { 38 | class CompletionQueue; 39 | class Channel; 40 | class ServerCompletionQueue; 41 | class ServerContext; 42 | } // namespace grpc 43 | 44 | namespace helloworld { 45 | 46 | // The greeting service definition. 47 | class Greeter final { 48 | public: 49 | static constexpr char const* service_full_name() { 50 | return "helloworld.Greeter"; 51 | } 52 | class StubInterface { 53 | public: 54 | virtual ~StubInterface() {} 55 | // Sends a greeting 56 | virtual ::grpc::Status SayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::helloworld::HelloReply* response) = 0; 57 | std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::helloworld::HelloReply>> AsyncSayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) { 58 | return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::helloworld::HelloReply>>(AsyncSayHelloRaw(context, request, cq)); 59 | } 60 | std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::helloworld::HelloReply>> PrepareAsyncSayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) { 61 | return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::helloworld::HelloReply>>(PrepareAsyncSayHelloRaw(context, request, cq)); 62 | } 63 | class experimental_async_interface { 64 | public: 65 | virtual ~experimental_async_interface() {} 66 | // Sends a greeting 67 | virtual void SayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response, std::function) = 0; 68 | }; 69 | virtual class experimental_async_interface* experimental_async() { return nullptr; } 70 | private: 71 | virtual ::grpc::ClientAsyncResponseReaderInterface< ::helloworld::HelloReply>* AsyncSayHelloRaw(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) = 0; 72 | virtual ::grpc::ClientAsyncResponseReaderInterface< ::helloworld::HelloReply>* PrepareAsyncSayHelloRaw(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) = 0; 73 | }; 74 | class Stub final : public StubInterface { 75 | public: 76 | Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel); 77 | ::grpc::Status SayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::helloworld::HelloReply* response) override; 78 | std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>> AsyncSayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) { 79 | return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>>(AsyncSayHelloRaw(context, request, cq)); 80 | } 81 | std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>> PrepareAsyncSayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) { 82 | return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>>(PrepareAsyncSayHelloRaw(context, request, cq)); 83 | } 84 | class experimental_async final : 85 | public StubInterface::experimental_async_interface { 86 | public: 87 | void SayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response, std::function) override; 88 | private: 89 | friend class Stub; 90 | explicit experimental_async(Stub* stub): stub_(stub) { } 91 | Stub* stub() { return stub_; } 92 | Stub* stub_; 93 | }; 94 | class experimental_async_interface* experimental_async() override { return &async_stub_; } 95 | 96 | private: 97 | std::shared_ptr< ::grpc::ChannelInterface> channel_; 98 | class experimental_async async_stub_{this}; 99 | ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>* AsyncSayHelloRaw(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) override; 100 | ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>* PrepareAsyncSayHelloRaw(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) override; 101 | const ::grpc::internal::RpcMethod rpcmethod_SayHello_; 102 | }; 103 | static std::unique_ptr NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options = ::grpc::StubOptions()); 104 | 105 | class Service : public ::grpc::Service { 106 | public: 107 | Service(); 108 | virtual ~Service(); 109 | // Sends a greeting 110 | virtual ::grpc::Status SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response); 111 | }; 112 | template 113 | class WithAsyncMethod_SayHello : public BaseClass { 114 | private: 115 | void BaseClassMustBeDerivedFromService(const Service *service) {} 116 | public: 117 | WithAsyncMethod_SayHello() { 118 | ::grpc::Service::MarkMethodAsync(0); 119 | } 120 | ~WithAsyncMethod_SayHello() override { 121 | BaseClassMustBeDerivedFromService(this); 122 | } 123 | // disable synchronous version of this method 124 | ::grpc::Status SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response) override { 125 | abort(); 126 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 127 | } 128 | void RequestSayHello(::grpc::ServerContext* context, ::helloworld::HelloRequest* request, ::grpc::ServerAsyncResponseWriter< ::helloworld::HelloReply>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { 129 | ::grpc::Service::RequestAsyncUnary(0, context, request, response, new_call_cq, notification_cq, tag); 130 | } 131 | }; 132 | typedef WithAsyncMethod_SayHello AsyncService; 133 | template 134 | class ExperimentalWithCallbackMethod_SayHello : public BaseClass { 135 | private: 136 | void BaseClassMustBeDerivedFromService(const Service *service) {} 137 | public: 138 | ExperimentalWithCallbackMethod_SayHello() { 139 | ::grpc::Service::experimental().MarkMethodCallback(0, 140 | new ::grpc::internal::CallbackUnaryHandler< ExperimentalWithCallbackMethod_SayHello, ::helloworld::HelloRequest, ::helloworld::HelloReply>( 141 | [this](::grpc::ServerContext* context, 142 | const ::helloworld::HelloRequest* request, 143 | ::helloworld::HelloReply* response, 144 | ::grpc::experimental::ServerCallbackRpcController* controller) { 145 | this->SayHello(context, request, response, controller); 146 | }, this)); 147 | } 148 | ~ExperimentalWithCallbackMethod_SayHello() override { 149 | BaseClassMustBeDerivedFromService(this); 150 | } 151 | // disable synchronous version of this method 152 | ::grpc::Status SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response) override { 153 | abort(); 154 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 155 | } 156 | virtual void SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response, ::grpc::experimental::ServerCallbackRpcController* controller) { controller->Finish(::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "")); } 157 | }; 158 | typedef ExperimentalWithCallbackMethod_SayHello ExperimentalCallbackService; 159 | template 160 | class WithGenericMethod_SayHello : public BaseClass { 161 | private: 162 | void BaseClassMustBeDerivedFromService(const Service *service) {} 163 | public: 164 | WithGenericMethod_SayHello() { 165 | ::grpc::Service::MarkMethodGeneric(0); 166 | } 167 | ~WithGenericMethod_SayHello() override { 168 | BaseClassMustBeDerivedFromService(this); 169 | } 170 | // disable synchronous version of this method 171 | ::grpc::Status SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response) override { 172 | abort(); 173 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 174 | } 175 | }; 176 | template 177 | class WithRawMethod_SayHello : public BaseClass { 178 | private: 179 | void BaseClassMustBeDerivedFromService(const Service *service) {} 180 | public: 181 | WithRawMethod_SayHello() { 182 | ::grpc::Service::MarkMethodRaw(0); 183 | } 184 | ~WithRawMethod_SayHello() override { 185 | BaseClassMustBeDerivedFromService(this); 186 | } 187 | // disable synchronous version of this method 188 | ::grpc::Status SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response) override { 189 | abort(); 190 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 191 | } 192 | void RequestSayHello(::grpc::ServerContext* context, ::grpc::ByteBuffer* request, ::grpc::ServerAsyncResponseWriter< ::grpc::ByteBuffer>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { 193 | ::grpc::Service::RequestAsyncUnary(0, context, request, response, new_call_cq, notification_cq, tag); 194 | } 195 | }; 196 | template 197 | class ExperimentalWithRawCallbackMethod_SayHello : public BaseClass { 198 | private: 199 | void BaseClassMustBeDerivedFromService(const Service *service) {} 200 | public: 201 | ExperimentalWithRawCallbackMethod_SayHello() { 202 | ::grpc::Service::experimental().MarkMethodRawCallback(0, 203 | new ::grpc::internal::CallbackUnaryHandler< ExperimentalWithRawCallbackMethod_SayHello, ::grpc::ByteBuffer, ::grpc::ByteBuffer>( 204 | [this](::grpc::ServerContext* context, 205 | const ::grpc::ByteBuffer* request, 206 | ::grpc::ByteBuffer* response, 207 | ::grpc::experimental::ServerCallbackRpcController* controller) { 208 | this->SayHello(context, request, response, controller); 209 | }, this)); 210 | } 211 | ~ExperimentalWithRawCallbackMethod_SayHello() override { 212 | BaseClassMustBeDerivedFromService(this); 213 | } 214 | // disable synchronous version of this method 215 | ::grpc::Status SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response) override { 216 | abort(); 217 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 218 | } 219 | virtual void SayHello(::grpc::ServerContext* context, const ::grpc::ByteBuffer* request, ::grpc::ByteBuffer* response, ::grpc::experimental::ServerCallbackRpcController* controller) { controller->Finish(::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "")); } 220 | }; 221 | template 222 | class WithStreamedUnaryMethod_SayHello : public BaseClass { 223 | private: 224 | void BaseClassMustBeDerivedFromService(const Service *service) {} 225 | public: 226 | WithStreamedUnaryMethod_SayHello() { 227 | ::grpc::Service::MarkMethodStreamed(0, 228 | new ::grpc::internal::StreamedUnaryHandler< ::helloworld::HelloRequest, ::helloworld::HelloReply>(std::bind(&WithStreamedUnaryMethod_SayHello::StreamedSayHello, this, std::placeholders::_1, std::placeholders::_2))); 229 | } 230 | ~WithStreamedUnaryMethod_SayHello() override { 231 | BaseClassMustBeDerivedFromService(this); 232 | } 233 | // disable regular version of this method 234 | ::grpc::Status SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response) override { 235 | abort(); 236 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 237 | } 238 | // replace default version of method with streamed unary 239 | virtual ::grpc::Status StreamedSayHello(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer< ::helloworld::HelloRequest,::helloworld::HelloReply>* server_unary_streamer) = 0; 240 | }; 241 | typedef WithStreamedUnaryMethod_SayHello StreamedUnaryService; 242 | typedef Service SplitStreamedService; 243 | typedef WithStreamedUnaryMethod_SayHello StreamedService; 244 | }; 245 | 246 | } // namespace helloworld 247 | 248 | 249 | #endif // GRPC_helloworld_2eproto__INCLUDED 250 | -------------------------------------------------------------------------------- /demo-sync-client/helloworld.pb.h: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: helloworld.proto 3 | 4 | #ifndef PROTOBUF_INCLUDED_helloworld_2eproto 5 | #define PROTOBUF_INCLUDED_helloworld_2eproto 6 | 7 | #include 8 | 9 | #include 10 | 11 | #if GOOGLE_PROTOBUF_VERSION < 3006001 12 | #error This file was generated by a newer version of protoc which is 13 | #error incompatible with your Protocol Buffer headers. Please update 14 | #error your headers. 15 | #endif 16 | #if 3006001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 17 | #error This file was generated by an older version of protoc which is 18 | #error incompatible with your Protocol Buffer headers. Please 19 | #error regenerate this file with a newer version of protoc. 20 | #endif 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include // IWYU pragma: export 31 | #include // IWYU pragma: export 32 | #include 33 | // @@protoc_insertion_point(includes) 34 | #define PROTOBUF_INTERNAL_EXPORT_protobuf_helloworld_2eproto 35 | 36 | namespace protobuf_helloworld_2eproto { 37 | // Internal implementation detail -- do not use these members. 38 | struct TableStruct { 39 | static const ::google::protobuf::internal::ParseTableField entries[]; 40 | static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; 41 | static const ::google::protobuf::internal::ParseTable schema[2]; 42 | static const ::google::protobuf::internal::FieldMetadata field_metadata[]; 43 | static const ::google::protobuf::internal::SerializationTable serialization_table[]; 44 | static const ::google::protobuf::uint32 offsets[]; 45 | }; 46 | void AddDescriptors(); 47 | } // namespace protobuf_helloworld_2eproto 48 | namespace helloworld { 49 | class HelloReply; 50 | class HelloReplyDefaultTypeInternal; 51 | extern HelloReplyDefaultTypeInternal _HelloReply_default_instance_; 52 | class HelloRequest; 53 | class HelloRequestDefaultTypeInternal; 54 | extern HelloRequestDefaultTypeInternal _HelloRequest_default_instance_; 55 | } // namespace helloworld 56 | namespace google { 57 | namespace protobuf { 58 | template<> ::helloworld::HelloReply* Arena::CreateMaybeMessage<::helloworld::HelloReply>(Arena*); 59 | template<> ::helloworld::HelloRequest* Arena::CreateMaybeMessage<::helloworld::HelloRequest>(Arena*); 60 | } // namespace protobuf 61 | } // namespace google 62 | namespace helloworld { 63 | 64 | // =================================================================== 65 | 66 | class HelloRequest : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:helloworld.HelloRequest) */ { 67 | public: 68 | HelloRequest(); 69 | virtual ~HelloRequest(); 70 | 71 | HelloRequest(const HelloRequest& from); 72 | 73 | inline HelloRequest& operator=(const HelloRequest& from) { 74 | CopyFrom(from); 75 | return *this; 76 | } 77 | #if LANG_CXX11 78 | HelloRequest(HelloRequest&& from) noexcept 79 | : HelloRequest() { 80 | *this = ::std::move(from); 81 | } 82 | 83 | inline HelloRequest& operator=(HelloRequest&& from) noexcept { 84 | if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { 85 | if (this != &from) InternalSwap(&from); 86 | } else { 87 | CopyFrom(from); 88 | } 89 | return *this; 90 | } 91 | #endif 92 | static const ::google::protobuf::Descriptor* descriptor(); 93 | static const HelloRequest& default_instance(); 94 | 95 | static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY 96 | static inline const HelloRequest* internal_default_instance() { 97 | return reinterpret_cast( 98 | &_HelloRequest_default_instance_); 99 | } 100 | static constexpr int kIndexInFileMessages = 101 | 0; 102 | 103 | void Swap(HelloRequest* other); 104 | friend void swap(HelloRequest& a, HelloRequest& b) { 105 | a.Swap(&b); 106 | } 107 | 108 | // implements Message ---------------------------------------------- 109 | 110 | inline HelloRequest* New() const final { 111 | return CreateMaybeMessage(NULL); 112 | } 113 | 114 | HelloRequest* New(::google::protobuf::Arena* arena) const final { 115 | return CreateMaybeMessage(arena); 116 | } 117 | void CopyFrom(const ::google::protobuf::Message& from) final; 118 | void MergeFrom(const ::google::protobuf::Message& from) final; 119 | void CopyFrom(const HelloRequest& from); 120 | void MergeFrom(const HelloRequest& from); 121 | void Clear() final; 122 | bool IsInitialized() const final; 123 | 124 | size_t ByteSizeLong() const final; 125 | bool MergePartialFromCodedStream( 126 | ::google::protobuf::io::CodedInputStream* input) final; 127 | void SerializeWithCachedSizes( 128 | ::google::protobuf::io::CodedOutputStream* output) const final; 129 | ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( 130 | bool deterministic, ::google::protobuf::uint8* target) const final; 131 | int GetCachedSize() const final { return _cached_size_.Get(); } 132 | 133 | private: 134 | void SharedCtor(); 135 | void SharedDtor(); 136 | void SetCachedSize(int size) const final; 137 | void InternalSwap(HelloRequest* other); 138 | private: 139 | inline ::google::protobuf::Arena* GetArenaNoVirtual() const { 140 | return NULL; 141 | } 142 | inline void* MaybeArenaPtr() const { 143 | return NULL; 144 | } 145 | public: 146 | 147 | ::google::protobuf::Metadata GetMetadata() const final; 148 | 149 | // nested types ---------------------------------------------------- 150 | 151 | // accessors ------------------------------------------------------- 152 | 153 | // string name = 1; 154 | void clear_name(); 155 | static const int kNameFieldNumber = 1; 156 | const ::std::string& name() const; 157 | void set_name(const ::std::string& value); 158 | #if LANG_CXX11 159 | void set_name(::std::string&& value); 160 | #endif 161 | void set_name(const char* value); 162 | void set_name(const char* value, size_t size); 163 | ::std::string* mutable_name(); 164 | ::std::string* release_name(); 165 | void set_allocated_name(::std::string* name); 166 | 167 | // @@protoc_insertion_point(class_scope:helloworld.HelloRequest) 168 | private: 169 | 170 | ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; 171 | ::google::protobuf::internal::ArenaStringPtr name_; 172 | mutable ::google::protobuf::internal::CachedSize _cached_size_; 173 | friend struct ::protobuf_helloworld_2eproto::TableStruct; 174 | }; 175 | // ------------------------------------------------------------------- 176 | 177 | class HelloReply : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:helloworld.HelloReply) */ { 178 | public: 179 | HelloReply(); 180 | virtual ~HelloReply(); 181 | 182 | HelloReply(const HelloReply& from); 183 | 184 | inline HelloReply& operator=(const HelloReply& from) { 185 | CopyFrom(from); 186 | return *this; 187 | } 188 | #if LANG_CXX11 189 | HelloReply(HelloReply&& from) noexcept 190 | : HelloReply() { 191 | *this = ::std::move(from); 192 | } 193 | 194 | inline HelloReply& operator=(HelloReply&& from) noexcept { 195 | if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { 196 | if (this != &from) InternalSwap(&from); 197 | } else { 198 | CopyFrom(from); 199 | } 200 | return *this; 201 | } 202 | #endif 203 | static const ::google::protobuf::Descriptor* descriptor(); 204 | static const HelloReply& default_instance(); 205 | 206 | static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY 207 | static inline const HelloReply* internal_default_instance() { 208 | return reinterpret_cast( 209 | &_HelloReply_default_instance_); 210 | } 211 | static constexpr int kIndexInFileMessages = 212 | 1; 213 | 214 | void Swap(HelloReply* other); 215 | friend void swap(HelloReply& a, HelloReply& b) { 216 | a.Swap(&b); 217 | } 218 | 219 | // implements Message ---------------------------------------------- 220 | 221 | inline HelloReply* New() const final { 222 | return CreateMaybeMessage(NULL); 223 | } 224 | 225 | HelloReply* New(::google::protobuf::Arena* arena) const final { 226 | return CreateMaybeMessage(arena); 227 | } 228 | void CopyFrom(const ::google::protobuf::Message& from) final; 229 | void MergeFrom(const ::google::protobuf::Message& from) final; 230 | void CopyFrom(const HelloReply& from); 231 | void MergeFrom(const HelloReply& from); 232 | void Clear() final; 233 | bool IsInitialized() const final; 234 | 235 | size_t ByteSizeLong() const final; 236 | bool MergePartialFromCodedStream( 237 | ::google::protobuf::io::CodedInputStream* input) final; 238 | void SerializeWithCachedSizes( 239 | ::google::protobuf::io::CodedOutputStream* output) const final; 240 | ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( 241 | bool deterministic, ::google::protobuf::uint8* target) const final; 242 | int GetCachedSize() const final { return _cached_size_.Get(); } 243 | 244 | private: 245 | void SharedCtor(); 246 | void SharedDtor(); 247 | void SetCachedSize(int size) const final; 248 | void InternalSwap(HelloReply* other); 249 | private: 250 | inline ::google::protobuf::Arena* GetArenaNoVirtual() const { 251 | return NULL; 252 | } 253 | inline void* MaybeArenaPtr() const { 254 | return NULL; 255 | } 256 | public: 257 | 258 | ::google::protobuf::Metadata GetMetadata() const final; 259 | 260 | // nested types ---------------------------------------------------- 261 | 262 | // accessors ------------------------------------------------------- 263 | 264 | // string message = 1; 265 | void clear_message(); 266 | static const int kMessageFieldNumber = 1; 267 | const ::std::string& message() const; 268 | void set_message(const ::std::string& value); 269 | #if LANG_CXX11 270 | void set_message(::std::string&& value); 271 | #endif 272 | void set_message(const char* value); 273 | void set_message(const char* value, size_t size); 274 | ::std::string* mutable_message(); 275 | ::std::string* release_message(); 276 | void set_allocated_message(::std::string* message); 277 | 278 | // @@protoc_insertion_point(class_scope:helloworld.HelloReply) 279 | private: 280 | 281 | ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; 282 | ::google::protobuf::internal::ArenaStringPtr message_; 283 | mutable ::google::protobuf::internal::CachedSize _cached_size_; 284 | friend struct ::protobuf_helloworld_2eproto::TableStruct; 285 | }; 286 | // =================================================================== 287 | 288 | 289 | // =================================================================== 290 | 291 | #ifdef __GNUC__ 292 | #pragma GCC diagnostic push 293 | #pragma GCC diagnostic ignored "-Wstrict-aliasing" 294 | #endif // __GNUC__ 295 | // HelloRequest 296 | 297 | // string name = 1; 298 | inline void HelloRequest::clear_name() { 299 | name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 300 | } 301 | inline const ::std::string& HelloRequest::name() const { 302 | // @@protoc_insertion_point(field_get:helloworld.HelloRequest.name) 303 | return name_.GetNoArena(); 304 | } 305 | inline void HelloRequest::set_name(const ::std::string& value) { 306 | 307 | name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); 308 | // @@protoc_insertion_point(field_set:helloworld.HelloRequest.name) 309 | } 310 | #if LANG_CXX11 311 | inline void HelloRequest::set_name(::std::string&& value) { 312 | 313 | name_.SetNoArena( 314 | &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); 315 | // @@protoc_insertion_point(field_set_rvalue:helloworld.HelloRequest.name) 316 | } 317 | #endif 318 | inline void HelloRequest::set_name(const char* value) { 319 | GOOGLE_DCHECK(value != NULL); 320 | 321 | name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); 322 | // @@protoc_insertion_point(field_set_char:helloworld.HelloRequest.name) 323 | } 324 | inline void HelloRequest::set_name(const char* value, size_t size) { 325 | 326 | name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), 327 | ::std::string(reinterpret_cast(value), size)); 328 | // @@protoc_insertion_point(field_set_pointer:helloworld.HelloRequest.name) 329 | } 330 | inline ::std::string* HelloRequest::mutable_name() { 331 | 332 | // @@protoc_insertion_point(field_mutable:helloworld.HelloRequest.name) 333 | return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 334 | } 335 | inline ::std::string* HelloRequest::release_name() { 336 | // @@protoc_insertion_point(field_release:helloworld.HelloRequest.name) 337 | 338 | return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 339 | } 340 | inline void HelloRequest::set_allocated_name(::std::string* name) { 341 | if (name != NULL) { 342 | 343 | } else { 344 | 345 | } 346 | name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); 347 | // @@protoc_insertion_point(field_set_allocated:helloworld.HelloRequest.name) 348 | } 349 | 350 | // ------------------------------------------------------------------- 351 | 352 | // HelloReply 353 | 354 | // string message = 1; 355 | inline void HelloReply::clear_message() { 356 | message_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 357 | } 358 | inline const ::std::string& HelloReply::message() const { 359 | // @@protoc_insertion_point(field_get:helloworld.HelloReply.message) 360 | return message_.GetNoArena(); 361 | } 362 | inline void HelloReply::set_message(const ::std::string& value) { 363 | 364 | message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); 365 | // @@protoc_insertion_point(field_set:helloworld.HelloReply.message) 366 | } 367 | #if LANG_CXX11 368 | inline void HelloReply::set_message(::std::string&& value) { 369 | 370 | message_.SetNoArena( 371 | &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); 372 | // @@protoc_insertion_point(field_set_rvalue:helloworld.HelloReply.message) 373 | } 374 | #endif 375 | inline void HelloReply::set_message(const char* value) { 376 | GOOGLE_DCHECK(value != NULL); 377 | 378 | message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); 379 | // @@protoc_insertion_point(field_set_char:helloworld.HelloReply.message) 380 | } 381 | inline void HelloReply::set_message(const char* value, size_t size) { 382 | 383 | message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), 384 | ::std::string(reinterpret_cast(value), size)); 385 | // @@protoc_insertion_point(field_set_pointer:helloworld.HelloReply.message) 386 | } 387 | inline ::std::string* HelloReply::mutable_message() { 388 | 389 | // @@protoc_insertion_point(field_mutable:helloworld.HelloReply.message) 390 | return message_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 391 | } 392 | inline ::std::string* HelloReply::release_message() { 393 | // @@protoc_insertion_point(field_release:helloworld.HelloReply.message) 394 | 395 | return message_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 396 | } 397 | inline void HelloReply::set_allocated_message(::std::string* message) { 398 | if (message != NULL) { 399 | 400 | } else { 401 | 402 | } 403 | message_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), message); 404 | // @@protoc_insertion_point(field_set_allocated:helloworld.HelloReply.message) 405 | } 406 | 407 | #ifdef __GNUC__ 408 | #pragma GCC diagnostic pop 409 | #endif // __GNUC__ 410 | // ------------------------------------------------------------------- 411 | 412 | 413 | // @@protoc_insertion_point(namespace_scope) 414 | 415 | } // namespace helloworld 416 | 417 | // @@protoc_insertion_point(global_scope) 418 | 419 | #endif // PROTOBUF_INCLUDED_helloworld_2eproto 420 | -------------------------------------------------------------------------------- /demo-sync-client/helloworld.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2015 gRPC authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | option java_multiple_files = true; 18 | option java_package = "io.grpc.examples.helloworld"; 19 | option java_outer_classname = "HelloWorldProto"; 20 | option objc_class_prefix = "HLW"; 21 | 22 | package helloworld; 23 | 24 | // The greeting service definition. 25 | service Greeter { 26 | // Sends a greeting 27 | rpc SayHello (HelloRequest) returns (HelloReply) {} 28 | } 29 | 30 | // The request message containing the user's name. 31 | message HelloRequest { 32 | string name = 1; 33 | } 34 | 35 | // The response message containing the greetings 36 | message HelloReply { 37 | string message = 1; 38 | } 39 | -------------------------------------------------------------------------------- /demo-sync-server/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # CMake 最低版本号要求 2 | cmake_minimum_required (VERSION 2.8) 3 | 4 | # 项目信息 5 | project (demo-sync-server CXX) 6 | 7 | # 版本信息 8 | set (Demo_VERSION_MAJOR 1) 9 | set (Demo_VERSION_MINOR 0) 10 | 11 | 12 | # 编译参数 13 | set (CMAKE_BUILE_TYPE RELEASE) 14 | add_definitions(-DRELEASE) 15 | 16 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC -pthread") 17 | 18 | 19 | # 查找当前目录下的所有源文件 20 | # 并将名称保存到 DIR_LIB_SRCS 变量 21 | aux_source_directory(. DIR_LIB_SRCS) 22 | #aux_source_directory(model DIR_LIB_SRCS) 23 | 24 | set (EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}) 25 | #设置proto工具目录 26 | get_filename_component(proto_tool "${PROJECT_SOURCE_DIR}/../../libs/protobuf" ABSOLUTE) 27 | #生成PB 28 | execute_process(COMMAND ${proto_tool}/protoc -I ${PROJECT_SOURCE_DIR} --cpp_out=${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/helloworld.proto) 29 | execute_process(COMMAND ${proto_tool}/protoc -I ${PROJECT_SOURCE_DIR} --grpc_out=${PROJECT_SOURCE_DIR} 30 | --plugin=protoc-gen-grpc=${proto_tool}/grpc_cpp_plugin ${PROJECT_SOURCE_DIR}/helloworld.proto) 31 | 32 | # 链接库目录 33 | link_directories ("${PROJECT_SOURCE_DIR}/../../libs/opt" 34 | "${PROJECT_SOURCE_DIR}/../../libs/lib" 35 | "${PROJECT_SOURCE_DIR}/../../libs/protobuf" 36 | "${PROJECT_SOURCE_DIR}/../../libs/zookeeper") 37 | 38 | # 添加包含目录 39 | include_directories("${PROJECT_SOURCE_DIR}" 40 | "${PROJECT_SOURCE_DIR}/../../include/orientsec_grpc" 41 | "${PROJECT_SOURCE_DIR}/../../include/include" 42 | "${PROJECT_SOURCE_DIR}/../../include/third_party/protobuf/src/" 43 | "${PROJECT_SOURCE_DIR}/../../include/third_party/protobuf" 44 | "${PROJECT_SOURCE_DIR}/model") 45 | 46 | 47 | # 生成链接库 48 | add_executable (demo-sync-server ${DIR_LIB_SRCS}) 49 | 50 | # 添加链接库 51 | target_link_libraries(demo-sync-server libgpr.so) 52 | target_link_libraries(demo-sync-server libgrpc.so) 53 | target_link_libraries(demo-sync-server libgrpc++.so) 54 | target_link_libraries(demo-sync-server libprotobuf.a) 55 | target_link_libraries(demo-sync-server libssl.so) 56 | target_link_libraries(demo-sync-server liborientsec_common.a) 57 | target_link_libraries(demo-sync-server liborientsec_provider.a) 58 | target_link_libraries(demo-sync-server liborientsec_consumer.a) 59 | target_link_libraries(demo-sync-server liborientsec_registry.a) 60 | target_link_libraries(demo-sync-server libzookeeper_mt.so) 61 | 62 | -------------------------------------------------------------------------------- /demo-sync-server/config/dfzq-grpc-config.properties: -------------------------------------------------------------------------------- 1 | # 配置信息分为五类: 2 | # 1. common config (公共配置) 3 | # 2. provider config (服务提供者需要填写) 4 | # 3. consumer config (服务消费者需要填写) 5 | # 4. kafka config (提供者、消费者都需要配置) 6 | # 5. zookeeper config (提供者、消费者都需要配置) 7 | 8 | # 配置文件的放置路径:class文件根目录 9 | # (请参照:使用log4j记日志的项目中 log4j.properties 文件的路径) 10 | 11 | 12 | # ------------ begin of common config ------------ 13 | 14 | # 必填,类型string,说明:当前应用名称 15 | common.application=grpc-test-app 16 | 17 | # 必填,类型string,说明:grpc版本号 18 | common.grpc=1.2.4 19 | 20 | #选填,默认是 grpc-test-app,说明:grpc项目名监控 21 | common.project=grpc-java 22 | 23 | # 选填,类型string,说明:服务注册根路径,默认值/Application/grpc 24 | #common.root=/Application/grpc/c++ 25 | 26 | # 必填,类型string,说明:项目负责人,员工工号,多个工号之间使用英文逗号 27 | common.owner=A9001,A9002,A9003 28 | 29 | # 可选,类型string,说明:服务注册使用的IP地址 30 | # 如果不配置该参数值,当前服务器的IP地址为"非127.0.0.1的第一个网卡的IP地址" 31 | # 使用场合:一台服务器安装有多个网卡,如果需要指定不是第一个网卡的IP地址为服务注册的IP地址 32 | #common.localhost.ip=192.168.2.123 33 | 34 | # ------------ end of common config ------------ 35 | 36 | 37 | 38 | 39 | # ------------ begin of provider config ------------ 40 | 41 | # 必填,类型string,说明:服务的版本信息,一般表示服务接口的版本号 42 | provider.version=2.0 43 | 44 | # 必填,类型String,固定值provider,说明:provider表示服务提供端,consumer表示服务消费端 45 | provider.side=provider 46 | 47 | # ---------------------------------------- 48 | 49 | # 可选,类型string,说明:当前模块名称 50 | # provider.module= 51 | 52 | # 可选,类型string,说明:服务分组信息,一般用来区分一个服务接口的多种实现(provider) 53 | # provider.group= 54 | 55 | # 可选,类型int,缺省值1000,说明:远程服务调用超时时间(毫秒) 56 | # provider.default.timeout= 57 | 58 | # 可选,类型int,缺省值2,说明:远程服务调用重试次数,不包括第一次调用,不需要重试则设置为0 59 | # provider.default.reties= 60 | 61 | # 可选,类型int,缺省值0,说明:对每个provider最大连接次数,默认最大连接数 62 | #provider.default.connections=1 63 | 64 | # 可选,类型string,缺省值round_robin,说明:负载均衡策略,可选值:pick_first、round_robin,weight_round_robin,可扩展实现其他策略 65 | # provider.default.loadbalance= 66 | 67 | # 可选,类型Boolean,缺省值false,说明:是否缺省异步执行,如果true则可直接忽略返回值,不阻塞线程 68 | # provider.default.async= 69 | #Max request 70 | #provider.default.requests=1 71 | # dataflow control 72 | #provider.default.connections=1 73 | 74 | #route rule 75 | #provider.access.protected=true 76 | 77 | 78 | # 可选,类型sting/Boolean,缺省值false,说明:令牌验证,为空表示不开启,为true则随机生成动态令牌,否则使用镜头令牌 79 | # provider.token= 80 | 81 | # 可选,类型boolean,缺省值false,说明:服务是否过时,如果为true则应用该服务时日志error告警 82 | # provider.deprecated=true 83 | 84 | # 可选,类型boolean,缺省值ture,说明:服务是否动态注册,如果为false则注册后将显示为disable状态, 85 | # 需要人工启用,且服务停止时需手动注销 86 | # provider.dynamic= 87 | 88 | # 可选,类型string/boolean,缺省值false,说明:设为true,将向logger中输出访问日志,也可填写访问 89 | # 日志文件路径,直接把访问日志输出到指定文件 90 | # provider.accesslog= 91 | 92 | # 可选,类型string,说明:服务负责人,填写负责人公司邮箱前缀 93 | # provider.owner= 94 | 95 | # 可选,类型int,缺省值100,说明:服务provider权重,是服务provider的容量,在负载均衡基于权重的选择算法中用到 96 | # provider.weight= 97 | 98 | # 可选,类型string,缺省值failover,说明:集群方式,可选:failover/failfast/failback/forking 99 | # provider.default.cluster= 100 | 101 | # 可选,类型string,说明:应用版本号 102 | # provider.application.version= 103 | 104 | # 可选,类型string,说明:组织名(BU或部门) 105 | # provider.organization= 106 | 107 | # 可选,类型string,说明:应用环境,如:develop/test/product 108 | # provider.environment= 109 | 110 | # 可选,类型string,说明:模块的版本号 111 | # provider.module.version= 112 | 113 | # 可选,类型boolean,缺省值false,说明:表示是否为跨主机访问 114 | # provider.anyhost= 115 | 116 | # 可选,类型string,说明:dubbo版本号,缺省值为grpc的版本号 117 | # provider.dubbo= 118 | 119 | # 可选, 类型boolean, 缺省值false, 说明:服务是否处于访问保护状态 120 | # 属性的可选值为false 、true ,分别表示不受保护、受保护,缺省值为false (不受保护) 121 | #provider.access.protected=true 122 | 123 | # ------------ end of provider config ------------ 124 | 125 | 126 | 127 | 128 | # ------------ begin of consumer config ------------ 129 | 130 | # 必填,类型boolean,缺省值true,说明:启动时检查提供者是否存在,true报错,false忽略 131 | consumer.check=true 132 | 133 | # 必填,类型int,固定值1000,说明:远程服务调用超时时间(毫秒) 134 | consumer.default.timeout=1000 135 | 136 | # 必填,类型String,默认值consumers,说明:所属范畴 137 | consumer.category=consumers 138 | 139 | # 必填,类型String,固定值consumer,说明:provider表示服务提供端,consumer表示服务消费端 140 | consumer.side=consumer 141 | 142 | # -------------------------- 143 | # 可选,类型string,说明:服务提供者的版本号 144 | # 指定了服务提供者的版本号之后,程序会优先选择具有指定版本的服务;如果注册中心没有该版本的服务,则不限制版本重新选择服务提供者。 145 | # 使用场景为:注册中心上同一个服务多版本共存,并且服务的高版本与低版本不兼容,而当前应用由于特殊原因只能调用低版本的服务 146 | # 如果当前应用只调用一个服务,属性值直接配置版本号,例如1.0.0 147 | # 如果当前应用需要调用多个服务,属性值按照冒号逗号的方式分隔,例如com.dfzq.examples.Greeter:1.0.0,com.dfzq.examples.Hello:1.2.1 148 | # 如果当前应用需要调用多个服务,建议在服务治理平台维护该属性,只有一个版本的服务可以不维护 149 | #consumer.service.version=helloworld.Greeter:1.0,com.dfzq.grpc.helloworld.Greeter:1.0.2 150 | 151 | # 可选,类型string,说明:应用版本号 152 | # consumer.application.version= 153 | 154 | # 可选,类型String,说明:服务消费方远程调用过程拦截器名称,多个名称用逗号分隔 155 | # consumer.default.reference.filter= 156 | 157 | # 可选,类型String,缺省值slf4j,说明:日志输出方式,可选:slf4j,jcl,log4j,jdk 158 | # consumer.logger= 159 | 160 | # 可选,类型String,说明:调用服务负责人,用于服务治理,请填写负责人公司邮箱前缀 161 | # consumer.owner= 162 | 163 | # 可选,类型string,说明:组织名(BU或部门) 164 | # consumer.organization= 165 | 166 | # 可选,类型int,缺省值2,说明:远程服务调用重试次数 167 | # consumer.default.retries= 168 | 169 | # 可选,类型string,缺省值connection,说明:负载均衡模式 170 | # 可选值为 connection 和 request,分别表示“连接负载均衡”、“请求负载均衡” 171 | # “连接负载均衡”适用于大部分业务场景,服务端和客户端消耗的资源较小。 172 | # “请求负载均衡”适用于服务端业务逻辑复杂、并有多台服务器提供相同服务的场景。 173 | consumer.loadbalance.mode=request 174 | #consumer.loadbalance.mode=connection 175 | 176 | 177 | # 可选,类型string,缺省值round_robin,说明:调度策略,可选范围:pick_first、round_robin、weight_round_robin、consistent_hash 178 | consumer.default.loadbalance=consistent_hash 179 | 180 | #the weight of provider 181 | provider.weight=1 182 | 183 | 184 | # 可选,类型string,负载均衡策略选择是consistent_hash(一致性Hash),配置进行hash运算的参数名称的列表 185 | # 多个参数之间使用英文逗号分隔,例如 id,name 186 | # 如果负载均衡策略选择是consistent_hash,但是该参数未配置参数值、或者参数值列表不正确,则随机取一个值来做散列运算 187 | 188 | consumer.consistent.hash.arguments=name,no 189 | 190 | # 可选,类型int,缺省值100,说明:每个服务对外最大连接数 191 | # consumer.default.connections= 192 | 193 | # 可选,类型string,缺省值failover,说明:集群方式,可选:failover/failfast/failback/forking 194 | # consumer.default.cluster= 195 | 196 | # 可选,类型integer,缺省值5,说明:连续多少次请求出错,自动切换到提供相同服务的新服务器 197 | consumer.switchover.threshold=5 198 | 199 | # 可选,类型为long,单位为秒,缺省值为60,说明:服务提供者不可用时的惩罚时间,即多次请求出错的服务提供者一段时间内不再去请求 200 | # 属性值大于或等于0,等于0表示没有惩罚时间,如果客户端只剩下一个服务提供者,即使服务提供者不可用,也不做剔除操作。 201 | consumer.unavailable.provider.punish.time=60 202 | # ------------ end of consumer config ------------ 203 | 204 | 205 | 206 | 207 | # ------------ begin of kafka.producer config ------------ 208 | 209 | # 转发服务跟踪信息给kafka的服务提供者的IP地址和端口 210 | # 服务跟踪信息先发送给KafkaSenderServer(一个基于原生grpc的服务),然后由KafkaSenderServer转发给kafka 211 | # 多个服务提供者之间使用英文逗号分隔,IP地址和端口使用英文冒号分隔 212 | # kafka.sender.servers=192.168.0.1:50080,192.168.0.2:50080,192.168.0.3:50080 213 | #kafka.sender.servers=127.0.0.1:50080 214 | #kafka.sender.servers=127.0.0.1:9093 215 | #kafka.sender.servers=160.6.78.133:50080 216 | 217 | # 可选,采样频率,指的是每秒采集服务链的数据条数(这里的一条理解为traceId相同的多个json串); 218 | # 默认值为空,表示所有服务链都发送到kafka; 219 | # 如果采样率的数值不为空,并且数值大于0,根据指定的采样率采集数据 220 | # 配置值可以为正整数、小数(例如0.5)、分数(例如3/1024) 221 | # kafka.sampling.frequency= 222 | 223 | # 可选, 将服务跟踪信息发送给KafkaSenderServer的线程个数 224 | # 配置值为正整数,默认值为1 225 | # kafka.sender.number=1 226 | 227 | # 可选, 服务跟踪信息消息队列的容量 228 | # 配置值为正整数,默认值为50000 229 | # message.queue.capacity=50000 230 | # -------------------------- 231 | 232 | # 可选,每个RecordBatch可以缓存的最大字节数 233 | # kafka.producer.batch.size=16384 234 | 235 | # 可选,所有RecordBatch的总共最大字节数 236 | # kafka.producer.buffer.memory=33554432 237 | 238 | # 可选,每个RecordBatch的最长延迟发送时间 239 | # kafka.producer.linger.ms=1 240 | 241 | # 可选,每个RecordBatch的最长阻塞时间 242 | # kafka.producer.max.block.ms=1 243 | 244 | # 可选,消息发送失败重试的次数 245 | # kafka.producer.retries=0 246 | 247 | # 可选,失败补偿时间,每次失败重试的时间间隔,不可设置太短,避免第一条消息的响应还没返回,第二条消息又发出去了,造成逻辑错误 248 | # kafka.producer.retry.backoff.ms 249 | 250 | # 可选,同一时间,producer到broker的一个连接上允许的最大未确认请求数,默认为5 251 | # kafka.producer.max.in.flight.requests.per.connection=5 252 | 253 | # 可选,采样频率,指的是每秒向kafka写服务链的数据条数(这里的一条理解为traceId相同的多个json串); 254 | # 默认值为空,表示所有服务链都发送到kafka; 255 | # 如果采样率的数值不为空,并且数值大于0,根据指定的采样率采集数据 256 | # 配置值可以为正整数、小数(例如0.5)、分数(例如3/1024) 257 | #kafka.sampling.frequency=0.5 258 | 259 | # ------------ end of kafka.producer config ------------ 260 | 261 | 262 | 263 | 264 | # ------------ begin of zookeeper config ------------ 265 | 266 | # zookeeper主机列表 267 | #zookeeper.host.server=192.168.207.4:2181,192.168.207.6:2181 268 | zookeeper.host.server=192.168.2.103:2181 269 | #zookeeper.host.server=160.6.78.133:2181 270 | 271 | #重试次数 272 | zookeeper.retryNum=5 273 | 274 | #连接超时时间 275 | zookeeper.connectiontimeout=5000 276 | 277 | 278 | # 可选,类型string,访问控制用户名 279 | zookeeper.acl.username=admin 280 | 281 | # 可选,类型string,访问控制密码 282 | # 这里的密码配置的是密文,使用com.orientsec.grpc.common.util.DesEncryptUtils#encrypt(String plaintext)进行加密 283 | #zookeeper.acl.password=9b579c35ca6cc74230f1eed29064d10a 284 | zookeeper.acl.password=9883c580ae8226f0dd8200620e4bc899 285 | 286 | 287 | 288 | # ------------ end of zookeeper config ------------ 289 | 290 | 291 | writekafka.enabled=false 292 | #kafka.sender.servers=127.0.0.1:50080,192.168.226.128:50080 293 | 294 | kafka.sender.servers=127.0.0.1:50080 295 | -------------------------------------------------------------------------------- /demo-sync-server/demo-sync-server.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Orient Securities Co., Ltd. 3 | * Copyright 2019 BoCloud Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | #ifdef BAZEL_BUILD 25 | #include "examples/protos/helloworld.grpc.pb.h" 26 | #else 27 | #include "helloworld.grpc.pb.h" 28 | #endif 29 | 30 | using grpc::Server; 31 | using grpc::ServerBuilder; 32 | using grpc::ServerContext; 33 | using grpc::Status; 34 | using helloworld::HelloRequest; 35 | using helloworld::HelloReply; 36 | using helloworld::Greeter; 37 | 38 | static int invoke_count = 0; 39 | // Logic and data behind the server's behavior. 40 | class GreeterServiceImpl final : public Greeter::Service { 41 | Status SayHello(ServerContext* context, const HelloRequest* request, 42 | HelloReply* reply) override { 43 | std::string prefix("Hello "); 44 | reply->set_message(prefix + request->name()); 45 | 46 | std::cout << "\n Service is Called ... " << request->name() << "\n" << std::endl; 47 | invoke_count++; 48 | std::cout << "invoke_count = " << invoke_count << std::endl; 49 | return Status::OK; 50 | } 51 | }; 52 | 53 | void RunServer() { 54 | std::string server_address("0.0.0.0:50066"); 55 | GreeterServiceImpl service; 56 | 57 | ServerBuilder builder; 58 | // Listen on the given address without any authentication mechanism. 59 | builder.AddListeningPort(server_address, grpc::InsecureServerCredentials()); 60 | // Register "service" as the instance through which we'll communicate with 61 | // clients. In this case it corresponds to an *synchronous* service. 62 | builder.RegisterService(&service); 63 | // Finally assemble the server. 64 | std::unique_ptr server(builder.BuildAndStart()); 65 | std::cout << "Server listening on " << server_address << std::endl; 66 | 67 | // Wait for the server to shutdown. Note that some other thread must be 68 | // responsible for shutting down the server for this call to ever return. 69 | server->Wait(); 70 | } 71 | 72 | int main(int argc, char** argv) { 73 | RunServer(); 74 | 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /demo-sync-server/helloworld.grpc.pb.cc: -------------------------------------------------------------------------------- 1 | // Generated by the gRPC C++ plugin. 2 | // If you make any local change, they will be lost. 3 | // source: helloworld.proto 4 | 5 | #include "helloworld.pb.h" 6 | #include "helloworld.grpc.pb.h" 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | namespace helloworld { 20 | 21 | static const char* Greeter_method_names[] = { 22 | "/helloworld.Greeter/SayHello", 23 | }; 24 | 25 | std::unique_ptr< Greeter::Stub> Greeter::NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options) { 26 | (void)options; 27 | std::unique_ptr< Greeter::Stub> stub(new Greeter::Stub(channel)); 28 | return stub; 29 | } 30 | 31 | Greeter::Stub::Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel) 32 | : channel_(channel), rpcmethod_SayHello_(Greeter_method_names[0], ::grpc::internal::RpcMethod::NORMAL_RPC, channel) 33 | {} 34 | 35 | ::grpc::Status Greeter::Stub::SayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::helloworld::HelloReply* response) { 36 | return ::grpc::internal::BlockingUnaryCall(channel_.get(), rpcmethod_SayHello_, context, request, response); 37 | } 38 | 39 | void Greeter::Stub::experimental_async::SayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response, std::function f) { 40 | return ::grpc::internal::CallbackUnaryCall(stub_->channel_.get(), stub_->rpcmethod_SayHello_, context, request, response, std::move(f)); 41 | } 42 | 43 | ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>* Greeter::Stub::AsyncSayHelloRaw(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) { 44 | return ::grpc::internal::ClientAsyncResponseReaderFactory< ::helloworld::HelloReply>::Create(channel_.get(), cq, rpcmethod_SayHello_, context, request, true); 45 | } 46 | 47 | ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>* Greeter::Stub::PrepareAsyncSayHelloRaw(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) { 48 | return ::grpc::internal::ClientAsyncResponseReaderFactory< ::helloworld::HelloReply>::Create(channel_.get(), cq, rpcmethod_SayHello_, context, request, false); 49 | } 50 | 51 | Greeter::Service::Service() { 52 | AddMethod(new ::grpc::internal::RpcServiceMethod( 53 | Greeter_method_names[0], 54 | ::grpc::internal::RpcMethod::NORMAL_RPC, 55 | new ::grpc::internal::RpcMethodHandler< Greeter::Service, ::helloworld::HelloRequest, ::helloworld::HelloReply>( 56 | std::mem_fn(&Greeter::Service::SayHello), this))); 57 | } 58 | 59 | Greeter::Service::~Service() { 60 | } 61 | 62 | ::grpc::Status Greeter::Service::SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response) { 63 | (void) context; 64 | (void) request; 65 | (void) response; 66 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 67 | } 68 | 69 | 70 | } // namespace helloworld 71 | 72 | -------------------------------------------------------------------------------- /demo-sync-server/helloworld.grpc.pb.h: -------------------------------------------------------------------------------- 1 | // Generated by the gRPC C++ plugin. 2 | // If you make any local change, they will be lost. 3 | // source: helloworld.proto 4 | // Original file comments: 5 | // Copyright 2015 gRPC authors. 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | #ifndef GRPC_helloworld_2eproto__INCLUDED 20 | #define GRPC_helloworld_2eproto__INCLUDED 21 | 22 | #include "helloworld.pb.h" 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | namespace grpc { 38 | class CompletionQueue; 39 | class Channel; 40 | class ServerCompletionQueue; 41 | class ServerContext; 42 | } // namespace grpc 43 | 44 | namespace helloworld { 45 | 46 | // The greeting service definition. 47 | class Greeter final { 48 | public: 49 | static constexpr char const* service_full_name() { 50 | return "helloworld.Greeter"; 51 | } 52 | class StubInterface { 53 | public: 54 | virtual ~StubInterface() {} 55 | // Sends a greeting 56 | virtual ::grpc::Status SayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::helloworld::HelloReply* response) = 0; 57 | std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::helloworld::HelloReply>> AsyncSayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) { 58 | return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::helloworld::HelloReply>>(AsyncSayHelloRaw(context, request, cq)); 59 | } 60 | std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::helloworld::HelloReply>> PrepareAsyncSayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) { 61 | return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::helloworld::HelloReply>>(PrepareAsyncSayHelloRaw(context, request, cq)); 62 | } 63 | class experimental_async_interface { 64 | public: 65 | virtual ~experimental_async_interface() {} 66 | // Sends a greeting 67 | virtual void SayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response, std::function) = 0; 68 | }; 69 | virtual class experimental_async_interface* experimental_async() { return nullptr; } 70 | private: 71 | virtual ::grpc::ClientAsyncResponseReaderInterface< ::helloworld::HelloReply>* AsyncSayHelloRaw(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) = 0; 72 | virtual ::grpc::ClientAsyncResponseReaderInterface< ::helloworld::HelloReply>* PrepareAsyncSayHelloRaw(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) = 0; 73 | }; 74 | class Stub final : public StubInterface { 75 | public: 76 | Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel); 77 | ::grpc::Status SayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::helloworld::HelloReply* response) override; 78 | std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>> AsyncSayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) { 79 | return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>>(AsyncSayHelloRaw(context, request, cq)); 80 | } 81 | std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>> PrepareAsyncSayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) { 82 | return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>>(PrepareAsyncSayHelloRaw(context, request, cq)); 83 | } 84 | class experimental_async final : 85 | public StubInterface::experimental_async_interface { 86 | public: 87 | void SayHello(::grpc::ClientContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response, std::function) override; 88 | private: 89 | friend class Stub; 90 | explicit experimental_async(Stub* stub): stub_(stub) { } 91 | Stub* stub() { return stub_; } 92 | Stub* stub_; 93 | }; 94 | class experimental_async_interface* experimental_async() override { return &async_stub_; } 95 | 96 | private: 97 | std::shared_ptr< ::grpc::ChannelInterface> channel_; 98 | class experimental_async async_stub_{this}; 99 | ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>* AsyncSayHelloRaw(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) override; 100 | ::grpc::ClientAsyncResponseReader< ::helloworld::HelloReply>* PrepareAsyncSayHelloRaw(::grpc::ClientContext* context, const ::helloworld::HelloRequest& request, ::grpc::CompletionQueue* cq) override; 101 | const ::grpc::internal::RpcMethod rpcmethod_SayHello_; 102 | }; 103 | static std::unique_ptr NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options = ::grpc::StubOptions()); 104 | 105 | class Service : public ::grpc::Service { 106 | public: 107 | Service(); 108 | virtual ~Service(); 109 | // Sends a greeting 110 | virtual ::grpc::Status SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response); 111 | }; 112 | template 113 | class WithAsyncMethod_SayHello : public BaseClass { 114 | private: 115 | void BaseClassMustBeDerivedFromService(const Service *service) {} 116 | public: 117 | WithAsyncMethod_SayHello() { 118 | ::grpc::Service::MarkMethodAsync(0); 119 | } 120 | ~WithAsyncMethod_SayHello() override { 121 | BaseClassMustBeDerivedFromService(this); 122 | } 123 | // disable synchronous version of this method 124 | ::grpc::Status SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response) override { 125 | abort(); 126 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 127 | } 128 | void RequestSayHello(::grpc::ServerContext* context, ::helloworld::HelloRequest* request, ::grpc::ServerAsyncResponseWriter< ::helloworld::HelloReply>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { 129 | ::grpc::Service::RequestAsyncUnary(0, context, request, response, new_call_cq, notification_cq, tag); 130 | } 131 | }; 132 | typedef WithAsyncMethod_SayHello AsyncService; 133 | template 134 | class ExperimentalWithCallbackMethod_SayHello : public BaseClass { 135 | private: 136 | void BaseClassMustBeDerivedFromService(const Service *service) {} 137 | public: 138 | ExperimentalWithCallbackMethod_SayHello() { 139 | ::grpc::Service::experimental().MarkMethodCallback(0, 140 | new ::grpc::internal::CallbackUnaryHandler< ExperimentalWithCallbackMethod_SayHello, ::helloworld::HelloRequest, ::helloworld::HelloReply>( 141 | [this](::grpc::ServerContext* context, 142 | const ::helloworld::HelloRequest* request, 143 | ::helloworld::HelloReply* response, 144 | ::grpc::experimental::ServerCallbackRpcController* controller) { 145 | this->SayHello(context, request, response, controller); 146 | }, this)); 147 | } 148 | ~ExperimentalWithCallbackMethod_SayHello() override { 149 | BaseClassMustBeDerivedFromService(this); 150 | } 151 | // disable synchronous version of this method 152 | ::grpc::Status SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response) override { 153 | abort(); 154 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 155 | } 156 | virtual void SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response, ::grpc::experimental::ServerCallbackRpcController* controller) { controller->Finish(::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "")); } 157 | }; 158 | typedef ExperimentalWithCallbackMethod_SayHello ExperimentalCallbackService; 159 | template 160 | class WithGenericMethod_SayHello : public BaseClass { 161 | private: 162 | void BaseClassMustBeDerivedFromService(const Service *service) {} 163 | public: 164 | WithGenericMethod_SayHello() { 165 | ::grpc::Service::MarkMethodGeneric(0); 166 | } 167 | ~WithGenericMethod_SayHello() override { 168 | BaseClassMustBeDerivedFromService(this); 169 | } 170 | // disable synchronous version of this method 171 | ::grpc::Status SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response) override { 172 | abort(); 173 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 174 | } 175 | }; 176 | template 177 | class WithRawMethod_SayHello : public BaseClass { 178 | private: 179 | void BaseClassMustBeDerivedFromService(const Service *service) {} 180 | public: 181 | WithRawMethod_SayHello() { 182 | ::grpc::Service::MarkMethodRaw(0); 183 | } 184 | ~WithRawMethod_SayHello() override { 185 | BaseClassMustBeDerivedFromService(this); 186 | } 187 | // disable synchronous version of this method 188 | ::grpc::Status SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response) override { 189 | abort(); 190 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 191 | } 192 | void RequestSayHello(::grpc::ServerContext* context, ::grpc::ByteBuffer* request, ::grpc::ServerAsyncResponseWriter< ::grpc::ByteBuffer>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { 193 | ::grpc::Service::RequestAsyncUnary(0, context, request, response, new_call_cq, notification_cq, tag); 194 | } 195 | }; 196 | template 197 | class ExperimentalWithRawCallbackMethod_SayHello : public BaseClass { 198 | private: 199 | void BaseClassMustBeDerivedFromService(const Service *service) {} 200 | public: 201 | ExperimentalWithRawCallbackMethod_SayHello() { 202 | ::grpc::Service::experimental().MarkMethodRawCallback(0, 203 | new ::grpc::internal::CallbackUnaryHandler< ExperimentalWithRawCallbackMethod_SayHello, ::grpc::ByteBuffer, ::grpc::ByteBuffer>( 204 | [this](::grpc::ServerContext* context, 205 | const ::grpc::ByteBuffer* request, 206 | ::grpc::ByteBuffer* response, 207 | ::grpc::experimental::ServerCallbackRpcController* controller) { 208 | this->SayHello(context, request, response, controller); 209 | }, this)); 210 | } 211 | ~ExperimentalWithRawCallbackMethod_SayHello() override { 212 | BaseClassMustBeDerivedFromService(this); 213 | } 214 | // disable synchronous version of this method 215 | ::grpc::Status SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response) override { 216 | abort(); 217 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 218 | } 219 | virtual void SayHello(::grpc::ServerContext* context, const ::grpc::ByteBuffer* request, ::grpc::ByteBuffer* response, ::grpc::experimental::ServerCallbackRpcController* controller) { controller->Finish(::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "")); } 220 | }; 221 | template 222 | class WithStreamedUnaryMethod_SayHello : public BaseClass { 223 | private: 224 | void BaseClassMustBeDerivedFromService(const Service *service) {} 225 | public: 226 | WithStreamedUnaryMethod_SayHello() { 227 | ::grpc::Service::MarkMethodStreamed(0, 228 | new ::grpc::internal::StreamedUnaryHandler< ::helloworld::HelloRequest, ::helloworld::HelloReply>(std::bind(&WithStreamedUnaryMethod_SayHello::StreamedSayHello, this, std::placeholders::_1, std::placeholders::_2))); 229 | } 230 | ~WithStreamedUnaryMethod_SayHello() override { 231 | BaseClassMustBeDerivedFromService(this); 232 | } 233 | // disable regular version of this method 234 | ::grpc::Status SayHello(::grpc::ServerContext* context, const ::helloworld::HelloRequest* request, ::helloworld::HelloReply* response) override { 235 | abort(); 236 | return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); 237 | } 238 | // replace default version of method with streamed unary 239 | virtual ::grpc::Status StreamedSayHello(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer< ::helloworld::HelloRequest,::helloworld::HelloReply>* server_unary_streamer) = 0; 240 | }; 241 | typedef WithStreamedUnaryMethod_SayHello StreamedUnaryService; 242 | typedef Service SplitStreamedService; 243 | typedef WithStreamedUnaryMethod_SayHello StreamedService; 244 | }; 245 | 246 | } // namespace helloworld 247 | 248 | 249 | #endif // GRPC_helloworld_2eproto__INCLUDED 250 | -------------------------------------------------------------------------------- /demo-sync-server/helloworld.pb.h: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: helloworld.proto 3 | 4 | #ifndef PROTOBUF_INCLUDED_helloworld_2eproto 5 | #define PROTOBUF_INCLUDED_helloworld_2eproto 6 | 7 | #include 8 | 9 | #include 10 | 11 | #if GOOGLE_PROTOBUF_VERSION < 3006001 12 | #error This file was generated by a newer version of protoc which is 13 | #error incompatible with your Protocol Buffer headers. Please update 14 | #error your headers. 15 | #endif 16 | #if 3006001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 17 | #error This file was generated by an older version of protoc which is 18 | #error incompatible with your Protocol Buffer headers. Please 19 | #error regenerate this file with a newer version of protoc. 20 | #endif 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include // IWYU pragma: export 31 | #include // IWYU pragma: export 32 | #include 33 | // @@protoc_insertion_point(includes) 34 | #define PROTOBUF_INTERNAL_EXPORT_protobuf_helloworld_2eproto 35 | 36 | namespace protobuf_helloworld_2eproto { 37 | // Internal implementation detail -- do not use these members. 38 | struct TableStruct { 39 | static const ::google::protobuf::internal::ParseTableField entries[]; 40 | static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; 41 | static const ::google::protobuf::internal::ParseTable schema[2]; 42 | static const ::google::protobuf::internal::FieldMetadata field_metadata[]; 43 | static const ::google::protobuf::internal::SerializationTable serialization_table[]; 44 | static const ::google::protobuf::uint32 offsets[]; 45 | }; 46 | void AddDescriptors(); 47 | } // namespace protobuf_helloworld_2eproto 48 | namespace helloworld { 49 | class HelloReply; 50 | class HelloReplyDefaultTypeInternal; 51 | extern HelloReplyDefaultTypeInternal _HelloReply_default_instance_; 52 | class HelloRequest; 53 | class HelloRequestDefaultTypeInternal; 54 | extern HelloRequestDefaultTypeInternal _HelloRequest_default_instance_; 55 | } // namespace helloworld 56 | namespace google { 57 | namespace protobuf { 58 | template<> ::helloworld::HelloReply* Arena::CreateMaybeMessage<::helloworld::HelloReply>(Arena*); 59 | template<> ::helloworld::HelloRequest* Arena::CreateMaybeMessage<::helloworld::HelloRequest>(Arena*); 60 | } // namespace protobuf 61 | } // namespace google 62 | namespace helloworld { 63 | 64 | // =================================================================== 65 | 66 | class HelloRequest : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:helloworld.HelloRequest) */ { 67 | public: 68 | HelloRequest(); 69 | virtual ~HelloRequest(); 70 | 71 | HelloRequest(const HelloRequest& from); 72 | 73 | inline HelloRequest& operator=(const HelloRequest& from) { 74 | CopyFrom(from); 75 | return *this; 76 | } 77 | #if LANG_CXX11 78 | HelloRequest(HelloRequest&& from) noexcept 79 | : HelloRequest() { 80 | *this = ::std::move(from); 81 | } 82 | 83 | inline HelloRequest& operator=(HelloRequest&& from) noexcept { 84 | if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { 85 | if (this != &from) InternalSwap(&from); 86 | } else { 87 | CopyFrom(from); 88 | } 89 | return *this; 90 | } 91 | #endif 92 | static const ::google::protobuf::Descriptor* descriptor(); 93 | static const HelloRequest& default_instance(); 94 | 95 | static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY 96 | static inline const HelloRequest* internal_default_instance() { 97 | return reinterpret_cast( 98 | &_HelloRequest_default_instance_); 99 | } 100 | static constexpr int kIndexInFileMessages = 101 | 0; 102 | 103 | void Swap(HelloRequest* other); 104 | friend void swap(HelloRequest& a, HelloRequest& b) { 105 | a.Swap(&b); 106 | } 107 | 108 | // implements Message ---------------------------------------------- 109 | 110 | inline HelloRequest* New() const final { 111 | return CreateMaybeMessage(NULL); 112 | } 113 | 114 | HelloRequest* New(::google::protobuf::Arena* arena) const final { 115 | return CreateMaybeMessage(arena); 116 | } 117 | void CopyFrom(const ::google::protobuf::Message& from) final; 118 | void MergeFrom(const ::google::protobuf::Message& from) final; 119 | void CopyFrom(const HelloRequest& from); 120 | void MergeFrom(const HelloRequest& from); 121 | void Clear() final; 122 | bool IsInitialized() const final; 123 | 124 | size_t ByteSizeLong() const final; 125 | bool MergePartialFromCodedStream( 126 | ::google::protobuf::io::CodedInputStream* input) final; 127 | void SerializeWithCachedSizes( 128 | ::google::protobuf::io::CodedOutputStream* output) const final; 129 | ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( 130 | bool deterministic, ::google::protobuf::uint8* target) const final; 131 | int GetCachedSize() const final { return _cached_size_.Get(); } 132 | 133 | private: 134 | void SharedCtor(); 135 | void SharedDtor(); 136 | void SetCachedSize(int size) const final; 137 | void InternalSwap(HelloRequest* other); 138 | private: 139 | inline ::google::protobuf::Arena* GetArenaNoVirtual() const { 140 | return NULL; 141 | } 142 | inline void* MaybeArenaPtr() const { 143 | return NULL; 144 | } 145 | public: 146 | 147 | ::google::protobuf::Metadata GetMetadata() const final; 148 | 149 | // nested types ---------------------------------------------------- 150 | 151 | // accessors ------------------------------------------------------- 152 | 153 | // string name = 1; 154 | void clear_name(); 155 | static const int kNameFieldNumber = 1; 156 | const ::std::string& name() const; 157 | void set_name(const ::std::string& value); 158 | #if LANG_CXX11 159 | void set_name(::std::string&& value); 160 | #endif 161 | void set_name(const char* value); 162 | void set_name(const char* value, size_t size); 163 | ::std::string* mutable_name(); 164 | ::std::string* release_name(); 165 | void set_allocated_name(::std::string* name); 166 | 167 | // @@protoc_insertion_point(class_scope:helloworld.HelloRequest) 168 | private: 169 | 170 | ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; 171 | ::google::protobuf::internal::ArenaStringPtr name_; 172 | mutable ::google::protobuf::internal::CachedSize _cached_size_; 173 | friend struct ::protobuf_helloworld_2eproto::TableStruct; 174 | }; 175 | // ------------------------------------------------------------------- 176 | 177 | class HelloReply : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:helloworld.HelloReply) */ { 178 | public: 179 | HelloReply(); 180 | virtual ~HelloReply(); 181 | 182 | HelloReply(const HelloReply& from); 183 | 184 | inline HelloReply& operator=(const HelloReply& from) { 185 | CopyFrom(from); 186 | return *this; 187 | } 188 | #if LANG_CXX11 189 | HelloReply(HelloReply&& from) noexcept 190 | : HelloReply() { 191 | *this = ::std::move(from); 192 | } 193 | 194 | inline HelloReply& operator=(HelloReply&& from) noexcept { 195 | if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { 196 | if (this != &from) InternalSwap(&from); 197 | } else { 198 | CopyFrom(from); 199 | } 200 | return *this; 201 | } 202 | #endif 203 | static const ::google::protobuf::Descriptor* descriptor(); 204 | static const HelloReply& default_instance(); 205 | 206 | static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY 207 | static inline const HelloReply* internal_default_instance() { 208 | return reinterpret_cast( 209 | &_HelloReply_default_instance_); 210 | } 211 | static constexpr int kIndexInFileMessages = 212 | 1; 213 | 214 | void Swap(HelloReply* other); 215 | friend void swap(HelloReply& a, HelloReply& b) { 216 | a.Swap(&b); 217 | } 218 | 219 | // implements Message ---------------------------------------------- 220 | 221 | inline HelloReply* New() const final { 222 | return CreateMaybeMessage(NULL); 223 | } 224 | 225 | HelloReply* New(::google::protobuf::Arena* arena) const final { 226 | return CreateMaybeMessage(arena); 227 | } 228 | void CopyFrom(const ::google::protobuf::Message& from) final; 229 | void MergeFrom(const ::google::protobuf::Message& from) final; 230 | void CopyFrom(const HelloReply& from); 231 | void MergeFrom(const HelloReply& from); 232 | void Clear() final; 233 | bool IsInitialized() const final; 234 | 235 | size_t ByteSizeLong() const final; 236 | bool MergePartialFromCodedStream( 237 | ::google::protobuf::io::CodedInputStream* input) final; 238 | void SerializeWithCachedSizes( 239 | ::google::protobuf::io::CodedOutputStream* output) const final; 240 | ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( 241 | bool deterministic, ::google::protobuf::uint8* target) const final; 242 | int GetCachedSize() const final { return _cached_size_.Get(); } 243 | 244 | private: 245 | void SharedCtor(); 246 | void SharedDtor(); 247 | void SetCachedSize(int size) const final; 248 | void InternalSwap(HelloReply* other); 249 | private: 250 | inline ::google::protobuf::Arena* GetArenaNoVirtual() const { 251 | return NULL; 252 | } 253 | inline void* MaybeArenaPtr() const { 254 | return NULL; 255 | } 256 | public: 257 | 258 | ::google::protobuf::Metadata GetMetadata() const final; 259 | 260 | // nested types ---------------------------------------------------- 261 | 262 | // accessors ------------------------------------------------------- 263 | 264 | // string message = 1; 265 | void clear_message(); 266 | static const int kMessageFieldNumber = 1; 267 | const ::std::string& message() const; 268 | void set_message(const ::std::string& value); 269 | #if LANG_CXX11 270 | void set_message(::std::string&& value); 271 | #endif 272 | void set_message(const char* value); 273 | void set_message(const char* value, size_t size); 274 | ::std::string* mutable_message(); 275 | ::std::string* release_message(); 276 | void set_allocated_message(::std::string* message); 277 | 278 | // @@protoc_insertion_point(class_scope:helloworld.HelloReply) 279 | private: 280 | 281 | ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; 282 | ::google::protobuf::internal::ArenaStringPtr message_; 283 | mutable ::google::protobuf::internal::CachedSize _cached_size_; 284 | friend struct ::protobuf_helloworld_2eproto::TableStruct; 285 | }; 286 | // =================================================================== 287 | 288 | 289 | // =================================================================== 290 | 291 | #ifdef __GNUC__ 292 | #pragma GCC diagnostic push 293 | #pragma GCC diagnostic ignored "-Wstrict-aliasing" 294 | #endif // __GNUC__ 295 | // HelloRequest 296 | 297 | // string name = 1; 298 | inline void HelloRequest::clear_name() { 299 | name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 300 | } 301 | inline const ::std::string& HelloRequest::name() const { 302 | // @@protoc_insertion_point(field_get:helloworld.HelloRequest.name) 303 | return name_.GetNoArena(); 304 | } 305 | inline void HelloRequest::set_name(const ::std::string& value) { 306 | 307 | name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); 308 | // @@protoc_insertion_point(field_set:helloworld.HelloRequest.name) 309 | } 310 | #if LANG_CXX11 311 | inline void HelloRequest::set_name(::std::string&& value) { 312 | 313 | name_.SetNoArena( 314 | &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); 315 | // @@protoc_insertion_point(field_set_rvalue:helloworld.HelloRequest.name) 316 | } 317 | #endif 318 | inline void HelloRequest::set_name(const char* value) { 319 | GOOGLE_DCHECK(value != NULL); 320 | 321 | name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); 322 | // @@protoc_insertion_point(field_set_char:helloworld.HelloRequest.name) 323 | } 324 | inline void HelloRequest::set_name(const char* value, size_t size) { 325 | 326 | name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), 327 | ::std::string(reinterpret_cast(value), size)); 328 | // @@protoc_insertion_point(field_set_pointer:helloworld.HelloRequest.name) 329 | } 330 | inline ::std::string* HelloRequest::mutable_name() { 331 | 332 | // @@protoc_insertion_point(field_mutable:helloworld.HelloRequest.name) 333 | return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 334 | } 335 | inline ::std::string* HelloRequest::release_name() { 336 | // @@protoc_insertion_point(field_release:helloworld.HelloRequest.name) 337 | 338 | return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 339 | } 340 | inline void HelloRequest::set_allocated_name(::std::string* name) { 341 | if (name != NULL) { 342 | 343 | } else { 344 | 345 | } 346 | name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); 347 | // @@protoc_insertion_point(field_set_allocated:helloworld.HelloRequest.name) 348 | } 349 | 350 | // ------------------------------------------------------------------- 351 | 352 | // HelloReply 353 | 354 | // string message = 1; 355 | inline void HelloReply::clear_message() { 356 | message_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 357 | } 358 | inline const ::std::string& HelloReply::message() const { 359 | // @@protoc_insertion_point(field_get:helloworld.HelloReply.message) 360 | return message_.GetNoArena(); 361 | } 362 | inline void HelloReply::set_message(const ::std::string& value) { 363 | 364 | message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); 365 | // @@protoc_insertion_point(field_set:helloworld.HelloReply.message) 366 | } 367 | #if LANG_CXX11 368 | inline void HelloReply::set_message(::std::string&& value) { 369 | 370 | message_.SetNoArena( 371 | &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); 372 | // @@protoc_insertion_point(field_set_rvalue:helloworld.HelloReply.message) 373 | } 374 | #endif 375 | inline void HelloReply::set_message(const char* value) { 376 | GOOGLE_DCHECK(value != NULL); 377 | 378 | message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); 379 | // @@protoc_insertion_point(field_set_char:helloworld.HelloReply.message) 380 | } 381 | inline void HelloReply::set_message(const char* value, size_t size) { 382 | 383 | message_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), 384 | ::std::string(reinterpret_cast(value), size)); 385 | // @@protoc_insertion_point(field_set_pointer:helloworld.HelloReply.message) 386 | } 387 | inline ::std::string* HelloReply::mutable_message() { 388 | 389 | // @@protoc_insertion_point(field_mutable:helloworld.HelloReply.message) 390 | return message_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 391 | } 392 | inline ::std::string* HelloReply::release_message() { 393 | // @@protoc_insertion_point(field_release:helloworld.HelloReply.message) 394 | 395 | return message_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); 396 | } 397 | inline void HelloReply::set_allocated_message(::std::string* message) { 398 | if (message != NULL) { 399 | 400 | } else { 401 | 402 | } 403 | message_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), message); 404 | // @@protoc_insertion_point(field_set_allocated:helloworld.HelloReply.message) 405 | } 406 | 407 | #ifdef __GNUC__ 408 | #pragma GCC diagnostic pop 409 | #endif // __GNUC__ 410 | // ------------------------------------------------------------------- 411 | 412 | 413 | // @@protoc_insertion_point(namespace_scope) 414 | 415 | } // namespace helloworld 416 | 417 | // @@protoc_insertion_point(global_scope) 418 | 419 | #endif // PROTOBUF_INCLUDED_helloworld_2eproto 420 | -------------------------------------------------------------------------------- /demo-sync-server/helloworld.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2015 gRPC authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | option java_multiple_files = true; 18 | option java_package = "io.grpc.examples.helloworld"; 19 | option java_outer_classname = "HelloWorldProto"; 20 | option objc_class_prefix = "HLW"; 21 | 22 | package helloworld; 23 | 24 | // The greeting service definition. 25 | service Greeter { 26 | // Sends a greeting 27 | rpc SayHello (HelloRequest) returns (HelloReply) {} 28 | } 29 | 30 | // The request message containing the user's name. 31 | message HelloRequest { 32 | string name = 1; 33 | } 34 | 35 | // The response message containing the greetings 36 | message HelloReply { 37 | string message = 1; 38 | } 39 | --------------------------------------------------------------------------------