Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0-M1
    • Component/s: camel-core
    • Labels:
      None
    1. camel-core.patch.2
      7 kB
      Martin Krasser
    2. camel-spring.patch
      4 kB
      Martin Krasser
    3. camel-core.patch
      26 kB
      Martin Krasser

      Issue Links

        Activity

        Hide
        davsclaus Claus Ibsen added a comment -

        We can do this today, but the DSL could be spiced up a bit.

        If we have the consumer template (oppose to producer template) you could consume from a processor and enrhich the original exchange with the result.

        void process(Exchange e) {
          Exchange result = consumerTemplate.consume("jdbc:xxx")
          // enrich original exchange with result
        

        Letting you do the enrich in Java gives you the full power how it should be enriched.

        Show
        davsclaus Claus Ibsen added a comment - We can do this today, but the DSL could be spiced up a bit. If we have the consumer template (oppose to producer template) you could consume from a processor and enrhich the original exchange with the result. void process(Exchange e) { Exchange result = consumerTemplate.consume( "jdbc:xxx" ) // enrich original exchange with result Letting you do the enrich in Java gives you the full power how it should be enriched.
        Hide
        mrt1nz Martin Krasser added a comment -

        You might also want to take a look at the content enricher in the Open eHealth Integration Platform (IPF) which is based on Camel. The example is written in Groovy but its easy to make it running in Java a well (except for using the closure). If you think this way of content enrichement is helpful for you I can contribute the enricher to Camel. Any thoughts?

        Show
        mrt1nz Martin Krasser added a comment - You might also want to take a look at the content enricher in the Open eHealth Integration Platform (IPF) which is based on Camel. The example is written in Groovy but its easy to make it running in Java a well (except for using the closure). If you think this way of content enrichement is helpful for you I can contribute the enricher to Camel. Any thoughts?
        Hide
        davsclaus Claus Ibsen added a comment -

        Martin, looks great. Closures really comes handy for the merge logic.

        We have also talked about a DSL for spawning an Exchange so there could be a double win here, since I see that enricher needs to spawn an Exchange.

        And as always we love contributions

        Show
        davsclaus Claus Ibsen added a comment - Martin, looks great. Closures really comes handy for the merge logic. We have also talked about a DSL for spawning an Exchange so there could be a double win here, since I see that enricher needs to spawn an Exchange. And as always we love contributions
        Hide
        janstey Jonathan Anstey added a comment -

        Very nice impl Martin. We'd love it contributed to Camel!

        Show
        janstey Jonathan Anstey added a comment - Very nice impl Martin. We'd love it contributed to Camel!
        Hide
        mrt1nz Martin Krasser added a comment -

        Attached are two patches that add content support enrichment to Camel trunk. A Java DSL example is

        AggregationStrategy myAggregationStartegy = ...
        
        from("direct:start")
        .enrich("direct:resource", myAggregationStrategy)
        .to("mock:result");
        
        // get additional data from this endpoint
        from("direct:resource")
        .transform().constant("blah");
        ...
        

        A Spring DSL example is

          <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
            <route>
              <from uri="direct:start"/>
              <enrich resourceUri="direct:resource" aggregationStrategyRef="sampleAggregator"/>
              <to uri="mock:result"/>
            </route>
            <route>
              <from uri="direct:resource"/>
              <transform>
                <constant>blah</constant>
              </transform>
            </route>
          </camelContext>
        
          <bean id="sampleAggregator" class="org.apache.camel.processor.enricher.SampleAggregator" />
        

        If you don't have any objections to these patches I'll add some documentation to the Camel Wiki.

        Show
        mrt1nz Martin Krasser added a comment - Attached are two patches that add content support enrichment to Camel trunk. A Java DSL example is AggregationStrategy myAggregationStartegy = ... from("direct:start") .enrich("direct:resource", myAggregationStrategy) .to("mock:result"); // get additional data from this endpoint from("direct:resource") .transform().constant("blah"); ... A Spring DSL example is <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="direct:start"/> <enrich resourceUri="direct:resource" aggregationStrategyRef="sampleAggregator"/> <to uri="mock:result"/> </route> <route> <from uri="direct:resource"/> <transform> <constant>blah</constant> </transform> </route> </camelContext> <bean id="sampleAggregator" class="org.apache.camel.processor.enricher.SampleAggregator" /> If you don't have any objections to these patches I'll add some documentation to the Camel Wiki.
        Hide
        janstey Jonathan Anstey added a comment -

        Looks cool. Just taking a peek at the source now.

        Show
        janstey Jonathan Anstey added a comment - Looks cool. Just taking a peek at the source now.
        Hide
        janstey Jonathan Anstey added a comment -

        Martin,

        I just committed your patches in revision 743442. Great work!

        I'm wondering now if we should shorten the Spring syntax a bit though. Something like this would align better with the other processors

        <enrich uri="direct:resource" strategyRef="sampleAggregator"/>
        

        What do you think?

        Show
        janstey Jonathan Anstey added a comment - Martin, I just committed your patches in revision 743442. Great work! I'm wondering now if we should shorten the Spring syntax a bit though. Something like this would align better with the other processors <enrich uri= "direct:resource" strategyRef= "sampleAggregator" /> What do you think?
        Hide
        mrt1nz Martin Krasser added a comment -

        Let's do that. Do you need a further patch or do you want to change that yourself?

        Show
        mrt1nz Martin Krasser added a comment - Let's do that. Do you need a further patch or do you want to change that yourself?
        Hide
        janstey Jonathan Anstey added a comment -

        No need for a patch. I'll update it shortly.

        Show
        janstey Jonathan Anstey added a comment - No need for a patch. I'll update it shortly.
        Hide
        janstey Jonathan Anstey added a comment -

        Committed the change in rev 743474.

        Show
        janstey Jonathan Anstey added a comment - Committed the change in rev 743474.
        Hide
        davsclaus Claus Ibsen added a comment -

        Martin. Great work.

        Yeah I was about to suggest to use uri as the attribute in spring DSL but I can see that you have also that covered.

        Show
        davsclaus Claus Ibsen added a comment - Martin. Great work. Yeah I was about to suggest to use uri as the attribute in spring DSL but I can see that you have also that covered.
        Hide
        davsclaus Claus Ibsen added a comment -

        In the enrich code part where you create a producer template you need to close it as well

        See this faq:
        http://camel.apache.org/why-does-camel-use-too-many-threads-with-producertemplate.html

        It would be better to create it once and keep it around. We have the service interface for that with start/stop.

        I will patch it.

        Show
        davsclaus Claus Ibsen added a comment - In the enrich code part where you create a producer template you need to close it as well See this faq: http://camel.apache.org/why-does-camel-use-too-many-threads-with-producertemplate.html It would be better to create it once and keep it around. We have the service interface for that with start/stop. I will patch it.
        Hide
        davsclaus Claus Ibsen added a comment -

        Martin, please feel free to add some wiki documentation to this great new feature. Its great with the community stepping up to help.

        And we should mention it on the release guide as well
        http://camel.apache.org/camel-200-release.html

        Show
        davsclaus Claus Ibsen added a comment - Martin, please feel free to add some wiki documentation to this great new feature. Its great with the community stepping up to help. And we should mention it on the release guide as well http://camel.apache.org/camel-200-release.html
        Hide
        davsclaus Claus Ibsen added a comment -

        On the EIP page:
        http://camel.apache.org/content-enricher.html

        Maybe we should divide it into 2 sections

        • the old solution, where you have full power in a processor and can enrich the exchange how you like it
        • and the new one with the enrich DSL

        So end users can see two kind of solutions.

        Show
        davsclaus Claus Ibsen added a comment - On the EIP page: http://camel.apache.org/content-enricher.html Maybe we should divide it into 2 sections the old solution, where you have full power in a processor and can enrich the exchange how you like it and the new one with the enrich DSL So end users can see two kind of solutions.
        Hide
        mrt1nz Martin Krasser added a comment -

        Claus,

        wouldn't it be even better to resolve the resource endpoint in the EnricherType.doCreateProcessor() method, create a producer from that endpoint and inject that producer into the Enricher?

        public class EnricherType extends OutputType<EnricherType> {
        
          ...
        
          public Processor createProcessor(RouteContext routeContext) throws Exception {
              Enricher enricher = new Enricher(...);
              enricher.setProducer(routeContext.resolveEndpoint(resourceUri).createProducer());
              ...
              return enricher;
          }
        
        }
        

        The Enricher then starts and stops the producer within its start()/stop() methods and uses it in its process(Exchange) method to send the resourceExchange

        public class Enricher extends ServiceSupport implements Processor {
        
           public void process(Exchange exchange) {
              ...
              producer.process(resourceExchange);
              ...
           }
        }
        

        Then the enricher creation and wiring code has been moved to the EnricherType and the Enricher is only doing the logic it needs to do. What do you think?

        I can provide a patch if you want.

        Show
        mrt1nz Martin Krasser added a comment - Claus, wouldn't it be even better to resolve the resource endpoint in the EnricherType.doCreateProcessor() method, create a producer from that endpoint and inject that producer into the Enricher? public class EnricherType extends OutputType<EnricherType> { ... public Processor createProcessor(RouteContext routeContext) throws Exception { Enricher enricher = new Enricher(...); enricher.setProducer(routeContext.resolveEndpoint(resourceUri).createProducer()); ... return enricher; } } The Enricher then starts and stops the producer within its start()/stop() methods and uses it in its process(Exchange) method to send the resourceExchange public class Enricher extends ServiceSupport implements Processor { public void process(Exchange exchange) { ... producer.process(resourceExchange); ... } } Then the enricher creation and wiring code has been moved to the EnricherType and the Enricher is only doing the logic it needs to do. What do you think? I can provide a patch if you want.
        Hide
        davsclaus Claus Ibsen added a comment -

        @Martin

        Good idea. Patch is much welcome.

        Show
        davsclaus Claus Ibsen added a comment - @Martin Good idea. Patch is much welcome.
        Hide
        mrt1nz Martin Krasser added a comment - - edited

        Here's the patch to resolve the resource endpoint inside the EnricherType (camel-core.patch.2).

        Show
        mrt1nz Martin Krasser added a comment - - edited Here's the patch to resolve the resource endpoint inside the EnricherType (camel-core.patch.2).
        Hide
        janstey Jonathan Anstey added a comment -

        Committed your patch in revision 743733. Thanks again Martin.

        Show
        janstey Jonathan Anstey added a comment - Committed your patch in revision 743733. Thanks again Martin.
        Hide
        janstey Jonathan Anstey added a comment -

        Documentation looks good. I'm closing this one.

        Show
        janstey Jonathan Anstey added a comment - Documentation looks good. I'm closing this one.
        Hide
        davsclaus Claus Ibsen added a comment -

        Closing 2.0m1 tickets

        Show
        davsclaus Claus Ibsen added a comment - Closing 2.0m1 tickets

          People

          • Assignee:
            janstey Jonathan Anstey
            Reporter:
            nickysandhu Nicky Sandhu
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development