前面两节,我们已经完成了猪齿鱼微服务支撑组件的部署;
这一节,我们来看下如何在前面部署好的微服务支撑组件的基础上,进行我们的业务服务的开发。
这里我们将创建一个简单的Demo工程,然后将此工程整合进来。
创建一个SpringBoot工程即可,工程的GAV如下
groupId:hec-panda-cloud artifactId:panda-cloud-service version:1.0-SNAPSHOT
工程的pom.xml文件内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>hec-panda-cloud</groupId>
<artifactId>panda-cloud-service</artifactId>
<version>1.0-SNAPSHOT</version>
<modelVersion>4.0.0</modelVersion>
<!--choerodon-framework-parent dependency-->
<parent>
<groupId>io.choerodon</groupId>
<artifactId>choerodon-framework-parent</artifactId>
<version>0.6.0.RELEASE</version>
</parent>
<!--choerodon-starters dependency-->
<properties>
<choerodon.starters.version>0.5.1.RELEASE</choerodon.starters.version>
</properties>
<dependencies>
<!--spring boot-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
<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>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-kafka</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-bus</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--choerodon starters-->
<dependency>
<groupId>io.choerodon</groupId>
<artifactId>choerodon-starter-oauth-resource</artifactId>
<version>${choerodon.starters.version}</version>
</dependency>
<dependency>
<groupId>io.choerodon</groupId>
<artifactId>choerodon-starter-swagger</artifactId>
<version>${choerodon.starters.version}</version>
</dependency>
<dependency>
<groupId>io.choerodon</groupId>
<artifactId>choerodon-starter-core</artifactId>
<version>${choerodon.starters.version}</version>
</dependency>
<dependency>
<groupId>io.choerodon</groupId>
<artifactId>choerodon-starter-mybatis-mapper</artifactId>
<version>${choerodon.starters.version}</version>
</dependency>
<dependency>
<groupId>io.choerodon</groupId>
<artifactId>choerodon-starter-bus</artifactId>
<version>${choerodon.starters.version}</version>
</dependency>
<!--mysql-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!--监控相关依赖 -->
<dependency><!-- 如果服务需要监控功能则需要此依赖 -->
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-kafka</artifactId>
</dependency>
<dependency><!-- 如果服务需要hystrix监控功能则需要此依赖 -->
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-hystrix-stream</artifactId>
</dependency>
<dependency><!-- 如果服务需要zipkin监控功能则需要此依赖 -->
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-stream</artifactId>
</dependency>
<!-- 添加cpu监控 -->
<dependency>
<groupId>io.choerodon</groupId>
<artifactId>choerodon-starter-hitoa</artifactId>
<version>${choerodon.starters.version}</version>
</dependency>
<!-- test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>app</finalName>
</build>
</project>
此文件是用来将当前工程的接口信息注册到Swagger中。 文件内容如下:
/*
*
* 项目名称:choerodon-framework-parent
* Copyright @ 2018 Shanghai Hand Co. Ltd.
* All right reserved.
*
*
*/
package io.choerodon.demo;
import io.choerodon.core.swagger.ChoerodonRouteData;
import io.choerodon.swagger.annotation.ChoerodonExtraData;
import io.choerodon.swagger.custom.extra.ExtraData;
import io.choerodon.swagger.custom.extra.ExtraDataManager;
/** HcbmTemplateExtraDataManager
*
* @author yinbo.shi@hand-china.com
* @date 2018/06/14
*/
@ChoerodonExtraData
public class PandaSystemExtraDataManager implements ExtraDataManager {
@Override
public ExtraData getData() {
ChoerodonRouteData choerodonRouteData = new ChoerodonRouteData();
choerodonRouteData.setName("panda-system");
choerodonRouteData.setPath("/panda/system/**");
choerodonRouteData.setServiceId("panda-system");
extraData.put(ExtraData.ZUUL_ROUTE_DATA, choerodonRouteData);
return extraData;
}
}
eureka
client:
serviceUrl:
defaultZone: http://localhost:8000/eureka/