1. 中间件开发

以SpringBoot为基础开发一款中间件我也是第一次,因为接触SpringBoot也刚刚1个月左右。虽然SpringBoot已经出来挺久的了,但由于我们项目开发并不使用SpringBoot的一套东西,所以一直依赖没有接触。直到上个月开始考虑领域驱动设计才接触,嗯!真的不错,那么就开始了夯实技能、学习思想用到项目里。

按照我的产品需求,开发这么一款分布式任务的中间件,我脑袋中的模型已经存在了。另外就是需要开发过程中去探索我需要的知识工具,简单包括;

  1. 读取Yml自定义配置
  2. 使用zookeeper作为配置中心,这样如果有机器宕机了就可以通过临时节点监听知道
  3. 通过Spring类;ApplicationContextAware, BeanPostProcessor, ApplicationListener,执行服务启动、注解扫描、节点挂在
  4. 分布式任务统一控制台,来管理任务

2. 使用方式

简单使用

@SpringBootApplication
@EnableScheduling
public class Application{
    public static void mian(String[] args){
        SpringApplication.run(Application.class,args);
    }
	
	@Scheduled(cron = "0/3 * * * * *")
	public void demoTask() {
		//...
	}
}

分布式架构

@Component("demoTaskThree")
public class DemoTaskThree {
	
    @DcsScheduled(cron = "0 0 9,13 * * *", desc = "03定时任务执行测试:taskMethod01", autoStartup = false)
    public void taskMethod01() {
        System.out.println("03定时任务执行测试:taskMethod01");
    }

    @DcsScheduled(cron = "0 0/30 8-10 * * *", desc = "03定时任务执行测试:taskMethod02", autoStartup = false)
    public void taskMethod02() {
        System.out.println("03定时任务执行测试:taskMethod02");
    }

}

管理后台

Untitled