【发布时间】:2020-02-03 12:31:25
【问题描述】:
我正在寻找有关如何在 Java Config 中使用 Spring Boot 实现自定义 Apache Camel component 和 endpoint 的示例/文档。我不知道我必须如何注释类,请你提供一个例子。
如果不使用 Spring,我的(工作)代码如下所示:
public class MyCustomComponent extends DefaultComponent {
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
Endpoint endpoint = new MyCustomEndpoint(uri, this);
setProperties(endpoint, parameters);
return endpoint;
}
}
Registered 是resources/META-INF/services/org/apache/camel/component/myscheme 中具有MyCustomComponent 类的FQN 的组件。
public class MyCustomEndpoint extends DefaultEndpoint {
public MyCustomEndpoint(String uri, MyCustomComponent component) {
super(uri, component);
}
@Override
public Producer createProducer() throws Exception {
return new MyCustomProducer(this);
}
@Override
public Consumer createConsumer(Processor processor) throws Exception {
throw new UnsupportedOperationException("Not implemented yet: MyCustomEndpoint#createConsumer");
}
@Override
public boolean isSingleton() {
return false;
}
}
public class MyCustomProducer extends DefaultProducer {
public MyCustomProducer(Endpoint endpoint) {
super(endpoint);
}
@Override
public void process(Exchange exchange) throws Exception {
}
}
【问题讨论】:
-
以现有的Camel组件为例,isSingleton也应该返回true。
-
@Claus Ibsen 感谢您的回答。如何将 Spring Bean 注入
MyCustomProducer
标签: spring apache-camel spring-camel