Skip to content

Commit e33d037

Browse files
committed
Merge pull request iluwatar#227 from iluwatar/message-channel
Message Channel EIP
2 parents 4135179 + b5d03b6 commit e33d037

File tree

8 files changed

+451
-0
lines changed

8 files changed

+451
-0
lines changed

message-channel/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target/
46.1 KB
Loading

message-channel/etc/message-channel.ucls

Lines changed: 320 additions & 0 deletions
Large diffs are not rendered by default.

message-channel/index.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
layout: pattern
3+
title: Message Channel
4+
folder: message-channel
5+
permalink: /patterns/message-channel/
6+
categories: Integration
7+
tags: Java
8+
---
9+
10+
**Intent:** When two applications communicate using a messaging system they do it by using logical addresses
11+
of the system, so called Message Channels.
12+
13+
![alt text](./etc/message-channel.png "Message Channel")
14+
15+
**Applicability:** Use the Message Channel pattern when
16+
17+
* two or more applications need to communicate using a messaging system
18+
19+
**Real world examples:**
20+
21+
* [akka-camel](http://doc.akka.io/docs/akka/snapshot/scala/camel.html)

message-channel/pom.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0"?>
2+
<project
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
4+
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>com.iluwatar</groupId>
8+
<artifactId>java-design-patterns</artifactId>
9+
<version>1.6.0</version>
10+
</parent>
11+
<artifactId>message-channel</artifactId>
12+
<dependencies>
13+
<dependency>
14+
<groupId>org.apache.camel</groupId>
15+
<artifactId>camel-core</artifactId>
16+
</dependency>
17+
<dependency>
18+
<groupId>org.apache.camel</groupId>
19+
<artifactId>camel-stream</artifactId>
20+
</dependency>
21+
<dependency>
22+
<groupId>junit</groupId>
23+
<artifactId>junit</artifactId>
24+
<scope>test</scope>
25+
</dependency>
26+
</dependencies>
27+
</project>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.iluwatar.message.channel;
2+
3+
import org.apache.camel.CamelContext;
4+
import org.apache.camel.builder.RouteBuilder;
5+
import org.apache.camel.impl.DefaultCamelContext;
6+
7+
/**
8+
*
9+
* When two applications communicate with each other using a messaging system
10+
* they first need to establish a communication channel that will carry the
11+
* data. Message Channel decouples Message producers and consumers.
12+
* <p>
13+
* The sending application doesn't necessarily know what particular application
14+
* will end up retrieving it, but it can be assured that the application that
15+
* retrieves the information is interested in that information. This is because
16+
* the messaging system has different Message Channels for different types of
17+
* information the applications want to communicate. When an application sends
18+
* information, it doesn't randomly add the information to any channel available;
19+
* it adds it to a channel whose specific purpose is to communicate that sort of
20+
* information. Likewise, an application that wants to receive particular information
21+
* doesn't pull info off some random channel; it selects what channel to get information
22+
* from based on what type of information it wants.
23+
* <p>
24+
* In this example we use Apache Camel to establish two different Message Channels. The first
25+
* one reads from standard input and delivers messages to Direct endpoint. The second Message
26+
* Channel is established from the Direct component to console output. No actual messages are sent,
27+
* only the established routes are printed to standard output.
28+
*
29+
*/
30+
public class App {
31+
32+
/**
33+
* Program entry point
34+
* @param args command line args
35+
* @throws Exception
36+
*/
37+
public static void main(String[] args) throws Exception {
38+
CamelContext context = new DefaultCamelContext();
39+
40+
context.addRoutes(new RouteBuilder() {
41+
42+
@Override
43+
public void configure() throws Exception {
44+
from("stream:in").to("direct:greetings");
45+
from("direct:greetings").to("stream:out");
46+
}
47+
});
48+
49+
context.start();
50+
context.getRoutes().stream().forEach((r) -> System.out.println(r));
51+
context.stop();
52+
}
53+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.iluwatar.message.channel;
2+
3+
import org.junit.Test;
4+
5+
/**
6+
*
7+
* Application test
8+
*
9+
*/
10+
public class AppTest {
11+
12+
@Test
13+
public void test() throws Exception {
14+
String[] args = {};
15+
App.main(args);
16+
}
17+
}

pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<coveralls.version>3.1.0</coveralls.version>
1818
<jacoco.version>0.7.2.201409121644</jacoco.version>
1919
<commons-dbcp.version>1.4</commons-dbcp.version>
20+
<camel.version>2.15.3</camel.version>
2021
</properties>
2122
<modules>
2223
<module>abstract-factory</module>
@@ -75,6 +76,7 @@
7576
<module>half-sync-half-async</module>
7677
<module>step-builder</module>
7778
<module>layers</module>
79+
<module>message-channel</module>
7880
</modules>
7981

8082
<dependencyManagement>
@@ -104,6 +106,16 @@
104106
<artifactId>commons-dbcp</artifactId>
105107
<version>${commons-dbcp.version}</version>
106108
</dependency>
109+
<dependency>
110+
<groupId>org.apache.camel</groupId>
111+
<artifactId>camel-core</artifactId>
112+
<version>${camel.version}</version>
113+
</dependency>
114+
<dependency>
115+
<groupId>org.apache.camel</groupId>
116+
<artifactId>camel-stream</artifactId>
117+
<version>${camel.version}</version>
118+
</dependency>
107119
<dependency>
108120
<groupId>junit</groupId>
109121
<artifactId>junit</artifactId>

0 commit comments

Comments
 (0)