Skip to content

seancarroll/jmediator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jmediator

Build Status codecov Maintainability Test Coverage Sonarcloud Status SonarCloud Coverage SonarCloud Bugs SonarCloud Vulnerabilities

Simple in-process mediator implementation.

Prerequisites

Requires Java 17

Examples

jmediator attempts to decouple the in-process sending of messages from how they are handled.

First, create a message by creating a class that implements the Request interface. The Request interface handles both commands and queries.

public class HelloRequest implements Request {

    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Message{" +
            "payload='" + name + '\'' +
            '}';
    }
}

Next, lets create the corresponding handler

@Named
public class HelloRequestHandler implements RequestHandler<HelloRequest, String> {

    @Override
    public String handle(HelloRequest request) {
        return "Hello " + request.getName();
    }

}

Finally, we can send a message through the mediator

String response dispatcher.send(new HelloRequest("Sean"));
System.out.println(response); // prints "Hello Sean"

Inspiration

This project was inspired by Jimmy Bogard's Mediator project

About

Simple in-process mediator implementation

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages