Publish and receive messages in Pub/Sub using the Trusted Cloud console

This page shows you how to perform basic tasks in Pub/Sub using the Trusted Cloud console.

Before you begin

  1. In the Trusted Cloud console, on the project selector page, select or create a Trusted Cloud project.

    Go to project selector

  2. Make sure that billing is enabled for your Trusted Cloud project.

  3. Enable the Pub/Sub API.

    Enable the API

  4. Make sure that you have the following role or roles on the project: Pub/Sub Admin

    Check for the roles

    1. In the Trusted Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

    4. For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Trusted Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. Click Grant access.
    4. In the New principals field, enter your user identifier. This is typically the identifier for a user in a workforce identity pool. For details, see Represent workforce pool users in IAM policies, or contact your administrator.

    5. In the Select a role list, select a role.
    6. To grant additional roles, click Add another role and add each additional role.
    7. Click Save.

Create a topic

  1. In the Trusted Cloud console, go to the Pub/Sub page.

    Go to Pub/Sub

  2. In the Topics page, click Create topic.

  3. In the window that opens, enter MyTopic in the Topic ID field.

    Leave the default values for the remaining options, and then click Create.

    You see the success message: A new topic and a new subscription have been successfully created.

    You have just created a topic called MyTopic and an associated default subscription MyTopic-sub.

Add a second subscription

To add a second subscription to the topic you just created, complete these steps:

  1. In the Trusted Cloud console, go to the Pub/Sub subscriptions page.

    Go to Subscriptions

  2. In the Subscriptions page, click Create subscription.

  3. Enter MySub in the Subscription ID field.

  4. For Select a Cloud Pub/Sub topic, select the MyTopic topic from the drop-down menu.

  5. Leave the default values for the remaining options.

  6. Click Create.

    You see the success message: Subscription successfully added.

    The MySub subscription is now attached to the topic MyTopic. Pub/Sub delivers all messages sent to MyTopic to the MySub and MyTopic-sub subscriptions.

Publish a message to the topic

  1. In the Trusted Cloud console, go to the Pub/Sub topics page.

    Go to Topics

  2. Click the MyTopic topic.

  3. Click the Topics page and click MyTopic.

  4. In the MyTopic page, click the Messages tab.

  5. Click Publish message.

  6. In the Message body window, enter Hello World.

  7. Click Publish. A message displays at the bottom of the page that says "Message published" if the publish was successful.

Pull the messages from the subscription

  1. In the Trusted Cloud console, go to the Pub/Sub subscriptions page.

    Go to Subscriptions

  2. In the Messages tab, click Pull.

You should see the message that you just published. The message has the data, Hello World, and the time when the message was published.

When using the Trusted Cloud console, an individual pull for a low message volume can often return zero messages. If you do not see messages, click Pull multiple times to issue multiple pull requests. This is not an issue with the Pub/Sub Client Libraries.

Clean up

To avoid incurring charges to your Trusted Cloud account for the resources used on this page, follow these steps.

If you no longer need the topic and subscription you created, you can delete them.

To delete the topic and subscription, complete these steps:

  1. Go to the Topics page.

  2. Check the checkbox next to MyTopic and click Delete.

  3. Complete the steps in the confirmation window to permanently delete the topic.

Or you can delete the project that you created.

What's next