如何从 groovy 元素访问 Camel 的 属性 CamelLoopIndex?

How to access Camel's property CamelLoopIndex from groovy element?

我有一个 headers 的设置,其中 groovy 个元素如下:

  <setHeader headerName="time_to">
    <groovy>1625761488 - 3600*(properties.resolve(CamelLoopIndex)-1)</groovy>
  </setHeader>
  <setHeader headerName="time_from">
    <groovy>1625761488 - 3600*properties.resolve(CamelLoopIndex)</groovy>
  </setHeader>

但是在执行路线时我遇到了这样的运行时错误:

groovy.lang.MissingPropertyException: No such property: CamelLoopIndex for class: script16306769092271458244993
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:67)
    at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:51)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:309)
    at script16306769092271458244993.run(script16306769092271458244993.groovy:1)

所以,问题是如何正确访问CamelLoopIndex

这里正确的做法是使用exchange.getProperty('CamelLoopIndex'):

    <setHeader headerName="time_to">
        <groovy>1625761488 - 3600*(exchange.getProperty('CamelLoopIndex')-1)</groovy>
      </setHeader>
      <setHeader headerName="time_from">
        <groovy>1625761488 - 3600*exchange.getProperty('CamelLoopIndex')</groovy>
      </setHeader>