[JAVA-14174] Renamed paterns to paterns-module (#12718)
* [JAVA-14174] Renamed paterns to paterns-module * [JAVA-14174] naming fixes Co-authored-by: panagiotiskakos <panagiotis.kakos@libra-is.com>
This commit is contained in:
+70
@@ -0,0 +1,70 @@
|
||||
package com.baeldung;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.camel.CamelContext;
|
||||
import org.apache.camel.ProducerTemplate;
|
||||
import org.apache.camel.RoutesBuilder;
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.apache.camel.component.jms.JmsComponent;
|
||||
import org.apache.camel.impl.DefaultCamelContext;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class AmqApplication {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SpringApplication.run(AmqApplication.class, args);
|
||||
|
||||
try (CamelContext context = new DefaultCamelContext()) {
|
||||
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
|
||||
"vm://localhost?broker.persistent=false");
|
||||
connectionFactory.setTrustAllPackages(true);
|
||||
context.addComponent("direct", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
|
||||
addRoute(context);
|
||||
|
||||
try (ProducerTemplate template = context.createProducerTemplate()) {
|
||||
context.start();
|
||||
|
||||
MyPayload payload = new MyPayload("One");
|
||||
template.sendBody("direct:source", payload);
|
||||
Thread.sleep(10000);
|
||||
} finally {
|
||||
context.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void addRoute(CamelContext context) throws Exception {
|
||||
context.addRoutes(newExchangeRoute());
|
||||
}
|
||||
|
||||
static RoutesBuilder traditionalWireTapRoute() {
|
||||
return new RouteBuilder() {
|
||||
public void configure() {
|
||||
|
||||
from("direct:source").log("Main route: Send '${body}' to tap router").wireTap("direct:tap").delay(1000)
|
||||
.log("Main route: Add 'two' to '${body}'").bean(MyBean.class, "addTwo").to("direct:destination")
|
||||
.log("Main route: Output '${body}'");
|
||||
|
||||
from("direct:tap").log("Tap Wire route: received '${body}'")
|
||||
.log("Tap Wire route: Add 'three' to '${body}'").bean(MyBean.class, "addThree")
|
||||
.log("Tap Wire route: Output '${body}'");
|
||||
|
||||
from("direct:destination").log("Output at destination: '${body}'");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
static RoutesBuilder newExchangeRoute() throws Exception {
|
||||
return new RouteBuilder() {
|
||||
public void configure() throws Exception {
|
||||
|
||||
from("direct:source").wireTap("direct:tap").onPrepare(new MyPayloadClonePrepare()).end().delay(1000);
|
||||
|
||||
from("direct:tap").bean(MyBean.class, "addThree");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.baeldung;
|
||||
|
||||
public class MyBean {
|
||||
|
||||
public MyPayload addTwo(MyPayload body) {
|
||||
body.setValue(body.getValue() + " and two");
|
||||
return body;
|
||||
}
|
||||
|
||||
public MyPayload addThree(MyPayload body) {
|
||||
body.setValue(body.getValue() + " and three");
|
||||
return body;
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.baeldung;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class MyPayload implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private String value;
|
||||
|
||||
public MyPayload(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public MyPayload deepClone() {
|
||||
MyPayload myPayload = new MyPayload(value);
|
||||
return myPayload;
|
||||
}
|
||||
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.baeldung;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.camel.Exchange;
|
||||
import org.apache.camel.Processor;
|
||||
|
||||
public class MyPayloadClonePrepare implements Processor {
|
||||
|
||||
public void process(Exchange exchange) throws Exception {
|
||||
MyPayload myPayload = exchange.getIn().getBody(MyPayload.class);
|
||||
exchange.getIn().setBody(myPayload.deepClone());
|
||||
exchange.getIn().setHeader("date", new Date());
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
# to keep the JVM running
|
||||
camel.springboot.main-run-controller = true
|
||||
|
||||
#configure the URL of the remote ActiveMQ broker
|
||||
#camel.component.activemq.broker-url=tcp://localhost:61616
|
||||
#spring.activemq.broker-url=tcp://localhost:61616
|
||||
|
||||
spring.activemq.in-memory=true
|
||||
spring.activemq.pool.enabled=false
|
||||
@@ -0,0 +1,16 @@
|
||||
# Root logger option
|
||||
log4j.rootLogger=INFO, file, console
|
||||
|
||||
log4j.logger.com.javarticles=INFO, file
|
||||
|
||||
# Direct log messages to a log file
|
||||
log4j.appender.file=org.apache.log4j.FileAppender
|
||||
log4j.appender.file.File=javarticles.log
|
||||
log4j.appender.file.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.file.layout.ConversionPattern=%d | %p | %F %L | %m%n
|
||||
|
||||
# Direct log messages to stdout
|
||||
log4j.appender.console=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.console.Target=System.out
|
||||
log4j.appender.console.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.console.layout.ConversionPattern=%d{HH:mm}| %p | %F %L | %m%n
|
||||
Reference in New Issue
Block a user