This example shows how to query a Postgresql database, using the camel sql
component, and logs the messages to the console.
-
A running Postgresql database
-
The Postgresql driver dependency available in the classpath, in this example, it's added to the
application.properties
file -
A database named
transactions
-
A table named
transactions
with the following structureColumn name Data type id serial timestamp timestamp accountnumber varchar amount float8 -
Some records in the
transactions
table
As an example, here's a SQL script to create the database and table, and insert some records:
CREATE DATABASE transactions;
USE transactions;
CREATE TABLE transactions.public.transactions (
id serial NOT NULL,
"timestamp" timestamp NULL,
accountnumber varchar NULL,
amount float8 NULL,
CONSTRAINT transactions_pk PRIMARY KEY (id)
);
INSERT INTO public.transactions ("timestamp", accountnumber, amount) VALUES ('2021-01-01T00:00:00', '92842238', 100.0);
INSERT INTO public.transactions ("timestamp", accountnumber, amount) VALUES ('2021-01-02T00:00:00', '2873628736', 120.0);
INSERT INTO public.transactions ("timestamp", accountnumber, amount) VALUES ('2021-01-03T00:00:00', '12922878', 320.0);
- Open the
postgresql-to-log.camel.yaml
file and set thePostgresqlDataSource
bean properties to match your Postgresql database, such asdatabaseName
,user
,password
,serverName
, andportNumber
1.1. This example expects to have a secret namedpostgres
with the following keys: *database-name
containing the database name *database-user
containing the user name *database-password
containing the password - Since this example requires the Postgresql dependency, change to the
postgresql-to-log
folder
cd postgresql-to-log
- Run the integration using the Camel CLI extension, or by executing the following command:
jbang '-Dcamel.jbang.version=4.5.0' camel@apache/camel run * --dev --logging-level=info