Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,9 @@
*/
package org.apache.camel.example.java8;

import java.util.Date;
import java.util.Objects;

import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.main.Main;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class MyApplication {
private static final Logger LOGGER = LoggerFactory.getLogger(MyApplication.class);

private MyApplication() {
}
Expand All @@ -36,42 +27,4 @@ public static void main(String[] args) throws Exception {
Main main = new Main(MyApplication.class);
main.run(args);
}

static class MyRouteBuilder extends RouteBuilder {

@Override
public void configure() throws Exception {
from("timer:simple?includeMetadata=true&period=503")
.id("simple-route")
.transform()
.exchange(this::dateToTime)
.process()
.message(this::log)
.process()
.body(this::log)
.choice()
.when()
.body(Integer.class, b -> (b & 1) == 0)
.log("Received even number")
.when()
.body(Integer.class, b -> (b & 1) != 0)
.log("Received odd number")
.when()
.body(Objects::isNull)
.log("Received null body")
.end();
}

private Long dateToTime(Exchange e) {
return e.getProperty(Exchange.TIMER_FIRED_TIME, Date.class).getTime();
}

private void log(Object b) {
LOGGER.info("body is: {}", b);
}

private void log(Message m) {
LOGGER.info("message is: {}", m);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.apache.camel.example.java8;
Comment thread
davsclaus marked this conversation as resolved.

import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.builder.RouteBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;
import java.util.Objects;

public class MyRouteBuilder extends RouteBuilder {
private static final Logger LOGGER = LoggerFactory.getLogger(MyApplication.class);
@Override
public void configure() throws Exception {
from("timer:simple?includeMetadata=true&period=503")
Comment thread
davsclaus marked this conversation as resolved.
.id("simple-route")
.transform()
.exchange(this::dateToTime)
.process()
.message(this::log)
.process()
.body(this::log)
.choice()
.when()
.body(Integer.class, b -> (b & 1) == 0)
.log("Received even number")
.when()
.body(Integer.class, b -> (b & 1) != 0)
.log("Received odd number")
.when()
.body(Objects::isNull)
.log("Received null body")
.end();
}

private Long dateToTime(Exchange e) {
return e.getProperty(Exchange.TIMER_FIRED_TIME, Date.class).getTime();
}

private void log(Object b) {
LOGGER.info("body is: {}", b);
}

private void log(Message m) {
LOGGER.info("message is: {}", m);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ void should_be_evaluated() {

@Override
protected void configure(MainConfigurationProperties configuration) {
configuration.addRoutesBuilder(new MyApplication.MyRouteBuilder());
configuration.addRoutesBuilder(new MyRouteBuilder());
}
}