Giter Site home page Giter Site logo

sofa-ark-spring-guides's Introduction

sofa-ark-spring-guides

实验内容

  • 通过 SOFAArk 提供的官方maven插件将一个 Spring Boot 应用启动成一个标准Ark包,即宿主机;
  • 通过 Telnet指令 动态安装另一个Spring Boot应用到宿主机上,同时在JVM中运行;

任务

1、任务准备

从 github 上将 demo 工程克隆到本地

git clone [email protected]:sofastack-guides/sofa-ark-spring-guides.git

然后将工程导入到 IDEA 或者 eclipse,该工程是使用 Spring脚手架 生成;

2、添加 SOFAArk 相关依赖

SOFAArk 当前最新版本号为 2.0.0

<!-- 这里添加动态模块相关依赖 -->
<properties>
    <sofa.ark.version>2.0.0</sofa.ark.version>
</properties>

<dependency>
    <groupId>com.alipay.sofa</groupId>
    <artifactId>sofa-ark-springboot-starter</artifactId>
    <version>${sofa.ark.version}</version>
</dependency>
<dependency>
    <groupId>com.alipay.sofa</groupId>
    <artifactId>sofa-ark-all</artifactId>
    <version>${sofa.ark.version}</version>
</dependency>
<dependency>
    <groupId>com.alipay.sofa</groupId>
    <artifactId>sofa-ark-api</artifactId>
    <version>${sofa.ark.version}</version>
</dependency>

3、修改打包方式

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>2.6.6</version>

            <configuration>
                <outputDirectory>target</outputDirectory>
                <classifier>ark-biz</classifier>
            </configuration>
            <executions>
                <execution>
                    <id>package</id>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

4. 包结构

5、启动

方式一:IDEA启动

本地启动需要加上启动参数

-Dsofa.ark.embed.enable=true

-Dcom.alipay.sofa.ark.master.biz=sofa-ark-spring-guides

启动后会先启动 Ark 容器

image.png

有该日志出现代表 Ark 容器启动成功,此时该应用处于运行时,可进行动态模块的安装,卸载。

方式二:命令行启动

Ark包是可执行Jar,可直接使用Java -jar的方式启动,先使用 mvn clean package 进行打包,打包得到 sofa-ark-spring-guides-0.0.1-SNAPSHOT-ark-biz.jar,命令行启动

java -jar -Dsofa.ark.embed.enable=true -Dcom.alipay.sofa.ark.master.biz=sofa-ark-spring-guides sofa-ark-spring-guides-0.0.1-SNAPSHOT-ark-biz.jar

image.png

6、Telnet指令

SOFAArk官方提供了本地运维模块小工具 Telnet指令

telnet localhost 1234 image.png

biz -a

查看该应用中所有模块,当前只有name=spring-guides,version=1.0.0,status=activated的宿主应用。

现在来尝试运行时动态安装新模块,模块应用使用了另一个Spring Boot应用打成的Ark包 spring-boot-ark-biz-0.0.1-SNAPSHOT-ark-biz.jar, 用于动态安装;

## 连接 SOFAArk telnet
> telnet localhost 1234

## 安装新版本 dynamic-provider
sofa-ark>biz -i file:////Users/yuanyuan/yuanyuan/Code/spring-boot-ark-biz/target/spring-boot-ark-biz-0.0.1-SNAPSHOT-ark-biz.jar
Start to process install command now, pls wait and check.

## 查看安装的模块信息
sofa-ark>biz -a
sofa-ark-spring-guides:1.0.0:activated          // 宿主应用
spring-boot-ark-biz:0.0.1-SNAPSHOT:activated    // 动态安装的模块应用
biz count = 2

当前JVM中同时运行着两个Spring Boot应用

两个Spring Boot应用可以是不同的Spring Boot版本,由各自的ClassLoader进行加载;

如,宿主应用sofa-ark-spring-guides是Spring Boot 2.6.6,由org.springframework.boot.loader.LaunchedURLClassLoader加载

SofaArkSpringGuidesApplication start!
Spring Boot Version: 2.6.6
SofaArkSpringGuidesApplication classLoader: org.springframework.boot.loader.LaunchedURLClassLoader@366e2eef

image.png

和 动态安装的模块应用spring-boot-ark-biz是Spring Boot 2.5.0,由Ark框架提供的com.alipay.sofa.ark.container.service.classloader.BizClassLoader加载

SpringBootArkBizApplication start!
SpringBootArkBizApplication spring boot version: 2.5.0
SpringBootArkBizApplication classLoader: com.alipay.sofa.ark.container.service.classloader.BizClassLoader@52a1e30

image.png

sofa-ark-spring-guides's People

Contributors

yuanyuancin avatar yuanyuan2021 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.