RoutePolicy:
Код: Выделить всё
@Slf4j
@RequiredArgsConstructor
public class LoggingPolicy extends RoutePolicySupport {
private final String greeting;
@Override
public void onExchangeBegin(Route route, Exchange exchange) {
super.onExchangeBegin(route, exchange);
log.info("%s from LoggingPolicy".formatted(greeting));
}
}
Код: Выделить всё
public abstract class BaseRouteBuilder
extends RouteBuilder {
@Override
public void configure() throws Exception {
onException()
.handled(true)
.log("Exception occured")
.end();
configRoutes();
}
abstract void configRoutes();
}
Код: Выделить всё
@Component
public class HelloRouteBuilder extends BaseRouteBuilder {
@Override
void configRoutes() {
from("timer:hello?repeatCount=1")
.routeId("HelloRoute")
.routePolicy( new LoggingPolicy("Hello"))
.log("HelloRoute Completed");
}
}
@Component
public class ByeRouteBuilder extends BaseRouteBuilder {
@Override
void configRoutes() {
from("timer:bye?repeatCount=1")
.routeId("ByeRoute")
.routePolicy( new LoggingPolicy("Bye"))
.log("ByeRoute Completed");
}
}
Код: Выделить всё
@Component
public class AnotherRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
from("timer:another?repeatCount=1")
.routeId("AnotherRoute")
.log("AnotherRoute Completed");
}
}
Теперь я хочу делегировать LoggingPolicy в BaseRouteBuilder, чтобы
- Политика журналирования применяется ко всем маршрутам во всех RouteBuilder, наследующих форму BaseRouteBuilder (в этом примере HelloRoute и ByeRoute, но не AnotherRoute< /code>)
- параметр конструктора () по умолчанию имеет значение «Привет», но его можно переопределить в построителе маршрутов.
Код: Выделить всё
greeting
Подробнее здесь: https://stackoverflow.com/questions/791 ... ache-camel
Мобильная версия