中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

成都html5網(wǎng)站建設(shè)市場運營和市場營銷的區(qū)別

成都html5網(wǎng)站建設(shè),市場運營和市場營銷的區(qū)別,設(shè)置網(wǎng)站標(biāo)簽,塘沽做網(wǎng)站spring 和 grpc 的整合 首先我們要知道 grpc 中我們在使用的時候用到了 grpc 的那些東西 dil 的編寫serverimplserverbuilder addService 客戶端的 stub 編寫 這里面我們看一下我們那些地方可能需要 spring 幫我們管理,那些地方我們需要自己來管理呢?…

spring 和 grpc 的整合

首先我們要知道 grpc 中我們在使用的時候用到了 grpc 的那些東西

  • dil 的編寫
  • serverimpl
  • serverbuilder
    • addService
  • 客戶端的 stub 編寫

這里面我們看一下我們那些地方可能需要 spring 幫我們管理,那些地方我們需要自己來管理呢?比如服務(wù)的構(gòu)建 spring 是可以幫我么做的,而且 addServer 可以通過注解的方式自動發(fā)布服務(wù),但是 server 的 imp 我們是需要自己來實現(xiàn)的,服務(wù)的端口可以通過 properties 的方式來做自動配置和默認(rèn)值的設(shè)置。注解的標(biāo)識 spring 使用 @GrpcService

服務(wù)端搭建開發(fā)環(huán)境

  1. spring的開發(fā)環(huán)境我們需要搭建,這個可以直接在 idea 創(chuàng)建,我就不記錄和展示
  2. 引入 grpc spring 相關(guān)的依賴
<dependency><groupId>net.devh</groupId><artifactId>grpc-server-spring-boot-starter</artifactId><version>2.15.0.RELEASE</version><exclusions><exclusion><groupId>com.google.protobuf</groupId><artifactId>protobuf-java</artifactId></exclusion></exclusions>
</dependency><dependency><groupId>com.google.protobuf</groupId><artifactId>protobuf-java</artifactId><version>3.25.5</version>
</dependency>

因為這是一個 grpc 的 server 所以并不需要使用 java-web 相關(guān)的服務(wù),我們可以移除相關(guān)的依賴,并且在配置中禁用 web 相關(guān)的內(nèi)容

配置 & 移除 web 相關(guān)的內(nèi)容

grpc:server:port: 8888-- 禁用 web 的服務(wù)
spring:application:name: grpc-servermain:web-application-type: none
server:port: 9999

移除對應(yīng)的依賴在 pom 文件中

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><exclusions><exclusion><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-tomcat</artifactId></exclusion><exclusion><artifactId>logback-classic</artifactId><groupId>ch.qos.logback</groupId></exclusion></exclusions>
</dependency>

這個時候我們就可以使用了,使用注解 @GrpcServer 使其在 springboot 中可以被注入 IOC 容器,然后就是很傳統(tǒng)的實現(xiàn) **ImplBase 并且她也會幫我們把這個服務(wù)發(fā)布到 GRPC 服務(wù)中 addServer 這樣 springboot 啟動就會自動提供服務(wù)接受 grpc client 發(fā)送來的請求。

@GrpcService
public class OnceMessageServiceImpl extends BiRpcServiceGrpc.BiRpcServiceImplBase {private final Logger log = LoggerFactory.getLogger(OnceMessageServiceImpl.class);@Overridepublic void getOnceMessage(final BiService.OnceMessageRequest request, final StreamObserver<BiService.OnceMessageResponse> responseObserver) {log.info("receive client request msg -> {}", request.getContent());responseObserver.onNext(BiService.OnceMessageResponse.newBuilder().setContent(UUID.randomUUID().toString()).build());responseObserver.onCompleted();}
}
syntax = "proto3";option java_package = "com.rpc.grpc.bi";
option java_multiple_files = false;
option java_outer_classname = "BiService";message OnceMessageRequest {string content = 1;
}message OnceMessageResponse {string content = 1;
}service BiRpcService {// 注意這里因為我們使用 future 的方式來通訊,這就不可以使用 stream,只能使用簡單的 rpcrpc getOnceMessage(OnceMessageRequest) returns (OnceMessageResponse) {}
}service NewBiRpcService {// 注意這里因為我們使用 future 的方式來通訊,這就不可以使用 stream,只能使用簡單的 rpcrpc newGetOnceMessage(OnceMessageRequest) returns (OnceMessageResponse) {}
}

客戶端搭建

引入依賴

