『高階篇』docker之開發課程服務(15)
這次一起編寫課程服務。之前的使用者服務,使用者EdgeSerivce,使用者資訊,都已經開發完畢了,開始開發課程服務,對外的是dubbo介面,需要訪問後端的資料庫。原始碼:https://github.com/limingios/msA-docker
開發課程服務模組
基於dubbo的服務,一般先定義api介面,前面的都是基於thrift的,我們先寫一個thrift的檔案,然後根據配置檔案升成對應的api,dubbo我們相當於先手寫一個api的模組。
稍微複雜
-
總體思想
>就不在複製程式碼了只通過截圖來講述功能,可以參考原始碼,本次跟用到了上次springboot整合dubbo的方式。
- course-dubbo-service-api 是負責提供介面的服務
- course-dubbo-service 是course-dubbo-service-api的實現
- course-dubbo-service 需要依賴原始的user-thrift-service-api的原生DTO類 和 user-thrift-service中的方法實現。
- course-dubbo-service呼叫user-thrift-service 是用過thrift的方式完成的呼叫。因為user-thrift-service本身就是通過thrift生成對應的java類。
- user-thrift-service 和 user-thrift-service-api
- user-thrift-service-api 做了thrift的修改,增加了老師的DTO和ID來獲取使用者的資訊,所以需要重新通過thrift命令生成對應的java類
- user-thrift-service 實現了新增的通過ID來獲取使用者的資訊的介面,並增加了UserMapper
- user資料庫中增加了一張關聯表teacher表
- course-dubbo-service-api 和 course-dubbo-service
- course-dubbo-service pom中引入了springboot,mysql的驅動,thrift,springboot-dubbo,user-thrift-service.jar,user-thrift-service-api.jar
- course-dubbo-service 中注入thrift微服務的訪問service,獲取教師針對課程的教程資訊訪問user-thrift-service的微服務,通過thrift的方式。
- application.properties 配置dubbo的配置,資料庫配置,user-thrift-service的地址和埠
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.3.RELEASE</version> </parent> <modelVersion>4.0.0</modelVersion> <groupId>com.idig8</groupId> <artifactId>course-dubbo-service</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>io.dubbo.springboot</groupId> <artifactId>spring-boot-starter-dubbo</artifactId> <version>1.0.0</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.apache.thrift</groupId> <artifactId>libthrift</artifactId> <version>0.10.0</version> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.1</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.44</version> </dependency> <dependency> <groupId>com.idig8</groupId> <artifactId>course-dubbo-service-api</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <dependency> <groupId>com.idig8</groupId> <artifactId>user-thrift-service</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <dependency> <groupId>com.idig8</groupId> <artifactId>user-thrift-service-api</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies> </project>
PS:基本的課程開發思路就是這樣,別人有的微服務呼叫,只實現自己所屬的。
ofollow,noindex" target="_blank" href="http://zhanzhang.baidu.com/sitesubmit/index?sitename=https://idig8.com/2018/10/17/gaojipiandockerzhikaifakechengfuwu14/">百度未收錄
>>原創文章,歡迎轉載。轉載請註明:轉載自IT人故事會,謝謝!
>>原文連結地址:上一篇:已是最新文章