Skip to content

arttom/cqs-spring-boot-starter

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Spring CQS library

spring-boot-started library to allow easily follow CQS (Command-Query Separation) principle

How to use

Command

Create Command by implementing Command interface

public class ExampleCommand implements Command {
    private final String textToLog;
    // constructor/getters
}

Then create Bean Handler for that Command (by default only one allowed)

@Component
public class ExampleCommandHandler implements CommandHandler<ExampleCommand> {

    void handle(ExampleCommand command) {
        log.info(command.getTextToLog());
    }
}

Inject somewhere BusProvider and call CommandBus to execute the command

@Service
class ExampleService {
    
    private final BusProvider busProvider;

    void executeExampleCommand() {
        busProvider.getCommandBus().execute(new ExampleCommand("Log this"));
    }
}

Query

Create Query by implementing Query interface

public class ExampleQuery implements Query<String> {
    private final String textToLowercase;
}

Then create Bean Handler for that Command (by default only one allowed)

@Component
public class ExampleQueryHandler implements QueryHandler<String, ExampleQuery> {

    String handle(ExampleQuery query) {
        return query.getTextToLowercase().toLowerCase();
    }
}

Inject somewhere BusProvider and call CommandBus to execute the command

@Service
class ExampleService {
    
    private final BusProvider busProvider;

    String executeTextExampleQuery() {
        return busProvider.getQueryBus().execute(new ExampleQuery("Make ThIS LOwerCase"));
    }
}

MVN artifact

<dependency>
  <groupId>com.github.arttom</groupId>
  <artifactId>cqs-spring-boot-starter</artifactId>
  <version>0.1</version>
</dependency>

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages