This repository has been archived by the owner on Jan 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMessagingEndPoint.java
45 lines (38 loc) · 1.8 KB
/
MessagingEndPoint.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
public class HelloWorld {
public static void main(String[] args) throws Exception {
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
public void configure() {
// Route to send message to a JMS queue and a topic
from("direct:start")
.to("jms:queue:orders")
.to("jms:topic:notifications");
// Route to receive message from a file
from("file:data/messages?fileName=message.txt")
.process(exchange -> {
String message = exchange.getIn().getBody(String.class);
System.out.println("Received from file: " + message);
});
// Route to receive message from a JMS queue
from("jms:queue:orders")
.process(exchange -> {
String message = exchange.getIn().getBody(String.class);
System.out.println("Received from JMS queue: " + message);
});
// Route to receive message from a JMS topic
from("jms:topic:notifications")
.process(exchange -> {
String message = exchange.getIn().getBody(String.class);
System.out.println("Received from JMS topic: " + message);
});
}
});
context.start();
context.createProducerTemplate().sendBody("direct:start", "Hello World!");
Thread.sleep(1000);
context.stop();
}
}