Configure message brokers

Akka Serverless integrates with Google Cloud Pub/Sub and Confluent Cloud to integrate with other services and to allow asynchronous messaging within Akka Serverless services.

Confluent Cloud

Take the following steps to configure access to your Confluent Cloud Kafka broker for your Akka Serverless project:app-name:

  1. Open Confluent Cloud.

  2. Go to your cluster. Create a new cluster if you don’t have one already.

  3. Go to data integration, clients. Create a new client with the New client button.

  4. Choose Java or Scala. Create a key with the Create Kafka cluster API key button. Copy the configuration shown in the user interface into a file, and save it to <kafka-broker-config-file>.

  5. Use akkasls to configure the broker for your project:

$ akkasls projects set broker --broker-service kafka --broker-config-file <kafka-broker-config-file>

Create a topic

To create a topic, you can either use the Confluent Cloud user interface, or the Confluent Cloud CLI.

Browser
  1. Open Confluent Cloud.

  2. Go to your cluster

  3. Go to the Topics page

  4. Use the Add Topic button

  5. Fill in the topic name, select the number of partitions, and use the Create with defaults button

You can now use the topic to connect with Akka Serverless.

Confluent Cloud CLI
ccloud kafka topic create TOPIC_ID

You can now use the topic to connect with Akka Serverless.

Use a Kafka broker locally

The docker-compose example file below shows how to set the akkaserverless.proxy.eventing.support to kafka. A volume is mounted to the current directory ., which is expected to contain a kafka.properties file. The BROKER_CONFIG_FILE environment variable points to the kafka.properties file in the mounted volume 'conf', which ensures that the service can connect to Kafka.

version: "3"
services:
  akka-serverless-proxy:
    image: gcr.io/akkaserverless-public/akkaserverless-proxy:{akkaserverless-proxy-version}
    command: -Dconfig.resource=dev-mode.conf -Dakkaserverless.proxy.eventing.support=kafka
    ports:
      - "9000:9000"
    extra_hosts:
      - "host.docker.internal:host-gateway"
    environment:
      USER_FUNCTION_HOST: ${USER_FUNCTION_HOST:-host.docker.internal}
      USER_FUNCTION_PORT: ${USER_FUNCTION_PORT:-8080}
      BROKER_CONFIG_FILE: /conf/kafka.properties
    volumes:
      - .:/conf

Google Cloud Pub/Sub

To configure access to your Google Cloud Pub/Sub broker for your Akka Serverless project, you need to create a Google service account with access to your Google Cloud Pub/Sub broker and provide it to Akka Serverless.

Details on doing this can be found in the Google documentation. We provide simplified steps below.

The service account should allow for the roles/pubsub.publisher and roles/pubsub.subscriber roles.

Setting up the service account

To set up a service account and generate the key, follow these steps:

  1. Navigate to https://console.cloud.google.com/new tab.

  2. From the blue bar, click the dropdown menu next to Google Cloud Platform.

  3. Click New Project to create a project and save the <gcp-project-id>, which you will need later.

  4. Enter the following gcloud command to set up the gcloud environment:

    gcloud auth login
    gcloud projects list
    gcloud config set project <gcp-project-id>
  5. Enter the following command to create the service account. The example uses the name akka-serverless-broker, but you can use any name.

    gcloud iam service-accounts create akka-serverless-broker
  6. Enter the following commands to grant the GCP Pub/Sub editor role to the service account. Substitute your project ID for <gcp-project-id>.

    gcloud projects add-iam-policy-binding <gcp-project-id> \
        --member "serviceAccount:akka-serverless-broker@<gcp-project-id>.iam.gserviceaccount.com" \
        --role "roles/pubsub.editor"
  7. Generate a key file for your service account:

    gcloud iam service-accounts keys create keyfile.json \
        --iam-account akka-serverless-broker@<gcp-project-id>.iam.gserviceaccount.com
  8. Use the cat command to invoke the keyfile.json content:

    cat keyfile.json
  9. Copy the content of the file to your clipboard.

Now you have a service account key file to configure Akka Serverless to use your Google Cloud Pub/Sub broker. Use the following steps to add the key file from the AkkaServerless console:

Browser
  1. Open the project in the AkkaServerless Console.

  2. Select Integrations from the left-hand navigation menu.

  3. Click + for the Google Cloud Pub/Sub integration option.

  4. Copy the contents of keyfile.json into the editor and, click Apply.

The project is now configured to use Google Pub/Sub as the message broker.

CLI
akkasls projects set broker --broker-service google-pubsub --gcp-key-file keyfile.json

The project is now configured to use Google Pub/Sub as the message broker.

Create a topic

To create a topic, you can either use the Google Cloud Console, or the Google Cloud CLI.

Browser
  1. Open the Google Cloud Console.

  2. Go to the Pub/Sub product page.

  3. Click CREATE TOPIC on the top of the screen.

  4. Fill in the Topic ID field and choose any other options you need.

  5. Click CREATE TOPIC in the modal dialog.

You can now use the topic to connect with Akka Serverless

Google Cloud CLI
gcloud pubsub topics create TOPIC_ID

You can now use the topic to connect with Akka Serverless