DDD Base

DDD Base support with Java annotations, base interfaces and event

License

License

Categories

Categories

Search Business Logic Libraries
GroupId

GroupId

org.mvnsearch
ArtifactId

ArtifactId

ddd-base
Last Version

Last Version

1.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

DDD Base
DDD Base support with Java annotations, base interfaces and event
Project URL

Project URL

https://github.com/linux-china/ddd-base
Source Code Management

Source Code Management

https://github.com/linux-china/ddd-base

Download ddd-base

How to add to project

<!-- https://jarcasting.com/artifacts/org.mvnsearch/ddd-base/ -->
<dependency>
    <groupId>org.mvnsearch</groupId>
    <artifactId>ddd-base</artifactId>
    <version>1.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.mvnsearch/ddd-base/
implementation 'org.mvnsearch:ddd-base:1.2.0'
// https://jarcasting.com/artifacts/org.mvnsearch/ddd-base/
implementation ("org.mvnsearch:ddd-base:1.2.0")
'org.mvnsearch:ddd-base:jar:1.2.0'
<dependency org="org.mvnsearch" name="ddd-base" rev="1.2.0">
  <artifact name="ddd-base" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.mvnsearch', module='ddd-base', version='1.2.0')
)
libraryDependencies += "org.mvnsearch" % "ddd-base" % "1.2.0"
[org.mvnsearch/ddd-base "1.2.0"]

Dependencies

compile (6)

Group / Artifact Type Version
org.jetbrains : annotations jar 20.1.0
io.cloudevents : cloudevents-core jar 2.0.0
com.fasterxml.jackson.core : jackson-annotations jar 2.12.2
com.fasterxml.jackson.core : jackson-databind Optional jar 2.12.2
com.fasterxml.jackson.datatype : jackson-datatype-jdk8 Optional jar 2.12.2
org.slf4j : slf4j-api jar 1.7.30

test (2)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-test jar 2.4.3
org.junit.jupiter : junit-jupiter jar

Project Modules

There are no modules declared in this project.

DDD Base

"Building Status"

Domain Driven Design base package for Java.

How to use it in Java?

Please refer https://jitpack.io/#linux-china/ddd-base/1.1.1

Features

  • Annotations
  • Base classes for entity, domain event etc
  • Domain event: follow CloudEvents specification and CloudEvent convert support
  • DDD Reactive: https://www.reactive-streams.org/

Components

  • Data: Entity, VO and Aggregate
  • Behaviour: Repository, Service, Factory and Specification
  • Event: Follow CloudEvents spec
  • Infrastructure
  • CQRS interfaces for command & query

Reactive

DDD + Reactive(RSocket) to make context map easy.

Code Structure

Please visit src/test/java for code structure

If you use Kotlin to develop application, the structure will be different, please add entity, vo and repository in the same kt file.

Events

Please extend DomainEvent or DomainEventBuilder, then use ApplicationEventPublisher to publish the event. please refer https://spring.io/blog/2015/02/11/better-application-events-in-spring-framework-4-2

Attention: Spring framework 5.2 will add reactive support: https://github.com/spring-projects/spring-framework/issues/21831

Event extensions(JavaScript Object):

  • Distributed Tracing extension(traceparent, tracestate): embeds context from Distributed Tracing so that distributed systems can include traces that span an event-driven system.
  • Dataref(dataref): reference another location where this information is stored
  • Partitioning(partitionkey): This extension defines an attribute for use by message brokers and their clients that support partitioning of events, typically for the purpose of scaling.
  • Sequence(sequence): describe the position of an event in the ordered sequence of events produced by a unique event source
  • Sampling(sampledrate): Sampling
  • Multi-tenant(tenantId): Multi-tenant system support

CloudEvents JSONSchema: https://github.com/cloudevents/spec/blob/v0.3/spec.json

How to create event class

  • Extend CloudEvent class:
public class LoginEvent extends CloudEvent<String> {

    public LoginEvent(String email, String ip) {
        setData(email);
        setContentType("text/plain");
        setExtension("ip", ip);
    }
}
  • Create an event directly
CloudEvent<String> loginEvent = new CloudEvent<String>("text/plain", "[email protected]");
  • Event Builder or reactive processor
CloudEvent<String> loginEvent = CloudEventBuilder.<String>newInstance().contentType("text/plain").data("[email protected]").build();

ObjectMapper

  • ObjectMapper creation
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
  • write as String
objectMapper.writeValueAsString(loginEvent);
  • read from json text
objectMapper.readValue(jsonText, new TypeReference<CloudEvent<String>>() {});

References

Versions

Version
1.2.0