Quickstart using the gcloud command-line tool

Pub/Sub is a messaging service for exchanging event data among applications and services. A producer of data publishes messages to a Pub/Sub topic. A consumer creates a subscription to that topic. Subscribers either pull messages from a subscription or are configured as webhooks for push subscriptions. Every subscriber must acknowledge each message within a configurable window of time.

This page shows how to publish and consume messages with a pull subscriber.

Before you begin

  1. Accede a tu Cuenta de Google.

    Si todavía no tienes una cuenta, regístrate para obtener una nueva.

  2. Configurar un proyecto de GCP Console.

    Configurar un proyecto

    Haz clic para realizar alguna de las siguientes acciones:

    • Crear o seleccionar un proyecto.
    • Habilitar las Pub/Sub API necesarias para el proyecto.

    Puedes visualizar y administrar estos recursos en GCP Console en cualquier momento.

  3. Realiza la instalación y la inicialización del SDK de Cloud.

Use the gcloud command-line tool

You can use the gcloud command-line tool to perform operations in Pub/Sub. The gcloud command-line tool is included in the Cloud SDK you installed in Before you begin. See the gcloud pubsub section in the gcloud reference for a complete list of Pub/Sub gcloud commands.

This self-contained example, meant to run in bash or the Cloud Shell, shows the steps required:

  1. Create a topic.
  2. Subscribe to the topic.
  3. Publish a message to the topic.
  4. Receive the message.
gcloud init
gcloud pubsub topics create my-topic
gcloud pubsub subscriptions create --topic my-topic my-sub
gcloud pubsub topics publish my-topic --message "hello"
gcloud pubsub subscriptions pull --auto-ack my-sub

This example uses a pull subscription. Pub/Sub also supports push subscriptions, as described in the Subscriber guide.

You can perform all administrative operations through the API, and most through the gcloud tool and Cloud Console UI.

How did it go?

Note that additional resources and links are available on the Pub/Sub support page.

What's next

See the Publisher and Subscriber guides to learn more about the concepts discussed in this page.

Get started with Pub/Sub in your language of choice at Pub/Sub Client Libraries .

See Quickstart: Using Client Libraries

for a walkthrough of how to use client library APIs to perform basic Pub/Sub tasks.

For a detailed overview of Pub/Sub, see What Is Pub/Sub?

¿Te ha resultado útil esta página? Enviar comentarios:

Enviar comentarios sobre...

Cloud Pub/Sub Documentation