You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2021/07/29 14:49:25 UTC

[camel-k-examples] branch example-postgresql updated (442083c -> 47d9cef)

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a change to branch example-postgresql
in repository https://gitbox.apache.org/repos/asf/camel-k-examples.git.


 discard 442083c  Added a new example to list
 discard 7f32461  Added PostgreSQL to Log example
    omit 730d776  Added Kafka to Log with value to key Action to the example list
    omit 6614c43  Added Kafka to Log with value to key sample
     add b503f88  Added Kafka to Log with value to key sample
     add 6d07ec1  Added Kafka to Log with value to key Action to the example list
     new 7d63af7  Added PostgreSQL to Log example
     new 47d9cef  Added a new example to list

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (442083c)
            \
             N -- N -- N   refs/heads/example-postgresql (47d9cef)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:

[camel-k-examples] 02/02: Added a new example to list

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch example-postgresql
in repository https://gitbox.apache.org/repos/asf/camel-k-examples.git

commit 47d9cef7117fcb5a7a5b73658f834fd7d60a508d
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Jul 29 16:45:40 2021 +0200

    Added a new example to list
---
 kamelets/README.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/kamelets/README.md b/kamelets/README.md
index f79c2f0..d0b7179 100644
--- a/kamelets/README.md
+++ b/kamelets/README.md
@@ -18,3 +18,4 @@ All the Kamelet examples in this folder have been tested on Camel-K 1.5.0.
 - [Kafka to Kafka with Manual commit](./kafka-to-kafka-with-manual-commit): Create a Kamelet binding between a Kafka Source Kamelet and a Kafka Sink Kamelet, with the usage of the Manual Commit Action.
 - [Kafka to Kafka with Timestamp router](./kafka-to-kafka-with-timestamp-router): Create a Kamelet binding between a Kafka Source Kamelet and a Kafka Sink Kamelet, with the usage of the Timestamp Router Action.
 - [Kafka to Log with Value to Key](./kafka-to-log-with-value-to-key): Create a Kamelet binding between a Kafka Source Kamelet and a Log Sink Kamelet, with the usage of the Value to Key Action.
+- [PostgreSQL to Log](./postgresql-to-log): Create a Kamelet binding between a PostgreSQL Source Kamelet and a Log Sink Kamelet.

[camel-k-examples] 01/02: Added PostgreSQL to Log example

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch example-postgresql
in repository https://gitbox.apache.org/repos/asf/camel-k-examples.git

commit 7d63af7b3af4f575194608307834948223497277
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Jul 29 16:44:40 2021 +0200

    Added PostgreSQL to Log example
---
 kamelets/postgresql-to-log/README.md             | 100 +++++++++++++++++++++++
 kamelets/postgresql-to-log/flow-binding.yaml     |  23 ++++++
 kamelets/postgresql-to-log/log-sink.kamelet.yaml |  22 +++++
 3 files changed, 145 insertions(+)

