jmediatr-boot-starter

基于spring实现的中介者模式类库,实现进程内消息发布与处理解耦

License

License

MIT
GroupId

GroupId

io.github.zhaord
ArtifactId

ArtifactId

jmediatr-boot-starter
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

jmediatr-boot-starter
基于spring实现的中介者模式类库,实现进程内消息发布与处理解耦
Project URL

Project URL

https://github.com/ZhaoRd/jmediatr-boot-starter.git
Source Code Management

Source Code Management

https://github.com/ZhaoRd/jmediatr-boot-starter.git

Download jmediatr-boot-starter

How to add to project

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

Dependencies

compile (2)

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

test (3)

Group / Artifact Type Version
org.mockito : mockito-core jar 3.6.28
org.assertj : assertj-core jar 3.18.1
org.junit.jupiter : junit-jupiter jar 5.7.0

Project Modules

There are no modules declared in this project.

jmediatr-boot-starter

java中介者类库,实现进程内消息发布与处理解耦

安装

<!-- https://mvnrepository.com/artifact/io.github.zhaord/jmediatr-boot-starter -->
<dependency>
    <groupId>io.github.zhaord</groupId>
    <artifactId>jmediatr-boot-starter</artifactId>
    <version>1.0.0</version>
</dependency>

一对一消息使用

@ExtendWith(SpringExtension.class)
@Import(
        value = {
                Mediator.class,
                PingPongTest.PingHandler.class,
        }
)
public class PingPongTest {

    @Autowired
    IMediator mediator;

    @Test
    public void should() {
        String send = mediator.send(new Ping());

        assertThat(send).isNotNull();
        assertThat(send).isEqualTo("Pong");
    }

    public static class Ping implements IRequest<String> {
    }

    public static class PingHandler implements IRequestHandler<Ping, String> {
        @Override
        public String handle(Ping request) {
            return "Pong";
        }
    }

}

一对多消息使用

@ExtendWith(SpringExtension.class)
@Import(
        value = {
                Mediator.class,
                PingNoticeTests.Pong1.class,
                PingNoticeTests.Pong2.class,
        }
)
public class PingNoticeTests {

    @Autowired
    IMediator mediator;

    @Autowired
    Pong1 pong1;

    @Autowired
    Pong2 pong2;

    @Test
    public void should() {
        mediator.publish(new Ping());

        assertThat(pong1.getCode()).isEqualTo("Pon1");
        assertThat(pong2.getCode()).isEqualTo("Pon2");
    }

    public static class Ping implements INotification {
    }

    public static class Pong1 implements INotificationHandler<Ping> {

        private String code;

        public String getCode() {
            return code;
        }

        @Override
        public void handle(Ping notification) {
            this.code = "Pon1";
        }
    }

    public static class Pong2 implements INotificationHandler<Ping> {

        private String code;

        public String getCode() {
            return code;
        }

        @Override
        public void handle(Ping notification) {
            this.code = "Pon2";
        }
    }

}

博客

https://www.yuque.com/zhugexiaoliang/ymi827/ox8omg

Versions

Version
1.0.0