This example shows how to use ready to use Kamelets that you can find at the Camel Kamelet Catalog.
The application is run with KameletMain
class from camel-kamelet-main JAR.
This makes it easy to run Camel standalone with Kamelet that can be automatically
downloaded from GitHub, and to use YAML DSL for creating Camel routes that use the Kamelets.
The example has no Java code at all.
A Camel routes is coded in the my-route.yaml
file using the YAML DSL that uses the Kamelet,
and log the result from the Kamelet to the console.
First of all run the command to start PostgreSQL
docker run --name psql -e POSTGRES_PASSWORD=secret -d postgres
Now you need to setup Database and populate it:
And run the following scripts
docker exec -i psql psql -U postgres < script/table.sql
docker exec -i psql psql -U postgres < script/populate.sql
Now the database has been populated
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' psql
172.17.0.2
Take note of the container IP.
Login into your AWS account console.
Jump to AWS Secrets Manager.
Create a new secret for a different database and select Postgresql.
Now you can create a secret, by populating the form, or by providing a json in plain text in the text field.
{
"username": "postgres",
"password": "secret",
"engine": "postgres",
"host": "172.17.0.2",
"port": "5432",
"dbname": "postgres"
}
Save the secret by naming it postgresql.
In src/main/resources/application.properties, populate the camel.vault.aws.* properties correctly.
Now you are ready to run this example.
You can run this example using
$ mvn camel:run
The application is also built as a fat jar (see pom.xml
), which you can run with
$ mvn package -DskipTests
$ java -jar target/camel-example-kamelet-sql-jar-with-dependencies.jar
You should see multiple lines coming from the Database at the first run
18:27:31.439 [Camel (postgresql-source-kamelet) thread #1 - sql://SELECT%20*%20FROM%20accounts] INFO info - Exchange[ExchangePattern: InOnly, BodyType: byte[], Body: {"user_id":29996,"username":"John","city":"New York"}]
18:27:31.440 [Camel (postgresql-source-kamelet) thread #1 - sql://SELECT%20*%20FROM%20accounts] INFO info - Exchange[ExchangePattern: InOnly, BodyType: byte[], Body: {"user_id":29997,"username":"John","city":"New York"}]
18:27:31.441 [Camel (postgresql-source-kamelet) thread #1 - sql://SELECT%20*%20FROM%20accounts] INFO info - Exchange[ExchangePattern: InOnly, BodyType: byte[], Body: {"user_id":29998,"username":"John","city":"New York"}]
18:27:31.442 [Camel (postgresql-source-kamelet) thread #1 - sql://SELECT%20*%20FROM%20accounts] INFO info - Exchange[ExchangePattern: InOnly, BodyType: byte[], Body: {"user_id":29999,"username":"John","city":"New York"}]
18:27:31.443 [Camel (postgresql-source-kamelet) thread #1 - sql://SELECT%20*%20FROM%20accounts] INFO info - Exchange[ExchangePattern: InOnly, BodyType: byte[], Body: {"user_id":30000,"username":"John","city":"New York"}]
If you hit any problem using Camel or have some feedback, then please let us know.
We also love contributors, so get involved :-)
The Camel riders!