Hi
This starts to look really good.
I would suggest renaming
.inMessage(m -> m.getBody() == null)
To just message
.message(m -> m.getBody() == null)
On Wed, Sep 7, 2016 at 2:22 PM, Luca Burgazzoli <[email protected]> wrote:
> Vitalii, it was the first iteration just to have some feedbacks ;)
>
> I've added something more now as experiment so your suggestions should
> have been covered now.
> By extending ExpressionClause built-in body/inMessage/etc, we could
> have something like:
>
> from("timer:simple?period=503")
> .id("simple-route")
> .transform()
> .exchange(this::dateToTime)
> .choice()
> .when()
> .body(Integer.class, b -> (b & 1) == 0)
> .log("Received even number")
> .when()
> .body(Integer.class, (b, h) -> h.containsKey("skip") ?
> false : (b & 1) == 0)
> .log("Received odd number")
> .when()
> .body(b -> b instanceof Number)
> .log("Received a number number")
> .when()
> .inMessage(m -> m.getBody() == null)
> .log("Received null body")
> .when()
> .body(Integer.class, b -> (b & 1) == 0)
> .log("Received odd number")
> .endChoice();
>
>
>
> ---
> Luca Burgazzoli
>
>
> On Wed, Sep 7, 2016 at 2:16 PM, Vitalii Tymchyshyn <[email protected]> wrote:
>> Hi.
>>
>> Why BodyFunction is a BiFunction? It would be great to have some method to
>> pass any Functional interface (any function) that would receive body as
>> parameter and result would be stored as an answer. This would allow to use
>> tons of existing functional method.
>> E.g. something like this would be possible:
>> .transform(function(String.class, String::toUpperCase))
>> Another thing is that often body type is not needed, e.g.
>> .transform(onBody(String::toUpperCase)) looks more readable.
>> i'd also rename other "function" calls with something that gives more
>> information like "onExchange", "onMessage" (or even simply body(),
>> exchange(), message()). This would also make casting unnesessary.
>>
>> Best regards, Vitalii Tymchyshyn
>>
>> Вт, 6 вер. 2016 о 11:38 Luca Burgazzoli <[email protected]> пише:
>>
>>> Hello everyone,
>>> I've started working on CAMEL-7831 to create a Java8 example to use
>>> Expressions and I've ended up with a simple example - see [1].
>>> Of course it is only for demonstrative purpose.
>>>
>>> Java8 lambda support to Expressions has been added to
>>> - ExpressionClause to avoid adding overload method for every method
>>> accepting an Expressions definition
>>> - ExpressionBuilder so you can use something like transform(function(e ->
>>> ...))
>>>
>>> There are some additional functional interfaces to select the argument
>>> of the lambda
>>> - ExchangeFunction
>>> - MessageFunction
>>> - BodyFunction
>>>
>>>
>>> Any feedback would be really appreciated.
>>>
>>> Regards,
>>> Luca
>>>
>>>
>>> [1]
>>> https://github.com/lburgazzoli/apache-camel/blob/CAMEL-7831/examples/camel-example-dsl-java8/src/main/java/org/apache/camel/example/dsl/java8/MyRoute.java
>>>
>>>
>>> ---
>>> Luca Burgazzoli
>>>
--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2