java Apache camel与spring事件基本示例
使用Java和Spring3。我正在编写一个使用ApacheCamel路由生成和使用基于spring的事件的示例。我很惊讶谷歌搜索没有返回任何有意义的结果。我的意思不是一个使用ApacheCamel和spring事件组件的示例
下面是我的event object/publisher/listener,有人可以帮助我使用apachecamel-spring event://DSL转换它
感谢您的帮助
我的自定义事件类
public class CustomSpringEvent extends ApplicationEvent {
private String message;
public CustomSpringEvent(Object source, String message) {
super(source);
this.message = message;
}
public String getMessage() {
return message;
}
}
出版商
@Component
public class CustomSpringEventPublisher {
@Autowired
private ApplicationEventPublisher applicationEventPublisher;
public void publishCustomEvent(final String message) {
System.out.println("Publishing custom event. ");
CustomSpringEvent customSpringEvent = new CustomSpringEvent(this, message);
applicationEventPublisher.publishEvent(customSpringEvent);
}
}
听众
@Component
public class CustomSpringEventListener {
@EventListener
public void onApplicationEvent(CustomSpringEvent event) {
System.out.println("Received spring custom event - " + event.getMessage());
}
}
春季活动
https://www.baeldung.com/spring-events
apachecamel-spring事件组件
https://camel.apache.org/components/3.4.x/spring-event-component.html
# 1 楼答案
您只需创建一条从
spring-event:foo
开始的驼峰路线,其中foo可以是任何东西