Steps to create a simple camel app using Apache Camel Spring Boot starters

I wanted to make a new simple app to verify the operation of the app made with ** Apache Camel **, but I made the Java system from scratch. I don't know what to do because there is almost no.

For the time being, following the explanation on the official page, I made a camel app that has a route that logs every second. I will not verify the startup of camel, so use ** Camel Spring Boot starters ** that seems to be easy to make. It was.

environment


Preparing the project

I somehow know that pom.xml is needed for maven, but I don't know how to write it at this point. Since the only thing that appears on camel's page is how to write dependencies, we have to prepare an outer frame.

I couldn't help it, so I made a new project with IDE (IntelliJ IDEA).

  1. File → New → Project...
  2. First screen
  3. Select Maven from the list on the left
  4. Project SDK remains 1.8 for the time being
  5. Leave Create from archetype unchecked
    1. 「Next」
  6. Next screen
    1. Name: mycamelapp
  7. Location: Appropriate new directory
  8. The inside of Artifact Coordinates remains as it is
    1. 「Finish」

Just in case, set up Git and save your work. I decided to use .gitignore because there was a template collection on GitHub.

terminal


cd path/to/app

git init

for kind in Java Maven Global/JetBrains; do
  echo "###--- github/gitignore : ${kind}.gitignore ---###"
  curl https://raw.githubusercontent.com/github/gitignore/master/${kind}.gitignore
  echo
done >> .gitignore

git add .
git commit -m 'Create a Maven project'

pom.xml Add dependencies according to https://camel.apache.org/camel-spring-boot/latest/index.html. It took time without realizing that dependencies had to be written separately inside and outside dependencyManagement.

The whole is as follows.

pom.xml (mycamelapp)


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>org.example</groupId>
	<artifactId>mycamelapp</artifactId>
	<version>1.0-SNAPSHOT</version>

	<!-- https://camel.apache.org/camel-spring-boot/latest/index.html -->
	<dependencyManagement>
		<dependencies>
			<!-- Camel BOM -->
			<dependency>
				<groupId>org.apache.camel.springboot</groupId>
				<artifactId>camel-spring-boot-dependencies</artifactId>
				<version>3.2.0</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
			<!-- ... other BOMs or dependencies ... -->
		</dependencies>
	</dependencyManagement>

	<dependencies>
		<!-- Camel Starter -->
		<dependency>
			<groupId>org.apache.camel.springboot</groupId>
			<artifactId>camel-spring-boot-starter</artifactId>
		</dependency>
		<!-- ... other dependencies ... -->
	</dependencies>
</project>

ActiveMQ is introduced as an example of the component to be added to other dependencies, but I skip it because I do not plan to use it.

route definition

I've seen a lot of examples here with the app under maintenance, so I don't have any doubts personally. https://camel.apache.org/camel-spring-boot/latest/spring-boot.html#SpringBoot-Camel Define a short route at SpringBootStarter.

terminal


cd path/to/app

mkdir -p src/main/java/org/example/mycamelapp/routes
touch    src/main/java/org/example/mycamelapp/routes/SampleTimerRoute.java

src/main/java/org/example/mycamelapp/routes/SampleTimerRoute.java


package org.example.mycamelapp.routes;

import org.apache.camel.builder.RouteBuilder;
import org.springframework.stereotype.Component;

@Component
public class SampleTimerRoute extends RouteBuilder {

	@Override
	public void configure() throws Exception {
		from("timer:foo").to("log:bar");
	}
}

What is a route?

Roughly speaking, ** pipeline **. Imagine Java8's Stream API, but it's flowing one after another. I write in DSL how to process the incoming data.

Spring Boot settings

I couldn't find it in camel's documentation, but it seems that I have to write the starting point of the app. When you write it, the "Run" mark is displayed on the corresponding line in the IDE.

src/main/java/org/example/mycamelapp/MyCamelApplication.java


package org.example.mycamelapp;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MyCamelApplication {

	public static void main(String[] args) {
		SpringApplication.run(MyCamelApplication.class, args);
	}
}

