In this lesson we will learn how to create a Red Hat Fuse project using JBoss Fuse tooling which is included in Red Hat Code Ready studio and to run a Fuse project within it.
Red Hat Code Ready studio is a development environment with superior support for your entire development lifecycle.
Start by downloading Red Hat Code Ready Studio: https://developers.redhat.com/products/codeready-studio/download
Once downloaded it, execute the JAR file:
$ java -jar codereadystudio-12.14.0.GA-installer-standalone.jar
The Red Hat Code Ready studio wizard will start. Just make sure you include the Fuse tooling in the installation:
At the end of the installation, you can launch Red Hat Code Ready studio .
Creating your first Fuse project with Fuse Tooling
From the File Menu choose: File | New | Fuse Integration Project:
Then select a Target Environment, for example a Standalone Spring Boot application:
In the next UI click Finish and a simple log using Spring Boot application will be generated
Let’s check the source code which has been added:
src └── main ├── fabric8 │ └── deployment.yml ├── java │ └── org │ └── mycompany │ └── Application.java └── resources ├── application.properties ├── logback.xml └── spring └── camel-context.xml
First of all, a spring-boot application Class that includes a Camel route builder to setup the Camel routes has been added:
@SpringBootApplication @ImportResource({"classpath:spring/camel-context.xml"}) public class Application { // must have a main method spring-boot can run public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
The above classes, imports as a Resource the following camel-context.xml file:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring https://camel.apache.org/schema/spring/camel-spring.xsd"> <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> <route id="simple-route"> <from id="route-timer" uri="timer://foo?period=1000"/> <setBody id="route-setBody"> <simple>Hello World from camel-context.xml</simple> </setBody> <log id="route-log" message=">>> ${body}"/> </route> </camelContext> </beans>
The route can be designed/edited graphically thanks to the Fuse Tooling plugin:
In order to run the application, just right-click on the Application Main class and choose “Run”.
The following log will be displayed in the Console Panel:
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.3.4.RELEASE) 09:54:05.170 [main] INFO org.mycompany.Application - Starting Application on fedora with PID 6928 (/home/francesco/codeready-projects/demofuse/target/classes started by francesco in /home/francesco/codeready-projects/demofuse) 09:54:05.174 [main] INFO org.mycompany.Application - No active profile set, falling back to default profiles: default 09:54:07.147 [main] INFO o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.apache.camel.spring.boot.CamelAutoConfiguration' of type [org.apache.camel.spring.boot.CamelAutoConfiguration$EnhancerBySpringCGLIB$d73737b8] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 09:54:07.502 [main] INFO o.a.c.i.c.DefaultTypeConverter - Type converters loaded (core: 195, classpath: 1) 09:54:07.961 [main] INFO o.a.c.spring.boot.RoutesCollector - Loading additional Camel XML routes from: classpath:camel/*.xml 09:54:07.961 [main] INFO o.a.c.spring.boot.RoutesCollector - Loading additional Camel XML rests from: classpath:camel-rest/*.xml 09:54:07.977 [main] INFO o.a.camel.spring.SpringCamelContext - Apache Camel 2.23.2.fuse-780036-redhat-00001 (CamelContext: MyCamel) is starting 09:54:07.978 [main] INFO o.a.c.m.ManagedManagementStrategy - JMX is enabled 09:54:08.196 [main] INFO o.a.camel.spring.SpringCamelContext - StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html 09:54:08.223 [main] INFO o.a.c.spring.boot.RoutesCollector - Starting CamelMainRunController to ensure the main thread keeps running 09:54:08.226 [main] INFO o.a.camel.spring.SpringCamelContext - Route: simple-route started and consuming from: timer://foo?period=1000 09:54:08.230 [main] INFO o.a.camel.spring.SpringCamelContext - Total 1 routes, of which 1 are started 09:54:08.236 [main] INFO o.a.camel.spring.SpringCamelContext - Apache Camel 2.23.2.fuse-780036-redhat-00001 (CamelContext: MyCamel) started in 0.253 seconds 09:54:08.256 [main] INFO org.mycompany.Application - Started Application in 3.431 seconds (JVM running for 3.839) 09:54:09.244 [Camel (MyCamel) thread #1 - timer://foo] INFO simple-route - >>> Hello World from camel-context.xml
Running Spring Boot and Fuse as Container Image
As you can check from the pom.xml, the project includes the fabric8-maven-plugin:
<?xml version="1.0" encoding="UTF-8"?><plugin> <groupId>org.jboss.redhat-fuse</groupId> <artifactId>fabric8-maven-plugin</artifactId> <version>${fuse.version}</version> <executions> <execution> <goals> <goal>resource</goal> <goal>build</goal> </goals> </execution> </executions> </plugin>
Before triggering the execution of the plugin, make sure Docker is started:
service docker start
Then from the shell you can run your project with:
mvn clean install spring-boot:run
The project will start, once that the container image of it has been created:
10:59:43.577 [Camel (MyCamel) thread #2 - timer://foo] INFO simple-route - >>> Hello World from camel-context.xml 10:59:44.577 [Camel (MyCamel) thread #2 - timer://foo] INFO simple-route - >>> Hello World from camel-context.xml 10:59:45.577 [Camel (MyCamel) thread #2 - timer://foo] INFO simple-route - >>> Hello World from camel-context.xml
You can check that the project Container image is available as follows:
$ docker images
mycompany/camel-ose-springboot-xml latest 71483fb79b90 2 minutes ago 517 MB
Source code for this tutorial: https://github.com/fmarchioni/masterspringboot/tree/master/camel/fuse/fuse7-spring-boot
You can continue learning how to create a Spring Boot Fuse project from the Command Line in this tutorial: Fuse example project with Spring Boot and Maven