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 approximately equal to: consul + rabbitmq + elk + prometheus + openFaas + quartz and some other functions, and organically combined.
Or approximately equal to: nacos + rocketmq + PlumeLog + prometheus + magic-api + xxl-job + etc., and organically combined.
This update
- Add query records and reusable selections
- Log ES solution, add 8.x support
- Adjust HttpUtils to add switching between short processing and long processing
- Fix the problem that some aggregate navigation without tags cannot be clicked
- Ignore the problem that the jwt key file cannot be found during the restart of the management background
- Solon upgrade to: 1.6.36
- grit upgrade to: 1.0.11
- redisx upgrade to: 1.0.6
- esearchx upgrade to: 1.0.11 (support Elasticsearch 8.x)
Quick start
Learn about development frameworks and mirroring
Development Framework | |
org.noear:water.client | Framework: Water Client |
org.noear:water-solon-plugin | Framework: Water client for soloon (also available for Spring Boot projects) |
mirror | |
noearorg/waterapi:2.5.9 | Image: Water main interface service |
nuarorg/watersev:2.5.9 | Mirror: Water background service (health detection; data monitoring; message distribution; scheduled tasks, etc...) |
noearorg/wateradmin:2.5.9 | Image: Water management console (support LDAP login) |
noearorg/waterfaas:2.5.9 | Image: Water instant interface service, providing lightweight FaaS interface service |
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
- https://gitee.com/noear/water
- https://github.com/noear/water
code demo
(1) Configuration
- pom.xml / mevan placement
<!-- 客户端版本 -->
<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>
- application.yml / configuration instructions
solon.app:
name: "wateradmin"
group: "water"
solon.cloud.water:
server: "waterapi:9371" #WATER服务地址
config:
load: "test.properties" #默认加载的配置
log:
default: "water_log_admin" #默认日志记录器
(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);
}
});
}
}
@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("我被调度了");
}
}