diff --git a/kamelets/postgresql-to-log/README.md b/kamelets/postgresql-to-log/README.md
new file mode 100644
index 0000000..153f043
--- /dev/null
+++ b/kamelets/postgresql-to-log/README.md
@@ -0,0 +1,100 @@
+# PostgreSQL to Log example
+
+- Ensure you have helm installed so you could use it on Minikube
+
+- Run the following command
+
+    > helm install my-release bitnami/postgresql
+    NAME: my-release
+    LAST DEPLOYED: Thu Jul 29 11:05:23 2021
+    NAMESPACE: default
+    STATUS: deployed
+    REVISION: 1
+    TEST SUITE: None
+    NOTES:
+    ** Please be patient while the chart is being deployed **
+    
+    PostgreSQL can be accessed via port 5432 on the following DNS name from within your cluster:
+    
+        my-release-postgresql.default.svc.cluster.local - Read/Write connection
+    
+    To get the password for "postgres" run:
+    
+        export POSTGRES_PASSWORD=$(kubectl get secret --namespace default my-release-postgresql -o jsonpath="{.data.postgresql-password}" | base64 --decode)
+    
+    To connect to your database run the following command:
+    
+        kubectl run my-release-postgresql-client --rm --tty -i --restart='Never' --namespace default --image docker.io/bitnami/postgresql:11.12.0-debian-10-r38 --env="PGPASSWORD=$POSTGRES_PASSWORD" --command -- psql --host my-release-postgresql -U postgres -d postgres -p 5432
+    
+    
+    
+    To connect to your database from outside the cluster execute the following commands:
+    
+        kubectl port-forward --namespace default svc/my-release-postgresql 5432:5432 &
+        PGPASSWORD="$POSTGRES_PASSWORD" psql --host 127.0.0.1 -U postgres -d postgres -p 5432
+
+- Now it's time to create the database and populate it
+
+    > kubectl run my-release-postgresql-client --rm --tty -i --restart='Never' --namespace default --image docker.io/bitnami/postgresql:11.12.0-debian-10-r38 --env="PGPASSWORD=$POSTGRES_PASSWORD" --command -- psql --host my-release-postgresql -U postgres -d postgres -p 5432
+    If you don't see a command prompt, try pressing enter.
+    
+    postgres=# CREATE TABLE accounts (
+    postgres(# user_id serial PRIMARY KEY,
+    postgres(# username VARCHAR ( 50 ) UNIQUE NOT NULL,
+    postgres(# city VARCHAR ( 50 ) NOT NULL
+    postgres(# );
+    CREATE TABLE
+    postgres=# INSERT into accounts (username,city) VALUES ('andrea', 'Roma');
+    INSERT 0 1
+    postgres=# INSERT into accounts (username,city) VALUES ('John', 'New York');
+    INSERT 0 1
+    postgres=# select * from accounts;
+     user_id | username |   city
+    ---------+----------+----------
+           1 | andrea   | Roma
+           2 | John     | New York
+    (2 rows)
+
+- So we now have two rows to consume.
+
+- Add the correct credentials and address in the flow-binding yaml for the PostgreSQL database.
+
+- Run the following commands
+
+    kubectl apply -f log-sink.kamelet.yaml
+    kubectl apply -f flow-binding.yaml
+
+- Check logs
+
+    kamel logs sql-to-log
+
+You should see the following output
+
+    [1] 2021-07-29 09:55:55,058 INFO  [org.apa.cam.k.Runtime] (main) Apache Camel K Runtime 1.8.0
+    [1] 2021-07-29 09:55:55,135 INFO  [org.apa.cam.qua.cor.CamelBootstrapRecorder] (main) Bootstrap runtime: org.apache.camel.quarkus.main.CamelMainRuntime
+    [1] 2021-07-29 09:55:55,550 INFO  [org.apa.cam.k.lis.SourcesConfigurer] (main) Loading routes from: SourceDefinition{name='camel-k-embedded-flow', language='yaml', type='source', location='file:/etc/camel/sources/camel-k-embedded-flow.yaml', }
+    [1] 2021-07-29 09:55:55,902 INFO  [org.apa.cam.k.lis.SourcesConfigurer] (main) Loading routes from: SourceDefinition{name='log-sink', language='yaml', type='source', location='file:/etc/camel/sources/log-sink.yaml', }
+    [1] 2021-07-29 09:55:55,906 INFO  [org.apa.cam.k.lis.SourcesConfigurer] (main) Loading routes from: SourceDefinition{name='postgresql-source', language='yaml', type='source', location='file:/etc/camel/sources/postgresql-source.yaml', }
+    [1] 2021-07-29 09:55:56,079 INFO  [org.apa.cam.imp.eng.AutowiredLifecycleStrategy] (main) Autowired property: dataSource on component: sql as exactly one instance of type: javax.sql.DataSource (org.apache.commons.dbcp2.BasicDataSource) found in the registry
+    [1] 2021-07-29 09:55:56,174 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (main) Routes startup summary (total:3 started:3)
+    [1] 2021-07-29 09:55:56,174 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (main)     Started route1 (kamelet://postgresql-source/source)
+    [1] 2021-07-29 09:55:56,174 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (main)     Started source (sql://SELECT%20*%20FROM%20accounts)
+    [1] 2021-07-29 09:55:56,174 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (main)     Started sink (kamelet://source)
+    [1] 2021-07-29 09:55:56,174 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (main) Apache Camel 3.11.0 (camel-1) started in 180ms (build:0ms init:108ms start:72ms)
+    [1] 2021-07-29 09:55:56,177 INFO  [io.quarkus] (main) camel-k-integration 1.5.0 on JVM (powered by Quarkus 2.0.0.Final) started in 2.272s. 
+    [1] 2021-07-29 09:55:56,177 INFO  [io.quarkus] (main) Profile prod activated. 
+    [1] 2021-07-29 09:55:56,178 INFO  [io.quarkus] (main) Installed features: [agroal, camel-bean, camel-core, camel-jackson, camel-k-core, camel-k-runtime, camel-kamelet, camel-log, camel-sql, camel-support-common, camel-support-commons-logging, camel-support-spring, camel-yaml-dsl, cdi, narayana-jta, smallrye-context-propagation]
+    [1] 2021-07-29 09:55:57,383 INFO  [info] (Camel (camel-1) thread #0 - sql://SELECT%20*%20FROM%20accounts) Exchange[Id: 86D986CD24E5F68-0000000000000000, ExchangePattern: InOnly, Properties: {}, Headers: {Content-Type=application/json}, BodyType: byte[], Body: {"user_id":1,"username":"andrea","city":"Roma"}]
+    [1] 2021-07-29 09:55:57,398 INFO  [info] (Camel (camel-1) thread #0 - sql://SELECT%20*%20FROM%20accounts) Exchange[Id: 86D986CD24E5F68-0000000000000001, ExchangePattern: InOnly, Properties: {}, Headers: {Content-Type=application/json}, BodyType: byte[], Body: {"user_id":2,"username":"John","city":"New York"}]
+
+If you go back to the postgresql console you won't have any row on the database, because of the consumedQuery parameter
+
+- Now it's time to check the database
+
+    > kubectl run my-release-postgresql-client --rm --tty -i --restart='Never' --namespace default --image docker.io/bitnami/postgresql:11.12.0-debian-10-r38 --env="PGPASSWORD=$POSTGRES_PASSWORD" --command -- psql --host my-release-postgresql -U postgres -d postgres -p 5432
+    If you don't see a command prompt, try pressing enter.
+    
+    postgres=# select * from Accounts;
+     user_id | username | city 
+    ---------+----------+------
+    (0 rows)
diff --git a/kamelets/postgresql-to-log/flow-binding.yaml b/kamelets/postgresql-to-log/flow-binding.yaml
new file mode 100644
index 0000000..bd71869
--- /dev/null
+++ b/kamelets/postgresql-to-log/flow-binding.yaml
@@ -0,0 +1,23 @@
+apiVersion: camel.apache.org/v1alpha1
+kind: KameletBinding
+metadata:
+  name: sql-to-log
+spec:
+  source:
+    ref:
+      kind: Kamelet
+      apiVersion: camel.apache.org/v1alpha1
+      name: postgresql-source
+    properties:
+      serverName: my-release-postgresql.default.svc.cluster.local
+      username: postgres
+      password: 9f1IenvnEn
+      query: 'SELECT * FROM accounts'
+      port: 5432
+      databaseName: postgres
+      consumedQuery: 'delete from accounts where user_id = :#user_id'
+  sink:
+    ref:
+      kind: Kamelet
+      apiVersion: camel.apache.org/v1alpha1
+      name: log-sink
diff --git a/kamelets/postgresql-to-log/log-sink.kamelet.yaml b/kamelets/postgresql-to-log/log-sink.kamelet.yaml
new file mode 100755
index 0000000..a48fb41
--- /dev/null
+++ b/kamelets/postgresql-to-log/log-sink.kamelet.yaml
@@ -0,0 +1,22 @@
+apiVersion: camel.apache.org/v1alpha1
+kind: Kamelet
+metadata:
+  name: log-sink
+  annotations:
+    camel.apache.org/kamelet.icon: "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNDAgMjQwIj48ZGVmcz48bGluZWFyR3JhZGllbnQgaWQ9ImEiIHgxPSIuNjY3IiB4Mj0iLjQxNyIgeTE9Ii4xNjciIHkyPSIuNzUiPjxzdG9wIG9mZnNldD0iMCIgc3RvcC1jb2xvcj0iIzM3YWVlMiIvPjxzdG9wIG9mZnNldD0iMSIgc3RvcC1jb2xvcj0iIzFlOTZjOCIvPjwvbGluZWFyR3JhZGllbnQ+PGxpbmVhckdyYWRpZW50IGlkPSJiIiB4MT0iLjY2IiB4Mj0iLjg1MSIgeTE9Ii40MzciIHkyPSIuODAyIj48c3RvcCBvZmZzZXQ9IjAiIHN0b3AtY29sb3I9IiNlZmY3Zm [...]
+    camel.apache.org/provider: "Apache Software Foundation"
+  labels:
+    camel.apache.org/kamelet.type: "sink"
+    camel.apache.org/kamelet.group: "Log"
+spec:
+  definition:
+    title: "Log Sink"
+    description: |-
+      Log something
+    type: object
+  flow:
+    from:
+      uri: "kamelet:source"
+      steps:
+      - to:
+          uri: "log:info?showAll=true"