Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example for securely connecting to Kafka #20

Merged
merged 4 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 142 additions & 0 deletions jbang/azure-eventhubs-kafka-ibm-mq/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
== Azure Event Hubs Kafka Enabled to IBM MQ

In this sample you'll use the Kafka Source to IBM MQ with Kafka enabled feature

=== Install JBang

First install JBang according to https://www.jbang.dev

When JBang is installed then you should be able to run from a shell:

[source,sh]
----
$ jbang --version
----

This will output the version of JBang.

To run this example you can either install Camel on JBang via:

[source,sh]
----
$ jbang app install camel@apache/camel
----

Which allows to run CamelJBang with `camel` as shown below.

=== Setup the Azure Event hubs with Kafka enabled

Running the terraform configuration provided in terraform folder.

[source,sh]
----
cd terraform/
----

and then run

[source,sh]
----
terraform init
----

At this point you should be to run the configuration

[source,sh]
----
terraform apply
----

Enter yes and wait for the terraform configuration to end.

Once the configuration end you'll need to obtain the connection string for accessing the Azure Event Hubs

[source,sh]
----
az eventhubs eventhub authorization-rule keys list --resource-group example-resources --namespace-name test12345678910 --eventhub-name camel-test --name navi
----

Open the file `azure.properties` and copy the primary connection string in both `camel.kamelet.kafka-sink.password` and `camel.kamelet.kafka-source.password`.

=== Set up IBM MQ

We could do this through running the following docker container:

```bash
docker volume create qm1data
```

and then run

```bash
docker run --env LICENSE=accept --env MQ_QMGR_NAME=QM1 --volume qm1data:/mnt/mqm --publish 1414:1414 --publish 9443:9443 --detach --env MQ_APP_PASSWORD=passw0rd --name QM1 icr.io/ibm-messaging/mq:latest
```

To check everything is fine:

```bash
docker exec -ti QM1 bash
dspmq
```

This should give a RUNNING state.

=== How to run

=== Kafka to MQ

Then you can run this example using:

[source,sh]
----
$ camel run --properties=azure.properties --local-kamelet-dir=<your-local-kamelets-path> kafka-mq.yaml
----

Or run with JBang using the longer command line (without installing camel as app in JBang):

[source,sh]
----
$ jbang camel@apache/camel run --properties=azure.properties --local-kamelet-dir=<your-local-kamelets-path> kafka-mq.yaml
----

=== MQ to log

Then you can run this example using:

[source,sh]
----
$ camel run mq-log.yaml
----

Or run with JBang using the longer command line (without installing camel as app in JBang):

[source,sh]
----
$ jbang camel@apache/camel run mq-log.yaml
----

=== Send data to Kafka on Eventhubs

You can run the timer to kafka route.

[source,sh]
----
$ camel run --properties=azure.properties --local-kamelet-dir=<your-local-kamelets-path> timer-kafka.yaml
----

Or run with JBang using the longer command line (without installing camel as app in JBang):

[source,sh]
----
$ jbang camel@apache/camel run --properties=azure.properties --local-kamelet-dir=<your-local-kamelets-path> timer-kafka.yaml
----

=== 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!
4 changes: 4 additions & 0 deletions jbang/azure-eventhubs-kafka-ibm-mq/azure.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
camel.kamelet.kafka-source.user=$ConnectionString
camel.kamelet.kafka-source.password=<password>
camel.kamelet.kafka-sink.user=$ConnectionString
camel.kamelet.kafka-sink.password=<password>
39 changes: 39 additions & 0 deletions jbang/azure-eventhubs-kafka-ibm-mq/kafka-mq.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## ---------------------------------------------------------------------------
## 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=mvn:com.ibm.mq:com.ibm.mq.allclient:9.2.5.0

- route:
from:
uri: "kamelet:kafka-source"
parameters:
bootstrapServers: "test12345678910.servicebus.windows.net:9093"
topic: camel-test
consumerGroup: "$Default"
deserializeHeaders: true
steps:
- to:
uri: "kamelet:jms-ibm-mq-sink"
parameters:
channel: DEV.APP.SVRCONN
destinationName: DEV.QUEUE.1
password: "passw0rd"
queueManager: QM1
serverName: 172.17.0.2
serverPort: 1414
username: app

37 changes: 37 additions & 0 deletions jbang/azure-eventhubs-kafka-ibm-mq/mq-log.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
## ---------------------------------------------------------------------------
## 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=mvn:com.ibm.mq:com.ibm.mq.allclient:9.2.5.0

- route:
from:
uri: "kamelet:jms-ibm-mq-source"
parameters:
channel: DEV.APP.SVRCONN
destinationName: DEV.QUEUE.1
password: "passw0rd"
queueManager: QM1
serverName: 172.17.0.2
serverPort: 1414
username: app
steps:
- to:
uri: "kamelet:log-sink"
parameters:
showStreams: true
showHeaders: true
multiline: true
67 changes: 67 additions & 0 deletions jbang/azure-eventhubs-kafka-ibm-mq/terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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.
*/

# We strongly recommend using the required_providers block to set the
# Azure Provider source and version being used
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "=3.0.0"
}
}
}

# Configure the Microsoft Azure Provider
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "West Europe"
}

resource "azurerm_eventhub_namespace" "example" {
name = "test12345678910"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
sku = "Standard"
capacity = 1

tags = {
environment = "Development"
}
}

resource "azurerm_eventhub" "example" {
name = "camel-test"
namespace_name = azurerm_eventhub_namespace.example.name
resource_group_name = azurerm_resource_group.example.name
partition_count = 2
message_retention = 1
}

resource "azurerm_eventhub_authorization_rule" "example" {
name = "navi"
namespace_name = azurerm_eventhub_namespace.example.name
eventhub_name = azurerm_eventhub.example.name
resource_group_name = azurerm_resource_group.example.name
listen = true
send = true
manage = true
}
33 changes: 33 additions & 0 deletions jbang/azure-eventhubs-kafka-ibm-mq/timer-kafka.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## ---------------------------------------------------------------------------
## 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.
## ---------------------------------------------------------------------------

- route:
from:
uri: "kamelet:timer-source"
parameters:
message: "test"
period: "10000"
repeatCount: 5
steps:
- set-header:
name: JMSCorrelationID
simple: test
- to:
uri: "kamelet:kafka-sink"
parameters:
bootstrapServers: "test12345678910.servicebus.windows.net:9093"
topic: camel-test
1 change: 0 additions & 1 deletion jbang/kafka-mq/kafka-mq.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,3 @@
serverName: 172.17.0.2
serverPort: 1414
username: app