How to create a timer based camel polling route?

Fluffy

i created a route that is supposed to read from an OPC-UA endpoint. The read operation should be performed every second, based on a timer. Every example i found shows that the route can only have one from item. My route looks like this:

<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>

When i deploy the route, it gets called every second, but it writes to the endpoint, since the call is declared in a to element. How can i turn this into a read? I could not find a solution so far. Thanks!

Souciance Eqdam Rashti

Use the .enrich() to turn it into a read when you want to read in the middle of a route. http://camel.apache.org/content-enricher.html

For your example something similar to (not tested):

<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>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related