[英]Apache Camel routing with recipientList
I'm trying to route messages dynamically with org.apache.camel. 我正在尝试使用org.apache.camel动态路由消息。
Here's my code : 这是我的代码:
from("direct:messenger")
.routeId("messenger-provider")
.bean(messengerService, "process")
.marshal().json(JsonLibrary.Jackson)
.setHeader(Exchange.HTTP_METHOD, constant("POST"))
.recipientList(header("access_token")).ignoreInvalidEndpoints()
And here's the part of my service class concerned : 这是我的服务类别的一部分:
exchange.getIn().setHeader("access_token", messengerServiceEndpoint.getEndpointUri()+"?access_token="+accessToken);
In fact I want to add the access_token dynamically to the endpoint URI. 实际上,我想将access_token动态添加到端点URI。 But i can only get the token from the service class.
但是我只能从服务类中获取令牌。
If anyone have some insights that would be great, thank you 如果有人有很好的见解,谢谢
I think what you are looking for is org.apache.camel.impl.JndiRegistry or org.apache.camel.impl.SimpleRegistry : 我认为您正在寻找的是org.apache.camel.impl.JndiRegistry或org.apache.camel.impl.SimpleRegistry :
You can bind your objects to the registry and retrieve where you need. 您可以将对象绑定到注册表,并在需要的地方检索。
http://camel.apache.org/registry.html http://camel.apache.org/registry.html
Check this link for creating SimpleRegistry and using in Java DSL: 检查此链接以创建SimpleRegistry并在Java DSL中使用:
http://preparationforinterview.com/preparationforinterview/camel-spring-bean-javadsl http://preparationforinterview.com/preparationforinterview/camel-spring-bean-javadsl
Below is a stackoverflow question on creating JNDIRegistry: 以下是有关创建JNDIRegistry的stackoverflow问题:
camel - get jndi registry 骆驼-获取jndi注册表
If you are using Spring, then you can use ApplicationContextRegistry: 如果您使用的是Spring,则可以使用ApplicationContextRegistry:
ApplicationContextRegistry registry = exchange.getContext().getRegistry(ApplicationContextRegistry.class);
Map<String,Object>map = (Map<String,Object>)registry.lookup("map");
map.put("objectVar", objectVar);
Have a map in your Spring config to load the objects: 在Spring配置中有一个映射来加载对象:
<bean id="map" class="java.util.HashMap"></bean>
Retrieve the objects: 检索对象:
Map<String,Object> map = (Map<String,Object>)registry.lookup("map");
Object1 o = (Object1) map.get("objectVar");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.