Giter Site home page Giter Site logo

ddd-base's Introduction

DDD Base

Domain Driven Design base package for Java.

How to use it in Java?

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

Features

Components

  • Data: Entity, VO and Aggregate
  • Behaviour: Repository, Service, Factory and Specification
  • Event
  • Infrastructure

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: spring-projects/spring-framework#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

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 object 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

ddd-base's People

Contributors

linux-china avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.