Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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,65 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.example.java8;

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")
.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());
}
}
Loading