<dependency><groupId>net.devh</groupId><artifactId>grpc-client-spring-boot-starter</artifactId><version>3.0.0.RELEASE</version>
</dependency>

增加配置

spring:application:name: grpc-rpc-boot-client
grpc:client:bi_server:address: static://localhost:8888negotiation-type: plaintextserver:port: 8989

編碼

由于 spring 以及對客戶端的服務(wù)創(chuàng)建,等配置做了封裝,所以我們并不需要關(guān)心 channel 的創(chuàng)建,我們直接注入對應(yīng)的 stub(這里有三種 stub,分別是 future,stub,block),直接使用注解 @GrpcClient 然后在里面放我們在配置文件中配置的服務(wù)名稱,直接就可以通過 stub 調(diào)用了,然后 channel 的關(guān)閉等操作我們也不用關(guān)心,這個已經(jīng)做好了相關(guān)的封裝,使用者直接關(guān)心業(yè)務(wù)層面的邏輯就可以了。

public class BiRpcServerBlockStub {@GrpcClient("bi_server")private BiRpcServiceGrpc.BiRpcServiceBlockingStub biRpcServiceBlockingStub;@GetMappingpublic Object getUserInfo(String msg) {final BiService.OnceMessageResponse onceMessage = biRpcServiceBlockingStub.getOnceMessage(BiService.OnceMessageRequest.newBuilder().setContent(msg).build());return onceMessage.getContent();}
}

大家可以關(guān)注我的WX
在這里插入圖片描述

http://www.risenshineclean.com/news/7047.html

相關(guān)文章:

  • 網(wǎng)站設(shè)計與網(wǎng)頁制作教程網(wǎng)站搜索引擎優(yōu)化技術(shù)
  • 購物網(wǎng)站建設(shè)包括哪些做電商需要學(xué)哪些基礎(chǔ)
  • 做的好的農(nóng)產(chǎn)品網(wǎng)站肇慶疫情最新情況
  • 公司做網(wǎng)站留言板seo綜合查詢什么意思
  • 像淘寶類別網(wǎng)站怎么做谷歌優(yōu)化是什么意思
  • 推薦一個可以做ppt的網(wǎng)站雅虎搜索引擎
  • 做環(huán)評需要關(guān)注哪些網(wǎng)站企業(yè)網(wǎng)站推廣渠道
  • 具有營銷型網(wǎng)站的公司網(wǎng)站域名在哪里查詢
  • 門戶網(wǎng)站建設(shè)招標(biāo)文件軟件工程培訓(xùn)機構(gòu)哪家好
  • 哪個網(wǎng)站可以做申論真題資源搜索引擎搜索神器網(wǎng)
  • 陜西交通建設(shè)集團(tuán)網(wǎng)站網(wǎng)站建設(shè)費用
  • 途牛企業(yè)網(wǎng)站建設(shè)百度推廣效果怎樣一天費用
  • 網(wǎng)站建設(shè)公司生存百度收錄提交入口
  • 貿(mào)易公司 網(wǎng)站 扶持搜索引擎優(yōu)化分析
  • 實業(yè)+東莞網(wǎng)站建設(shè)網(wǎng)絡(luò)seo推廣
  • 重慶網(wǎng)站建設(shè)制作設(shè)計企業(yè)站seo案例分析
  • 東平網(wǎng)站建設(shè)公司網(wǎng)頁制作教程
  • 查詢網(wǎng)站備案密碼是什么免費網(wǎng)站服務(wù)器安全軟件下載
  • 自己做網(wǎng)站賣東西怎么樣西安seo服務(wù)商
  • 招聘網(wǎng)站做招聘顧問百度風(fēng)云榜小說排行榜
  • 福田做網(wǎng)站seo關(guān)鍵詞優(yōu)化推廣報價表
  • 可以免費做調(diào)查問卷的網(wǎng)站常見的網(wǎng)絡(luò)營銷工具有哪些
  • 網(wǎng)站開發(fā)廣告宣傳微信管理軟件
  • 做別人一樣的網(wǎng)站百度推廣圖片
  • 宿州網(wǎng)站建設(shè)設(shè)計公司最近一周的重大新聞
  • b2b網(wǎng)站模板saas建站平臺
  • 西安至成網(wǎng)站建設(shè)公司寧波seo外包代運營
  • 做b2b比較好的網(wǎng)站有哪些360搜索引擎入口
  • 全面的聊城網(wǎng)站建設(shè)獲客軟件排名前十名
  • 山西省政府網(wǎng)站建設(shè)百度競價推廣后臺