1. 程式人生 > >豬齒魚_01_環境搭建(三)_整合業務服務

豬齒魚_01_環境搭建(三)_整合業務服務

一、前言

本文承接上一節:豬齒魚_01_環境搭建(一)_微服務支撐元件部署

前面兩節,我們已經完成了豬齒魚微服務支撐元件的部署;

這一節,我們來看下如何在前面部署好的微服務支撐元件的基礎上,進行我們的業務服務的開發。

二、整合業務服務

這裡我們將建立一個簡單的Demo工程,然後將此工程整合進來。

1.建立工程

1.1 建立SpringBoot工程

建立一個SpringBoot工程即可,工程的GAV如下

groupId:hec-panda-cloud
artifactId:panda-cloud-service
version:1.0-SNAPSHOT

1.2 修改pom.xml

工程的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>


1.3 新建 PandaSystemExtraDataManager.java

此檔案是用來將當前工程的介面資訊註冊到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 
[email protected]
* @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; } }

2.指定註冊中心地址

eureka
  client:
    serviceUrl:
      defaultZone: http://localhost:8000/eureka/