2

Dewdrop:开源事件源框架

 2 years ago
source link: https://www.jdon.com/61591
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Dewdrop:开源事件源框架
Dewdrop 是一个自以为是的、简单而强大的框架,用于在 Java 中实现事件溯源。Dewdrop 的想法是通过将所有复杂的事件读取、写入和编组深入到框架中,使您的团队能够专注于根据 AggregateRoot 构建业务逻辑,从而轻松快速地构建事件驱动系统行为、查询逻辑和 ReadModel 组合。

目前,Dewdrop 仅支持使用EventStore作为其后备存储。

Dewdrop 严格遵循一些架构原则,以便轻松构建事件驱动的系统。以下是 Dewdrop 的核心概念:

  • DDD - 领域驱动设计
  • CQRS - 命令查询职责分离
  • 事件溯源——事件驱动架构

使用方式
首先,您需要确保在本地运行 EventStore。为此,您可以下载EventStore客户端并运行它。或者,您可以运行存储库中包含的 docker 实例。要启动 docker 实例,请在 dewdrop 目录中运行以下命令:
docker-compose up -d
我们还假设大多数参与该项目的人都在像 Spring Boot 这样的依赖注入框架中运行它。如果是这种情况,您需要创建一个包装您的 DI 应用程序上下文的类。对于 Spring Boot,您将创建一个实现DependencyInjectionAdapter并将其公开为 bean 的类。

public class DewdropDependencyInjection implements DependencyInjectionAdapter {
        private ApplicationContext applicationContext;
        public DewdropDependencyInjection(ApplicationContext applicationContext) {
                this.applicationContext = applicationContext;
        }

        @Override
        public <T> T getBean(Class<?> clazz) {
            return (T) applicationContext.getBean(clazz);
        }
}

这让 Dewdrop 知道它应该使用应用程序上下文来获取它需要的 Spring 托管 bean。

下一步是创建一个DewdropConfiguration用于配置 Dewdrop 框架的类。

import java.beans.BeanProperty;

public class DewdropConfiguration {
    @Autowired
    ApplicationContext applicationContext;
    
    @Bean 
    public DewdropDependencyInjection dependencyInjection() {
        return new DewdropDependencyInjection(applicationContext);
    }
    
    @Bean
    public DewdropProperties dewdropProperties() {
        return DewdropProperties.builder()
            .packageToScan("events.dewdrop")
            .packageToExclude("events.dewdrop.fixture.customized")
            .connectionString("esdb://localhost:2113?tls=false")
            .create();
    }
    
    @Bean 
    public Dewdrop dewdrop() {
        return DewdropSettings.builder()
            .properties(dewdropProperties())
            .dependencyInjectionAdapter(dependencyInjection())
            .create()
            .start();
    }
}

就是这样!您现在可以运行该应用程序,它将启动 Dewdrop 框架。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK