2016-12-01 42 views
0

我创建了一个应该从OPC-UA端点读取的路由。读操作应该每秒执行一次,基于计时器。我发现的每个例子都显示路线只能有一个from项目。我的路线是这样的:如何创建基于计时器的骆驼轮询路线?

<camelContext xmlns="http://camel.apache.org/schema/blueprint"> 
    <route id="opctorest"> 
    <from uri="timer://simpleTimer?period=1000"/> 
    <log message="Triggered Route: opctorest: Sensorreading body: ${body}"/> 
    <to uri="milo-client:tcp://0.0.0.0:4840/freeopcua/server?nodeId=2&amp;namespaceUri=http://examples.freeopcua.github.io"/>   
    <convertBodyTo type="java.lang.String"/>   
    <to uri="stream:out"/> 
    </route> 
</camelContext> 

当我部署的路线,它被称为每一秒,但它写入到端点,因为该呼叫在to元素声明。我怎样才能把它变成一个阅读?到目前为止我找不到解决方案。谢谢!

回答

0

使用.enrich()可以在要读取路径中间时将其变为读取。 http://camel.apache.org/content-enricher.html

类似,对于你的榜样东西(未测试):

<camelContext xmlns="http://camel.apache.org/schema/blueprint"> 
    <route id="opctorest"> 
    <from uri="timer://simpleTimer?period=1000"/> 
    <log message="Triggered Route: opctorest: Sensorreading body: ${body}"/> 
    <enrich uri="milo-client:tcp://0.0.0.0:4840/freeopcua/server?nodeId=2&amp;namespaceUri=http://examples.freeopcua.github.io"/>   
    <convertBodyTo type="java.lang.String"/>   
    <to uri="stream:out"/> 
    </route> 
</camelContext> 
+0

顺便说也有PollingEnrich这样你就可以查询端点和基于某些间隔读取。也许这更适合你? –

+0

这样做的技巧,谢谢:) – Fluffy