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.propertiesfile -
A database named
transactions -
A table named
transactionswith the following structureColumn name Data type id serial timestamp timestamp accountnumber varchar amount float8 -
Some records in the
transactionstable
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.yamlfile and set thePostgresqlDataSourcebean properties to match your Postgresql database, such asdatabaseName,user,password,serverName, andportNumber1.1. This example expects to have a secret namedpostgreswith the following keys: *database-namecontaining the database name *database-usercontaining the user name *database-passwordcontaining the password - Since this example requires the Postgresql dependency, change to the
postgresql-to-logfolder
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