dracarys-chain

Chain of responsibility abstraction

License

License

GroupId

GroupId

io.github.junhuhdev
ArtifactId

ArtifactId

dracarys-chain
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

dracarys-chain
Chain of responsibility abstraction
Source Code Management

Source Code Management

https://github.com/junhuhdev/dracarys-chain

Download dracarys-chain

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.junhuhdev/dracarys-chain/ -->
<dependency>
    <groupId>io.github.junhuhdev</groupId>
    <artifactId>dracarys-chain</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.junhuhdev/dracarys-chain/
implementation 'io.github.junhuhdev:dracarys-chain:1.0.0'
// https://jarcasting.com/artifacts/io.github.junhuhdev/dracarys-chain/
implementation ("io.github.junhuhdev:dracarys-chain:1.0.0")
'io.github.junhuhdev:dracarys-chain:jar:1.0.0'
<dependency org="io.github.junhuhdev" name="dracarys-chain" rev="1.0.0">
  <artifact name="dracarys-chain" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.junhuhdev', module='dracarys-chain', version='1.0.0')
)
libraryDependencies += "io.github.junhuhdev" % "dracarys-chain" % "1.0.0"
[io.github.junhuhdev/dracarys-chain "1.0.0"]

Dependencies

compile (5)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-data-jdbc jar 2.4.1
org.projectlombok : lombok Optional jar 1.18.16
com.thoughtworks.xstream : xstream jar 1.4.14
com.google.guava : guava jar 30.0-jre
org.apache.commons : commons-lang3 jar 3.11

test (1)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-test jar 2.4.1

Project Modules

There are no modules declared in this project.

🔥 dracarys-chain

Installation

<dependency>
    <groupId>io.github.junhuhdev</groupId>
    <artifactId>dracarys-chain</artifactId>
    <version>1.0.0</version>
</dependency>

Usage

Enable Dracarys Chain

@EnableDracarysChain
@SpringBootApplication
public class Application {

	public static void main(String[] args) {
		SpringApplication.run(JobRunrApplication.class, args);
	}

}

Commands

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@RequiredArgsConstructor
@Component
public class UserValidateCmd implements Command {

	private final ValidationService validationService;

	public ChainContext execute(ChainContext ctx, Chain chain) {
		var event = ctx.getEvent(ValidateUserRequest.class);
		boolean response = validationService.validate(event);
		if (response) {
			return chain.proceed(ctx);
		}
		return ctx;
	}

}

@RequiredArgsConstructor
@Component
public class UserCreateCmd implements Command {

	private final UserRepository userRepository;

	public ChainContext execute(ChainContext ctx, Chain chain) {
		var event = ctx.getEvent(UserRequest.class);
		userRepository.create(event);
		return chain.proceed(ctx);
	}

}

@RequiredArgsConstructor
@Component
public class EmailSendCmd implements Command {

	private final EmailService emailService;

	public ChainContext execute(ChainContext ctx, Chain chain) {
		var event = ctx.getEvent(MailRequest.class);
		emailService.send(event);
		return chain.proceed(ctx);
	}

}

Chain

import ChainBase;
import org.springframework.stereotype.Component;

@Component
public class UserRegistrationChain extends ChainBase {

    @Override
    protected Class<?>[] getCommands() {
        return new Class<?>[]{UserValidateCmd.class, UserCreateCmd.class, EmailSendCmd.class};
    }
}

TODO

  • Dashboard
  • Sub-chains
  • Support retries
  • Customizable lock key
  • Custom annotations

Versions

Version
1.0.0