274.3. 运行时查找
当您需要在可以在运行时计算 URI 的 registry 中动态发现端点时,可以使用这个组件。然后,您可以使用以下代码查找端点:
// lookup the endpoint String myEndpointRef = "bigspenderOrder"; Endpoint endpoint = context.getEndpoint("ref:" + myEndpointRef); Producer producer = endpoint.createProducer(); Exchange exchange = producer.createExchange(); exchange.getIn().setBody(payloadToSend); // send the exchange producer.process(exchange);
然后,您可以有一个 Registry 中定义的端点列表,例如:
<camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring"> <endpoint id="normalOrder" uri="activemq:order.slow"/> <endpoint id="bigspenderOrder" uri="activemq:order.high"/> </camelContext>