[
https://issues.apache.org/jira/browse/CAMEL-19749?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17801179#comment-17801179
]
Raymond commented on CAMEL-19749:
---------------------------------
Seems to going forward nicely
I was wondering if it will also be possible to use alternative store for
variables in this iteration? Or that it's planned for a next version/iteration?
The most flexible way would be to choose every component available for Camel
that can be both producer/consumer. Alternative is to introduce an additional
attribute if something can act as a store for variables or not (similar to
components that can implement SSL or not).
The default store for variables is in memory, if not set the store explicitly,
but the user may get the choice to use other components. Basically, then Camel
takes care to pass variable values between memory and a specific store
(component).
*Syntax*
Here are some syntax ideas to use external endpoints for variables:
Option 1: Using inline
{code:java}
<routes>
<route>
<setVariable name="myBody">
<constant>someValue</constant>
</setVariable>
<setVariable name="myBody2" uri="sql:insert into xxx?option1=value1">
<constant>someValue</constant>
</setVariable>
<getVariable uri="sql:select from xxx?option1=value1"/>
<setVariable name="myBody3" uri="ehcache:mycache?action=create">
<constant>someValue</constant>
</setVariable>
<getVariable name="myBody2" uri="ehcache:mycache?action=read"/>
</route>
</routes> {code}
Option 2: Using inline
{code:java}
<routes>
<route>
<setVariable name="myBody">
<constant>someValue</constant>
</setVariable>
<setVariable name="myBody2">
<to uri="sql:insert into xxx?option1=value1"/>
</setVariable>
<getVariable name="myBody2">
<to uri="sql:select from xxx?option1=value1"/>
</getVariable>
<setVariable name="myBody3" strategy="storeEhcachProcessor">
<to ehcache:mycache?action=create/>
</setVariable>
<getVariable name="myBody2">
<to ehcache:mycache?action=read/>
</getVariable>
</route>
</routes>
{code}
Option 3: Using strategies / processors
{code:java}
<routes>
<route>
<setVariable name="myBody">
<constant>someValue</constant>
</setVariable>
<setVariable name="myBody2" strategy="storePostgressProcessor">
<constant>someValue</constant>
</setVariable>
<setVariable name="myBody3" strategy="storeEhcachProcessor">
<constant>someValue</constant>
</setVariable>
</route>
</routes>
{code}
Option 4: Using subroutes
{code:java}
<routes>
<route>
<setVariable name="myBody">
<constant>someValue</constant>
</setVariable>
<setVariable name="myBody2" route="storeProgress">
<constant>someValue</constant>
</setVariable>
<setVariable name="myBody3" route="postgress">
<constant>someValue</constant>
</setVariable>
</route>
<route name="insertProgress">
<from uri="direct:in">
<to uri="sql:insert into xxx?option1=value1"/>
<to uri="direct:out"/>
</route>
<from uri="direct:in">
<to ehcache:mycache?action=create/>
<to uri="direct:out"/>
</route>
</routes>
{code}
Option 5: Using configuration
Something like restConfiguration where you configure the CRUD actions
<variableStores>
<variableStore storeName="postgress">
<set uri="sql:insert into xxx?option1=value1"/>
<get uri="sql:select from xxx?option1=value1"/>
<remove uri="sql:delete from ?option1=value1"/>
</variableStore>
<variableStore storeName="cache">
<set uri="ehcache:mycache?action=create"/>
<get uri="ehcache:mycache?action=read"/>
<remove uri="ehcache:mycache?action=remove"/>
</variableStore>
<variableStores>
<route>
<setVariable name="myBody">
<constant>someValue</constant>
</setVariable>
<setVariable name="myBody2" storeName="postgress">
<constant>someValue</constant>
</setVariable>
<setVariable name="myBody3" storeName="postgress">
<constant>someValue</constant>
</setVariable>
</route>
There are other syntax options to solve this, but these were a couple I could
think of.
> camel-core - Allow users to use variables in route to store data instead of
> headers
> -----------------------------------------------------------------------------------
>
> Key: CAMEL-19749
> URL: https://issues.apache.org/jira/browse/CAMEL-19749
> Project: Camel
> Issue Type: New Feature
> Components: camel-core, eip
> Reporter: Claus Ibsen
> Assignee: Claus Ibsen
> Priority: Major
> Fix For: 4.4.0
>
>
> Users that need to do message transformation in Camel routes may find
> themselves having to store data in headers / claim-check / exchange
> properties from multiple sources before they have all data needed to build a
> response message.
> Today users are doing this in different ways.
> However we may want to introduce variables that users can name and store the
> data, then they can do this more intuitive, like they would do in a
> programming language.
> {code}
> from(kafka("topic1").setVar("customer"))
> .to("sql:get-order-by-cust?id=${var.customer.id}").setVar("order")
> .transform().simple( ' Thank you ${var.customer.name} for ordering
> ${var.order.item}'))
> {code}
> Then you have 2 variables
> - customer
> - order
> Then the variable customer can be used anywhere in Camel like it was a header
> with ${header.xxx} but with ${var.customer} in the simple language etc.
> This proposal needs some more though and design/prototype.
> But this should be done in a way that does not affect regular Camel DSL as it
> is, but with variables then results during routing that usually will be
> override current message body / headers, are stored in variables, that the
> user assign a name and therefore better can understand what the data the
> variable contains are.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)