messaging: add a simple message broker

Add a simple message broker which uses the chain of responsibility design pattern for
message handling.

Inspired by this article: http://www.softwarematters.org/message-broker.html#java-implementation

In this design, a message handler can contain a reference to the next
message handler. If the current handler cannot handle the message given
to him by the MessageBroker, he passes this message to the next
MessageHandler.

The chain of responsibility pattern is used in order to decouple the creation of a
concrete message instance from the broker communication logic. This adheres to the Open
Closed Principle, because it is possible to add a new message type without modifying the
message broker.
This commit is contained in:
2019-10-19 17:48:53 +02:00
parent eea8074d32
commit c4477aca38
12 changed files with 376 additions and 0 deletions

36
messaging/pom.xml Normal file
View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>fr.gasser</groupId>
<artifactId>java-cookbook</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>messaging</artifactId>
<properties>
<hamcrest-junit.version>2.0.0.0</hamcrest-junit.version>
<mockito-mockito-core.version>3.1.0</mockito-mockito-core.version>
</properties>
<dependencies>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-junit</artifactId>
<version>${hamcrest-junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito-mockito-core.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>