gpt4 book ai didi

java - Apache Camel Unmarshal 到 Singleton Scoped Bean

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:00:04 25 4
gpt4 key购买 nike

我使用 Spring 作为我的 Bean 注册表,我目前有一个使用 Java DSL 定义的路由,如下所示:

@Override
public void configure() throws Exception {
from("netty:tcp://{{netty.host}}:{{netty.port}}?sync=false")
.routeId("pbxToBean").unmarshal("castor").to("mock:result");
}

它从 Netty 端点获取 XML 编码输入并将其解编为 PBX bean。

我在想我可以将我的结果 PBX bean 声明为单例,并让 Camel 将一个未编码的对象传递给处理器,然后处理器更新所述单例 bean。这行得通吗?

最佳答案

是的,如果 casor 是在注册表中绑定(bind)的 bean,

/**
* <a href="http://camel.apache.org/data-format.html">DataFormat:</a>
* Unmarshals the in body using the specified {@link DataFormat}
* reference in the {@link org.apache.camel.spi.Registry} and sets
* the output on the out message body.
*
* @param dataTypeRef reference to a {@link DataFormat} to lookup in the registry
* @return the builder
*/
@SuppressWarnings("unchecked")
public Type unmarshal(String dataTypeRef) {
addOutput(new UnmarshalDefinition(dataTypeRef));
return (Type) this;
}

关于java - Apache Camel Unmarshal 到 Singleton Scoped Bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29879107/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com