Camel Knative Source Slack Example

This example demonstrates how to use a Camel based Knative source to receive messages written to a Slack channel.

You can find more information about Apache Camel and Apache Camel K on the official Camel website.

Before you begin

Read the general instructions in the root README.md file for setting up your environment and the Kubernetes cluster before looking at this example.

Make sure you've read the Camel K installation instructions for your specific cluster before starting the example.

You should open this file with Didact if available on your IDE.

Requirements

Validate all Requirements at Once!

Kubectl CLI

The Kubernetes kubectl CLI tool will be used to interact with the Kubernetes cluster.

Check if the Kubectl CLI is installed{.didact}

Status: unknown

Connection to a Kubernetes cluster

You need to connect to a Kubernetes cluster in order to run the example.

Check if you're connected to a Kubernetes cluster{.didact}

Status: unknown

Apache Camel K CLI (“kamel”)

You need the Apache Camel K CLI (“kamel”) in order to access all Camel K features.

Check if the Apache Camel K CLI (“kamel”) is installed{.didact}

Status: unknown

Knative installed on the cluster

The cluster also needs to have Knative installed and working. Refer to the official Knative documentation for information on how to install it in your cluster.

Check if the Knative Serving is installed{.didact}

Status: unknown

Check if the Knative Eventing is installed{.didact}

Status: unknown

Knative Camel Source installed on the cluster

The cluster also needs to have installed the Knative Camel Source from the camel.yaml in the Eventing Sources release page.

Check if the Knative Camel Source is installed{.didact}

Status: unknown

Optional Requirements

The following requirements are optional. They don't prevent the execution of the demo, but may make it easier to follow.

VS Code Extension Pack for Apache Camel

The VS Code Extension Pack for Apache Camel provides a collection of useful tools for Apache Camel K developers, such as code completion and integrated lifecycle management. They are recommended for the tutorial, but they are not required.

You can install it from the VS Code Extensions marketplace.

Check if the VS Code Extension Pack for Apache Camel by Red Hat is installed{.didact}

Status: unknown

1. Creating the Slack App

Slack Apps have access to the full scope of the platform, including sending messages to conversations and receiving event notifications.

  1. Go to the Slack API website and create a new Slack App.
  2. Go to the OAuth & Permissions page and add the channels:history user token scope to your app to grant it permission to view messages in the user’s public channels.
  3. Install the app to your workspace.
  4. Copy the generated token and set it as the value of the slack.token property in slack.properties{.didact}.

2. Preparing the namespace

Let's open a terminal and go to the example directory:

cd 11-knative-source-slack

(^ execute{.didact})

We're going to create a namespace named camel-source for running the example. To create it, execute the following command:

kubectl create namespace camel-source

(^ execute{.didact})

Now we can set the camel-source namespace as default namespace for the following commands:

kubectl config set-context --current --namespace=camel-source

(^ execute{.didact})

You need to install Camel K in the camel-source namespace (or globally in the whole cluster). In many settings (e.g. OpenShift, CRC), it's sufficient to execute the following command to install Camel K:

kamel install

(^ execute{.didact})

NOTE: The kamel install command requires some prerequisites to be successful in some situations, e.g. you need to enable the registry addon on Minikube. Refer to the Camel K install guide for cluster-specific instructions.

To check that Camel K is installed we'll retrieve the IntegrationPlatform object from the namespace:

kubectl get integrationplatform

(^ execute{.didact})

You should find an IntegrationPlatform in status Ready.

You can now proceed to the next section.

3. Preparing the environment

Create a Kubernetes Secret with the slack.properties{.didact} file.

kubectl create secret generic slack --from-file=slack.properties

(^ execute{.didact})

As the example levareges Knative Eventing channels, we need to create the one that the example will use:

kubectl apply -f slack-channel.yaml

(^ execute{.didact})

4. Running a Camel Source

This repository contains a simple Camel Source based on the Slack component that forward messages written to the generic Slack channel to a Knative channel.

Use the following command to deploy the Camel Source:

kubectl apply -f slack-source.yaml

(^ execute{.didact})

5. Running a basic integration to echo messages from Slack in the console

kamel run slack-consumer.groovy --dev

(^ execute{.didact})

If everything is OK, after the build phase finishes, you should see the Camel integration running and printing the messages you write in the generic Slack channel.

6. Uninstall

To cleanup everything, execute the following command:

kubectl delete namespace camel-source

(^ execute{.didact})