Water (water breeds all things…)

Water provides a one-stop solution for project development and service governance (which can be understood as a microservice architecture support suite). Developed based on the Solon framework and supports the full Solon Cloud specification; has been running in production for 4 years.

The function is equivalent to: consul + rabbitmq + elk + prometheus + openFaas + quartz + etc., and organically combined. Or approximately equal to: nacos + rocketmq + PlumeLog + prometheus + magic-api + xxl-job + etc.

It is friendly to k8s, supports IP drift, and supports k8s service mapping.

This update

  • Added “Indicator Concern” record interface and display
  • Added “Certificate Monitoring” management interface
  • Added “app monitoring” batch disable enable support
  • Added “Data Monitoring” batch disable enable support
  • Solon is upgraded to: 1.10.2 (project address: https://gitee.com/noear/solon)
  • Snack3 is upgraded to: 3.2.35 (project address: https://gitee.com/noear/snack3)

Quick start

Learn about development frameworks and mirroring

componentsillustrate
Development Framework
org.noear:water.clientFramework: Water Client
org.noear:water-solon-pluginFramework: Water client for soloon (also available for Spring Boot projects)
mirror
noearorg/waterapi:2.8.2Image: Water main interface service
noearorg/watersev:2.8.2Mirror: Water background service (health detection; data monitoring; message distribution; scheduled tasks, etc…)
noearorg/wateradmin:2.8.2Image: Water management console (support LDAP login)
noearorg/waterfaas:2.8.2Image: Water instant interface service, providing lightweight FaaS interface service
noearorg/xwater:2.8.2Build: Water Assistant Tool

Console Demonstration Station

Address: http://water.noear.org (account: demo; password: demo)

Key persistence notes:

  • Log persistence, support: MySql, PostgreSQL, MongoDb, ElasticSearch, ClickHouse
  • Message persistence, support: MySql, PostgreSQL, MongoDb

project address

code demo

(1) Configuration


<!-- 客户端版本 -->
<dependency>
    <groupId>org.noear</groupId>
    <artifactId>water.client</artifactId>
    <version>${water.ver}</version>
</dependency>

<!-- solon cloud 集成版本 (也可用于 Spring Boot 项目) -->
<dependency>
    <groupId>org.noear</groupId>
    <artifactId>water-solon-plugin</artifactId>
    <version>${solon.ver}</version>
</dependency>

solon.app:
  name: "demo-api"
  group: "demo"

solon.cloud.water:
  server: "waterapi:9371"    #WATER服务地址
  config:
    load: "demo.yml"         #默认加载的配置

(2) Code


public class DemoApp {
    public void main(String[] args) {
        SolonApp app = Solon.start(DemoApp.class, args);

        //监控服务:之:添加接口性能记录(一般这个过滤器写成独立类)
        Logger log = LoggerFactory.getLogger(DemoApp.class);
        app.filter((ctx, chain) -> {
            //1.开始计时(用于计算响应时长)
            long start = System.currentTimeMillis();

            try {
                chain.doFilter(ctx);
            } catch (Throwable e) {
                //2.顺带记录个异常
                log.error("{}",e);
            } finally {
                //3.获得接口响应时长
                long milliseconds = System.currentTimeMillis() - start;
                CloudClient.metric().addMeter(Solon.cfg().appName(), "path", ctx.pathNew(), milliseconds);
            }
        });
    }
}

@Configuration
public class DemoConfig {

    @Bean
    public DataSource db1(@CloudConfig("demoDb") HikariDataSource ds) {
        //配置一个数据源
        return ds;
    }
    
    @Bean
    public I18nBundleFactory i18nBundleFactory(){
        //将国际化服务,切换为云端接口
        return new CloudI18nBundleFactory();
    }
}

@Slf4j
@Controller
public class DemoController{
    @CloudConfig(name = "demoDb", autoRefreshed = true)  //配置服务的功能(注解模式)
    DbContext demoDb;

    @NamiClient            //RPC服务发现的功能(注解模式)
    RockService rockService;
   
    @Mapping("/")
    public void test(){
        //日志服务:写个日志
        log.info("你好,日志服务"); //(content)
        TagsMDC.tag0("demo");
        log.error("{}\\r\\n{}","test","你好,日志服务"); //(tag,summary,content)
        
        //配置服务:使用配置的数据库上下文进行查询
        Map map = demoDb.table("water_reg_service").limit(1).selectMap("*");

        //消息服务:发送消息
        CloudClient.event().publish(new Event("demo.test", "{\\"order_id\\":1}")); //(非注解模式)

        //Rpc发现服务:调用Rpc接口
        AppModel app = rockService.getAppById(12);
    }
}

//消息订阅:订阅消息并处理(根据:topic 进行订阅)
@Slf4j
@CloudEvent("demo.test")
public class Event_demo_test implements CloudEventHandler {
    @Override
    public boolean handle(Event event) throws Exception {
        //处理消息...
        log.info("我收到消息:" + event.content());
        return true;
    }
}


//配置订阅:关注配置的实时更新
@CloudConfig("demoDb")
public class TestConfigHandler implements CloudConfigHandler {
    @Override
    public void handle(Config config) {

    }
}

//分布式任务
@CloudJob(name = "demo_test", cron7x = "0 1 * * * ?")
public class Job_test implements CloudJobHandler {

    @Override
    public void handle(Context ctx) throws Throwable {
        //处理任务...
        log.info("我被调度了");
    }
}

#Onestop #service #governance #platform #Water #released #News Fast Delivery

Leave a Comment

Your email address will not be published. Required fields are marked *