Prevent the app from closing immediately after launching. It seems that you only need to give parameters here, so write it in yaml (may be properties).

src/main/resources/application.yml


# to keep the JVM running
camel:
  springboot:
    main-run-controller: true

Start-up

On the IDE, you can start it immediately by pressing the "Run" button mentioned above.


If you start it with maven command, add the setting to pom.xml.

pom.xml&#x20;(mycamelapp)


...
	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<version>2.2.6.RELEASE</version>
			</plugin>
		</plugins>
	</build>
...

terminal


cd path/to/app

mvn spring-boot:run

reference

Recommended Posts

Steps to create a simple camel app using Apache Camel Spring Boot starters
Create a simple search app with Spring Boot
Create a portfolio app using Java and Spring Boot
Java beginner tried to make a simple web application using Spring Boot
Sample to batch process data on DB with Apache Camel Spring Boot starters
How to create a Spring Boot project in IntelliJ
[Spring Boot] How to create a project (for beginners)
[Introduction to Spring Boot] Submit a form using thymeleaf
Create a simple demo site with Spring Security with Spring Boot 2.1
Hello World (console app) with Apache Camel + Spring Boot 2
I made a simple MVC sample system using Spring Boot
Create an app with Spring Boot 2
Create an app with Spring Boot
Try to create a server-client app
I tried to create a simple map app in Android Studio
How to make a hinadan for a Spring Boot project using SPRING INITIALIZR
Create a Spring Boot web app that uses IBM Cloudant and deploy it to Cloud Foundry
Inexperienced create a weather app using OpenWeatherMap and deploy it to Netlify
Create a Spring Boot app development project with the cURL + tar command
[Rails] How to create a graph using lazy_high_charts
I tried to create a LINE clone app
How to add a classpath in Spring Boot
How to create an Excel form using a template file with Spring MVC
Apply Twitter Bootstrap 4 to Spring Boot 2 using Webjars
Create a web api server with spring boot
Create a Spring Boot development environment with docker
From building an AWS cloud environment to deploying a Spring Boot app (for beginners)
Until you create a Spring Boot project in Intellij and push it to Github
Create a web app that is just right for learning [Spring Boot + Thymeleaf + PostgreSQL]
Create a docker image that runs a simple Java app
How to write a unit test for Spring Boot 2
Hello World (REST API) with Apache Camel + Spring Boot 2
A memorandum of addiction to Spring Boot2 x Doma2
[JUnit 5 compatible] Write a test using JUnit 5 with Spring boot 2.2, 2.3
A memorandum when trying to create a GUI using JavaFX
Implement a simple Rest API with Spring Security with Spring Boot 2.0
Create Restapi with Spring Boot ((1) Until Run of App)
Steps required to issue an asynchronous event for Spring Boot
[Rails] I tried to create a mini app with FullCalendar
Deploy Spring Boot applications to Heroku without using the Heroku CLI
How to deploy a simple Java Servlet app on Heroku
[Java] Deploy the Spring Boot application to Azure App Service
Create a Hello World web app with Spring framework + Jetty
Let's make a simple API with EC2 + RDS + Spring boot ①
What to do if the log using JUL is no longer output to the app log after deploying the Spring Boot app to Tomcat as a war
I tried to get started with Swagger using Spring Boot
8 things to insert into DB using Spring Boot and JPA
Implement a simple Rest API with Spring Security & JWT with Spring Boot 2.0
How to control transactions in Spring Boot without using @Transactional
Try Spring Boot from 0 to 100.
Introduction to Spring Boot ① ~ DI ~
Introduction to Spring Boot ② ~ AOP ~
Create a fortune using Ruby
Introduction to Spring Boot Part 1
Try using Spring Boot Security
How to create a method
Implement a simple Web REST API server with Spring Boot + MySQL
How to create a jar file or war file using the jar command
I want to create a chat screen for the Swift chat app!
Create a memo app with Tomcat + JSP + Servlet + MySQL using Eclipse
I tried to create a Spring MVC development environment on Mac