Message Transformation
- By Using transform() method
@Component
public class MyTimerRouterTransformation extends RouteBuilder {
@Override
public void configure() throws Exception {
from("timer:first-timer")
.log("${body}")
//// Transformation by Processing Method ////
.transform().constant("Time now is " + LocalDateTime.now())
.log("${body}")
.to("log:first-timer"); // Exchange[ExchangePattern: InOnly, BodyType: String, Body: My Constant Message]
}
}
- By Using a Bean
2-1) bean name 호출을 통한 transformation
@Component
public class MyTimerRouterBeanTransformationA extends RouteBuilder {
@Override
public void configure() throws Exception {
from("timer:first-timer")
.log("${body}")
//// Bean Transformation ////
.bean("getCurrentTimeBeanA") // bean 이름으로 bean 호출
.log("${body}")
.to("log:first-timer");
}
}
@Component
public class GetCurrentTimeBeanA {
public String getCurrentTime1() {
return "Time now is " + LocalDateTime.now();
}
}
2-2) Autowired 어노테이션으로 생성한 객체를 호출하여 transformation
. 아래와 같이 bean에 메소드가 2개 이상일 경우, 반드시 메소드명까지 명시해야 함
@Component
public class MyTimerRouterBeanTransformationB extends RouteBuilder {
@Autowired
private GetCurrentTimeBeanB getCurrentTimeBeanB;
@Override
public void configure() throws Exception {
from("timer:first-timer")
.log("${body}")
//// Bean Transformation ////
.bean(getCurrentTimeBeanB, "getCurrentTime1") // 메소드가 2개이상이면 메소드이름도 명시해야함
.log("${body}")
.to("log:first-timer");
}
}
@Component
public class GetCurrentTimeBeanB {
public String getCurrentTime1() {
return "1. Time now is " + LocalDateTime.now();
}
public String getCurrentTime2() {
return "2. Time now is " + LocalDateTime.now();
}
}
Message Processing
- By Using a Bean
. (3) getCurrentTimeBean을 통한 message transformation 이후에 message body가 바뀌었음을 알 수 있다
. (5) bean processing 이후에는 body가 변하지 않는다.
. bean method의 return type이 String이면 body 내용이 변하고(Transformation), void이면 message body가 변하지 않는다(Processing).
- By Creating Processor
'~2022 > Camel with Spring-Boot' 카테고리의 다른 글
[Camel Tutorial] Accessing Database with JDBC (0) | 2022.03.12 |
---|---|
[Camel Tutorial] Simple ActiveMQ Router (0) | 2022.03.12 |
[Camel Tutorial] Simple File Router (0) | 2022.03.12 |
[Camel Tutorial] Simple Timer Router (0) | 2022.03.12 |
[Camel Tutorial] Generate Spring Boot Project (0) | 2022.03.12 |