Skip to content

Commit

Permalink
(apache#56) Update generic - component usage examples - amqp, caffein…
Browse files Browse the repository at this point in the history
…e, database, dns, http
  • Loading branch information
tdiesler committed May 23, 2024
1 parent 338429d commit 0797685
Show file tree
Hide file tree
Showing 27 changed files with 296 additions and 261 deletions.
6 changes: 0 additions & 6 deletions generic-examples/amqp/AmqpConnectionBeanConsumer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
* limitations under the License.
*/

// You can bundle your credentials as a secret properties file:
//
// kubectl create secret generic my-amqp --from-file=amqp.properties
//
// kamel run AmqpConnectionBeanConsumer.java --dev --config secret:my-amqp

public class AmqpConnectionBeanConsumer extends org.apache.camel.builder.RouteBuilder {
@Override
public void configure() throws Exception {
Expand Down
6 changes: 0 additions & 6 deletions generic-examples/amqp/AmqpConnectionBeanProducer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
* limitations under the License.
*/

// You can bundle your credentials as a secret properties file:
//
// kubectl create secret generic my-amqp --from-file=amqp.properties
//
// kamel run AmqpConnectionBeanProducer.java --dev --config secret:my-amqp

public class AmqpConnectionBeanProducer extends org.apache.camel.builder.RouteBuilder {
@Override
public void configure() throws Exception {
Expand Down
20 changes: 7 additions & 13 deletions generic-examples/amqp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,19 @@ cluster before starting the example.
- [`amqp.properties`](./amqp.properties) holds required credentials to connect to broker.

## Running the Example

You should have an amqp broker running in a namespace, if not, see [how to install a JMS/AMQP Broker on Kubernetes](./artemis/)

To create a secret for your credentials, run:
To run an integration that sends/consumes message to amqp queue, run:
```
kubectl create secret generic my-amqp --from-file=amqp.properties
kamel run --dev --config secret:my-amqp amqp.yaml
```

To run an integration that sends message to amqp queue, run:
```
kamel run AmqpConnectionBeanProducer.java --config secret:my-amqp
```

To consume messages from the amqp queue, run:
```
kamel run AmqpConnectionBeanConsumer.java --dev --config secret:my-amqp
```
The terminal should show the logged messages:
```console
[1] 2022-06-21 15:44:46,513 INFO [info] (Camel (camel-1) thread #1 - JmsConsumer[example]) Exchange[ExchangePattern: InOnly, BodyType: String, Body: Hello Camel K]
[1] 2022-06-21 15:44:47,513 INFO [info] (Camel (camel-1) thread #1 - JmsConsumer[example]) Exchange[ExchangePattern: InOnly, BodyType: String, Body: Hello Camel K]
[1] 2022-06-21 15:44:48,517 INFO [info] (Camel (camel-1) thread #1 - JmsConsumer[example]) Exchange[ExchangePattern: InOnly, BodyType: String, Body: Hello Camel K]
[1] 2024-05-23 07:12:27,778 INFO [org.apa.qpi.jms.JmsConnection] (AmqpProvider :(8):[amqp://my-amqp-service:5672]) Connection ID:e04a1ef1-d167-4aed-b525-6959666be4a8:8 connected to server: amqp://my-amqp-service:5672
[1] 2024-05-23 07:12:27,788 INFO [info] (Camel (camel-1) thread #1 - JmsConsumer[example]) Exchange[ExchangePattern: InOnly, BodyType: String, Body: Hello Camel K]
[1] 2024-05-23 07:12:28,772 INFO [org.apa.qpi.jms.JmsConnection] (AmqpProvider :(9):[amqp://my-amqp-service:5672]) Connection ID:34387545-ef55-429a-976f-a28cd2d5e038:9 connected to server: amqp://my-amqp-service:5672
[1] 2024-05-23 07:12:28,783 INFO [info] (Camel (camel-1) thread #1 - JmsConsumer[example]) Exchange[ExchangePattern: InOnly, BodyType: String, Body: Hello Camel K]
```
39 changes: 0 additions & 39 deletions generic-examples/amqp/amqp.groovy

This file was deleted.

31 changes: 0 additions & 31 deletions generic-examples/amqp/amqp.js

This file was deleted.

32 changes: 32 additions & 0 deletions generic-examples/amqp/amqp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# camel-k: language=yaml

# ---------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ---------------------------------------------------------------------------

# camel-k: dependency=camel-amqp

- from:
uri: "timer:foo"
steps:
- setBody:
simple: "Hello Camel K"
- to: "amqp:queue:example?exchangePattern=InOnly"

- from:
uri: "amqp:queue:example?exchangePattern=InOnly"
steps:
- to: "log:info"
19 changes: 15 additions & 4 deletions generic-examples/amqp/artemis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,35 @@ This is a very simple example to show how to create a JMS/AMQP broker. **Note**,

## Create a Kubernetes Deployment

You can [install ActiveMQ Artemis Operator on Kubernetes](https://artemiscloud.io/docs/tutorials/using_operator/) thanks to ArtemisCloud.io. It would be enough to execute steps 1 and 2 of the linked tutorial post. \
You can [install ActiveMQ Artemis Operator on Kubernetes](https://artemiscloud.io/docs/tutorials/using_operator/) thanks to ArtemisCloud.io.
It would be enough to execute steps 1 and 2 of the linked tutorial post.

**Note:** Openshift environments may require some adjustments, see [Installing the AMQ Broker Operator](https://access.redhat.com/documentation/en-us/red_hat_amq/7.4/html/deploying_amq_broker_on_openshift_container_platform/broker-operator-broker-ocp#install-broker-operator-broker-ocp)

## Verify that the Artemis Operator is running

```
$ kubectl get pod -l name=activemq-artemis-operator -w
NAME READY STATUS RESTARTS AGE
activemq-artemis-controller-manager-55645cc79f-q2qbj 0/1 ContainerCreating 0 48s
activemq-artemis-controller-manager-55645cc79f-q2qbj 0/1 Running 0 56s
activemq-artemis-controller-manager-55645cc79f-q2qbj 1/1 Running 0 61s
```

## Create an AMQP broker instance

Once the operator is up and running, you can proceed by creating a basic install of a broker accepting `amqp` protocol:

```
kubectl apply -f artemis-amqp.yaml
kubectl apply -f ./artemis/artemis-amqp.yaml
```

## Expose the Broker via service

We need to make the broker accessible from the `Integration`. Let's do that via a `Service`:

```
kubectl apply -f artemis-service.yaml
kubectl apply -f ./artemis/artemis-service.yaml
```

We're now ready to use the `Broker`.
6 changes: 3 additions & 3 deletions generic-examples/caffeine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ cluster before starting the example.

## Understanding the Example

- [`CaffeineCacheSample.java`](./CaffeineCacheSample.java) defines a route that every second:
- [`camel-caffeine.yaml`](./CaffeineCacheSample.java) defines a route that every second:
- uses message headers to PUT a key-value pair in the cache and log the result
- uses message headers to GET the cached value for the key and log the result
- uses message headers to INVALIDATE the cached value for the key, logs about invalidating the data
- uses message headers to GET the now discarded cached value for the key and log the result
- [`camel-caffeine.groovy`](./camel-caffeine.groovy) does the same thing as `CaffeineCacheSample.java` except that a bean is defined and accumulation of cache statistics is enabled.

## Running the Example

To see the logs in the terminal, run the integration in dev mode:
```
kamel run --dev CaffeineCacheSample.java
kamel run --dev camel-caffeine.yaml
```

The following should be logged continuously to the terminal:
Expand Down
59 changes: 0 additions & 59 deletions generic-examples/caffeine/camel-caffeine.groovy

This file was deleted.

55 changes: 55 additions & 0 deletions generic-examples/caffeine/camel-caffeine.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# camel-k: language=yaml

# ---------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ---------------------------------------------------------------------------

- from:
uri: "timer:tick"
steps:
- setBody:
constant: "Hello"
- setHeader:
name: "CamelCaffeineAction"
constant: "PUT"
- setHeader:
name: "CamelCaffeineKey"
constant: "1"
- to: "caffeine-cache://test"
- setBody:
simple: "Result of Action ${header.CamelCaffeineAction} with key ${header.CamelCaffeineKey} is: ${body}"
- to: "log:info"

- setBody:
constant: null
- setHeader:
name: "CamelCaffeineAction"
constant: "GET"
- to: "caffeine-cache://test"
- setBody:
simple: "Result of Action ${header.CamelCaffeineAction} with key ${header.CamelCaffeineKey} is: ${body}"
- to: "log:info"

- setBody:
constant: null
- setHeader:
name: "CamelCaffeineAction"
constant: "INVALIDATE"
- log: "Invalidating entry with key ${header.CamelCaffeineKey}"
- to: "caffeine-cache://test"
- setBody:
simple: "The Action ${header.CamelCaffeineAction} with key ${header.CamelCaffeineKey} has result? ${header.CamelCaffeineActionHasResult}"
- to: "log:info"
17 changes: 2 additions & 15 deletions generic-examples/databases/PostgresDBAutoDatasource.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,8 @@
* limitations under the License.
*/

// kamel run PostgresDBAutoDatasource.java --dev
// --build-property quarkus.datasource.camel.db-kind=postgresql
// -p quarkus.datasource.camel.jdbc.url=jdbc:postgresql://postgres:5432/test
// -p quarkus.datasource.camel.username=postgresadmin
// -p quarkus.datasource.camel.password=admin123
// -d mvn:io.quarkus:quarkus-jdbc-postgresql:2.10.0.Final
//
// Alternatively, you can bundle your credentials as a secret properties file:
//
// kubectl create secret generic my-datasource --from-file=datasource.properties
//
// kamel run PostgresDBAutoDatasource.java --dev
// --build-property quarkus.datasource.camel.db-kind=postgresql
// --config secret:my-datasource
// -d mvn:io.quarkus:quarkus-jdbc-postgresql:2.10.0.Final
// camel-k: build-property=quarkus.datasource.camel.db-kind=postgresql
// camel-k: dependency=mvn:io.quarkus:quarkus-jdbc-postgresql:2.10.0.Final

import org.apache.camel.builder.RouteBuilder;

Expand Down
Loading

0 comments on commit 0797685

Please sign in to comment.