83.3. 사용법
83.3.1. 기본 모드 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
다음은 Camel YAML DSL 태그 내에 정의할 때 리플렉션을 위해 클래스를 등록해야 합니다. 자세한 내용은 기본 모드 가이드를 참조하십시오.
83.3.1.1. Quarkus 정의 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
YAML DSL은 다음과 같이 빈을 정의하는 기능을 제공합니다.
- beans:
- name: "greetingBean"
type: "org.acme.GreetingBean"
properties:
greeting: "Hello World!"
- route:
id: "my-yaml-route"
from:
uri: "timer:from-yaml?period=1000"
steps:
- to: "bean:greetingBean"
이 예에서는 리플렉션 을 위해 등록되어야 합니다. 이는 YAML 경로의 빈 키에서 참조하는 모든 유형에 적용됩니다.
@RegisterForReflection
public class GreetingBean {
}
83.3.1.2. 예외 처리 링크 복사링크가 클립보드에 복사되었습니다!
링크 복사링크가 클립보드에 복사되었습니다!
Camel은 예외를 처리하는 다양한 방법을 제공합니다. 이러한 중 일부는 DSL 정의에서 참조되는 모든 예외 클래스가 반영을 위해 등록되어야 합니다.
on-exception
- on-exception:
handled:
constant: "true"
exception:
- "org.acme.MyHandledException"
steps:
- transform:
constant: "Sorry something went wrong"
@RegisterForReflection
public class MyHandledException {
}
throw-exception
- route:
id: "my-yaml-route"
from:
uri: "direct:start"
steps:
- choice:
when:
- simple: "${body} == 'bad value'"
steps:
- throw-exception:
exception-type: "org.acme.ForcedException"
message: "Forced exception"
otherwise:
steps:
- to: "log:end"
@RegisterForReflection
public class ForcedException {
}
do-catch
- route:
id: "my-yaml-route2"
from:
uri: "direct:tryCatch"
steps:
- do-try:
steps:
- to: "direct:readFile"
do-catch:
- exception:
- "java.io.FileNotFoundException"
steps:
- transform:
constant: "do-catch caught an exception"
@RegisterForReflection(targets = FileNotFoundException.class)
public class MyClass {
}