[英]Apache Camel default data format for a component
How to set default data format for a component in Apache Camel? 如何在Apache Camel中为组件设置默认数据格式?
I have a number of routes interacting with different ActiveMQ queues. 我有许多与不同的ActiveMQ队列交互的路由。 At the moment all of them look like
目前,他们所有人看起来像
from("...")
.process(...)
.marshal().json() // (1)
.to("activemq:queue:...");
or 要么
from("activemq:queue:...")
.unmarshal().json() // (2)
.process(...)
.to("...");
You could marshall/unmarshall using a named reference to a data format that you can define once (here as "myDefaultFormat") in your Camel Registry: 您可以使用对可在Camel注册表中定义一次的数据格式 (此处为“ myDefaultFormat”) 的命名引用进行编组/解组:
from("activemq:queue:...")
.unmarshal(myDefaultFormat)
This way, you dont have to repeat .json() everywhere (but ok, you have yet to repeat the named reference :-$ ) 这样,您不必到处重复.json()(但是,您还没有重复命名的引用:-$)
Using interceptors (Based on Claus Ibsen's comment) 使用拦截器(基于克劳斯·易卜生的评论)
new RouteBuilder() {
@Override
public void configure() throws Exception {
// interceptors
interceptSendToEndpoint("activemq:queue:*")
.marshal()
.json();
interceptFrom("activemq:queue:*")
.unmarshal()
.json();
// routes
from("...")
.process(...)
.to("activemq:queue:...");
from("activemq:queue:...")
.process(...)
.to("...");
}
}
Notes: 笔记:
RouteBuilder
. RouteBuilder
任何路由之前定义拦截器。 Otherwise IllegalArgumentException
is thrown explaining situation. IllegalArgumentException
来解释情况。 RouteBuilder
. RouteBuilder
定义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.