Configure message brokers

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

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 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>" \
        --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>
  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:

  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.

akkasls projects set broker --broker-service gcp-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.

  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