blob: 11bde81e7a8d8193cda2f4aa9cadbc5b648af3f3 [file] [log] [blame]
== Camel Example Kamelet SQL and AWS Secrets Manager Properties Function
=== Introduction
This example shows how to use ready to use Kamelets that you can find at the
https://camel.apache.org/camel-kamelets/next/[Camel Kamelet Catalog].
The application is run with `KameletMain` class from camel-kamalet-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.
=== Setting up your container
First of all run the command to start PostgreSQL
```shell script
docker run --name psql -e POSTGRES_PASSWORD=secret -d postgres
```
Now you need to setup Database and populate it:
And run the following scripts
```shell script
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
```shell script
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' psql
172.17.0.2
```
Take note of the container IP.
=== Save the secret on AWS Secrets Manager
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.
```shell script
{
"username": "postgres",
"password": "secret",
"engine": "postgres",
"host": "172.17.0.2",
"port": "5432",
"dbname": "postgres"
}
```
Save the secret by naming it postgresql.
=== Set up credentials for AWS Secrets Manager
In src/main/resources/application.properties, populate the camel.vault.aws.* properties correctly.
Now you are ready to run this example.
=== Build
You will need to compile this example first:
[source,sh]
----
$ mvn compile
----
=== Run
You can run this example using
[source,sh]
----
$ mvn camel:run
----
The application is also built as a _fat jar_ (see `pom.xml`), which you can run with
[source,sh]
----
$ mvn package -DskipTests
$ java -jar target/camel-example-kamelet-sql-jar-with-dependencies.jar
----
=== Output
You should see multiple lines coming from the Database at the first run
[source,sh]
----
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"}]
----
=== Help and contributions
If you hit any problem using Camel or have some feedback, then please
https://camel.apache.org/community/support/[let us know].
We also love contributors, so
https://camel.apache.org/community/contributing/[get involved] :-)
The Camel riders!