Camel process
От: purser Россия  
Дата: 06.12.19 17:03
Оценка:
Подскажите, как, используя enrich, записать в хедер результат процессора и при агрегации сохранить оригинальный body.
Сейчас в хедер кладется что надо, но body пустой. Для примера написал роут start2, где всё норм.
Код пишу по памяти, мог опечататься.

<blueprint>
<bean id="flexible" class="org.apache.camel.util.toolbox.FlexibleAggregationStrategy"/>
<bean id="storeInHeader" ref="flexible" factory-method="storeInHeader" 
       class="org.apache.camel.util.toolbox.FlexibleAggregationStrategy">
    <argument>myHeader<argument>
</bean>
<bean id="myProcessor" class="MyProcessor "/>

<camelContext>
  <route>
    <from uri="direct:start1"/>
    <enrich strategyRef="storeInHeader">
      <constant>direct:fromBean</constant>    
    </enrich>
    <!-- Здесь в header[myHeader] лежит "Enrichment", но пустой body  -->
  </route>

  <route>
    <from uri="direct:fromBean"/>
    <process ref="myProcessor" />
  </route>

  <route>
    <from uri="direct:start2"/>
    <enrich strategyRef="storeInHeader">
      <constant>direct:fromSetBody</constant>    
    </enrich>
    <!-- Здесь всё норм, в header[myHeader] лежит "Enrichment" и body как надо (который пришел на роут)-->
  </route>


  <route>
    <from uri="direct:fromSetBody"/>
    <setBody>
        <constant>Enrichment</constant>
    </setBody>
  </route>


</camelContext>
</blueprint>


public class MyProcessor implements Processor {
    @Override
    public void process(Exchange exchange) throws Exception {
        exchange.getOut().setBody("Enrichment");
    }
}
Отредактировано 06.12.2019 17:04 purser . Предыдущая версия .
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.