我们正在考虑使用事件驱动架构 (EDA) 来集成我们的一些粗粒度业务服务,并且这些服务 (REST) 的服务器端在 Java 和 .NET (C#) 中实现。我们最初认为使用 RabbitMQ(和 AMQP 协议)作为一种中立和开放的手段(在这两种语言中具有良好的客户端支持),但这意味着必须支持 Java 和 CLR 之外的另一个运行时(Erlang)。我们也在关注 Apache qPid,因为它具有 AMQP 协议的 Java 代理实现,这可能会消除这种担忧。
有没有人有尝试在 ActiveMQ 之上使用更丰富的 Apache Camel ESB 以 Pub-Sub EDA 方式集成 Java 和 .NET 服务的经验?我是否错过了有关通过此路线的任何其他可能的建议?
谢谢
如何在不等待端点的路由被处理的情况下向端点发送消息(也就是说,我的路由应该只发送消息并完成)?
我想将 Json 解组为 Map/List of Strings(例如 Map>...)
这是我的输入:
{"pointsOfSale":
{"pointOfSale":[
{"href":"\/pointsOfSale\/UUID.0abc2aca-7930-4c9e-9f38-8af3d0692e04",
"model":{"href":"\/models\/modelePointOfSale",
"modelType":{"href":"\/modelTypes\/pointOfSale"}},
"source":{"href":"\/sources\/TEST"},
"attribute":[
{"code":"pointOfSalePhysical","value":true},
{"code":"mail","value":"Mail1"},
{"code":"adresse","value":"address1"}]},
{"href":"\/pointsOfSale\/UUID.a12e7adf-652a-4197-91bf-d4785e43f09f",
"model":{"href":"\/models\/modelePointOfSale",
"modelType":{"href":"\/modelTypes\/pointOfSale"}},
"source":{"href":"\/sources\/Wikeo"},
"attribute":[
{"code":"pointOfSalePhysical","value":false},
{"code":"mail","value":"Mail1"},
{"code":"adresseMateriau","value":"Material address1"}]}
}}
Run Code Online (Sandbox Code Playgroud)
我希望能够在解组后做这样的“事情”:
myJsonMapped.get("pointsOfSale").get("pointOfSale").get(0).get("source").get("href").equals("\/sources\/TEST") == true
Run Code Online (Sandbox Code Playgroud)
例如,我们可以使用 Gson 进行这种解码:
new Gson().fromJson(json, Map.class);
Run Code Online (Sandbox Code Playgroud)
我知道我可以用一个简单的 bean 或处理器等来做到这一点......
我只是想知道我可以使用本机 JSON 骆驼组件配置更有效地做到这一点
编辑:我已经尝试了不同的东西,比如: unmarshal().json()... 或 unmarshal().json(JsonLibrary.Gson, Map.class).. 等等...没有成功:'(
如果我正在评估轻量级 EAI 框架的 Apache Camel 替代方案 - 我应该在评估中包括什么?
我想在 Camel Exchange 上设置一个属性,然后在保存文件时使用这个属性。在我的骆驼 dsl 中,我有以下内容:
.process(processorToSetExhangeProperty) // sets the property <uid> on the exchange
.to("file:/tmp?fileName=file-" + property("uid") + ".xml")
Run Code Online (Sandbox Code Playgroud)
该文件被保存为:
"file-property{uid}.xml" though
Run Code Online (Sandbox Code Playgroud)
我的处理器如下:
@Override
public void process(Exchange exchange) throws Exception {
UUID uuid = UUID.randomUUID();
exchange.setProperty("uid", uuid.toString());
exchange.setOut(exchange.getIn());
}
Run Code Online (Sandbox Code Playgroud)
关于可能出了什么问题或我如何实现这一目标的任何想法?
我试图在 Java bean 的主体上设置一个属性,该属性构成通过 Camel 路由传输的消息。我尝试了各种方法,例如
<route>
...
..
<transform>
<simple>${body.label} = ${property.label}</simple>
</transform>
...
..
</route>
Run Code Online (Sandbox Code Playgroud)
在这种特殊情况下,它${body}是一个带有setLabel(String label)方法的 Java bean,它${property.label}是通过其他方式在另一个路由中设置的。在这个例子中,结果不是想要的(我明白为什么),即在转换之后,消息的正文被替换为${body.label} = ${property.label}字符串。
我目前的解决方法是将转换器手动编码为 Spring bean 并在代码中设置 Java bean 的标签属性,但我想找出是否有更简单/更智能的方法来实现这一点,最好是在 XML DSL 中我用什么?
问候,奥拉
我想在一个单元测试中测试多个骆驼 RouteBuilder 测试我所拥有的:
改变状态的自定义骆驼处理器
public class MyProcessor implements Processor {
MyState state;
public MyProcessor(MyState state) {this.state = state;}
@Override
public void process(Exchange exchange) throws Exception {
state.setState(state.getState() + 5);
}}
Run Code Online (Sandbox Code Playgroud)
两个简单的 RouteBuilders:首先将消息从“direct:start”路由到“direct:endroute1”,然后从“direct:endroute1”获取消息并路由到“mock:endroute2”
public class MyRouteBuilder1 extends RouteBuilder {
MyState state;
public MyRouteBuilder1(MyState state) {this.state = state;}
@Override
public void configure() throws Exception {
from("direct:start").process(new MyProcessor(state)).to("direct:endroute1");
}}
public class MyRouteBuilder2 extends RouteBuilder {
MyState state;
public MyRouteBuilder2(MyState state) {this.state = state;}
@Override
public void configure() throws Exception {
from("direct:endroute1").process(new MyProcessor(state)).to("mock:endroute2");
}} …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Java DSL 和 RouteBuilder 实现 Camel 路由。我想从计时器端点发送到 cxf 端点。
public class MyRoute extends RouteBuilder {
@Override
public void configure() {
CamelContext camelContext = getContext();
CxfEndpoint cxfEndpoint = new CxfEndpoint();
cxfEndpoint.setAddress("http://localhost:8088/interface");
cxfEndpoint.setWsdlURL("wsdl/contract.wsdl");
cxfEndpoint.setCamelContext(camelContext);
cxfEndpoint.setDataFormat(DataFormat.PAYLOAD);
try {
camelContext.addEndpoint("myEndpoint", cxfEndpoint);
} catch (Exception e) {
e.printStackTrace();
}
from("timer://my-timer?fixedRate=true&period=500")
.transform(constant("DummyBody"))
.to("cxf://myEndpoint");
}
}
Run Code Online (Sandbox Code Playgroud)
这条路线被插入到使用 Spring XML 定义的骆驼上下文中(我还有一些其他路线)。
我收到以下错误:
karaf@root> Exception in thread "SpringOsgiExtenderThread-78" org.apache.camel.FailedToCreateProducerException: Failed to create Producer fo
r endpoint: Endpoint[cxf://myEndpoint]. Reason: java.lang.IllegalArgumentException: serviceClass must be specified
at org.apache.camel.impl.ProducerCache.doGetProducer(ProducerCache.java:395) …Run Code Online (Sandbox Code Playgroud) 我是使用 activemq 和 Camel 的新手。
我有这些问题:
我有一个 bean 和 bean 方法,它们由过滤器调用。
<filter>
<method ref="MyBean" method="CheckReceivedFilesByParameters"/>
<to uri="direct:b"/>
</filter>
Run Code Online (Sandbox Code Playgroud)
方法 CheckReceivedFilesByParameters 返回布尔值。如果为真,则下一条路线成功启动。错误时如何调用路由(直接:b)。我想用 xml 来做到这一点。我试图在标签外调用方法,但没有运气。
<to uri="bean:MyBean?method=CheckReceivedFilesByParameters"/>
<filter>
<simple>false</simple>
<to uri="direct:b"/>
</filter>
Run Code Online (Sandbox Code Playgroud)如何通过 Exchange 消息正确地将参数传递给 MyBean 方法。什么是最佳实践?现在我通过创建标题来做,稍后在我的方法中我得到 headerValues。我的 xml 中的示例。
<setHeader headerName="RouteId">
<constant>Test1</constant>
</setHeader>
Run Code Online (Sandbox Code Playgroud)
然后在 MyBean 方法值中获取标题。
String routeId = exchange.getIn().getHeader("RouteId", String.class);
应该有一些更“优雅”的方式。就像传递参数一样。就像在 servlet 中一样?
request.getParameter("par1")
提前致谢。
我正在尝试构建一个模块以插入 Spring Boot 应用程序。这个模块应该公开一些 REST 端点,我正在尝试用 Camel 构建它们,因为我不想向 web.xml 等添加内容。
restConfiguration().component("servlet")
.contextPath("/my")
.apiContextPath("/api-doc")
.apiProperty("api.title", "My REST API")
.apiProperty("cors", "true")
.apiContextRouteId("my-api")
.bindingMode(RestBindingMode.json);
rest("/my").description("My REST Services")
.get("foo/{id}").route().routeId("foo")
.to("direct:foo");
from("direct:foo")
.process(new FooParamParser())
.log("Done");
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是,不是在 /my/foo/123?status=abc 我必须在 /camel/my/foo/123?status=abc 打它。
它这样做是因为它默认使用 Camel Servlet 作为来自 DSL 的 REST 端点,我对此很好,但我不希望它把“/camel”放在我的路径的开头。我应该注意到,无论有没有.component("servlet")
有什么办法可以改变吗?
apache-camel ×10
java ×5
spring ×2
amqp ×1
c# ×1
cxf ×1
eai ×1
eda ×1
esb ×1
json ×1
spring-boot ×1
unit-testing ×1
xml ×1