Sign in to your Google Cloud account. If you're new to
Google Cloud,
create an account to evaluate how our products perform in
real-world scenarios. New customers also get $300 in free credits to
run, test, and deploy workloads.
In the Google Cloud console, on the project selector page,
select or create a Google Cloud project.
Roles required to select or create a project
Select a project: Selecting a project doesn't require a specific
IAM role—you can select any project that you've been
granted a role on.
Create a project: To create a project, you need the Project Creator
(roles/resourcemanager.projectCreator), which contains the
resourcemanager.projects.create permission. Learn how to grant
roles.
To enable APIs, you need the Service Usage Admin IAM
role (roles/serviceusage.serviceUsageAdmin), which
contains the serviceusage.services.enable permission. Learn how to grant
roles.
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.
For all rows that specify or include you, check the Role column to see whether
the list of roles includes the required roles.
En el campo Nuevos principales, introduce tu identificador de usuario.
Normalmente, se trata de la dirección de correo de una cuenta de Google.
En la lista Selecciona un rol, elige un rol.
Para conceder más roles, haz clic en addAñadir otro rol y añade cada rol adicional.
Haz clic en Guardar.
In the Google Cloud console, on the project selector page,
select or create a Google Cloud project.
Roles required to select or create a project
Select a project: Selecting a project doesn't require a specific
IAM role—you can select any project that you've been
granted a role on.
Create a project: To create a project, you need the Project Creator
(roles/resourcemanager.projectCreator), which contains the
resourcemanager.projects.create permission. Learn how to grant
roles.
To enable APIs, you need the Service Usage Admin IAM
role (roles/serviceusage.serviceUsageAdmin), which
contains the serviceusage.services.enable permission. Learn how to grant
roles.
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.
For all rows that specify or include you, check the Role column to see whether
the list of roles includes the required roles.
En la página Suscripciones, haz clic en Crear suscripción.
Introduce MySub en el campo ID de suscripción.
En Selecciona un tema de Cloud Pub/Sub, elige el tema MyTopic en el menú desplegable.
Deje los valores predeterminados de las opciones restantes.
Haz clic en Crear.
Verás el mensaje de confirmación: Subscription successfully added.
La suscripción MySub ahora está vinculada al tema MyTopic. Pub/Sub envía todos los mensajes enviados a MyTopic a las suscripciones MySub y MyTopic-sub.
Publicar un mensaje en el tema
En la Google Cloud consola, ve a la página Temas de Pub/Sub.
Haz clic en la página
Temas
y, a continuación, en MyTopic.
En la página MyTopic, haz clic en la pestaña Mensajes.
Haz clic en
Publicar mensaje.
En la ventana Cuerpo del mensaje, escribe Hello World.
Haz clic en Publicar. Si la publicación se ha realizado correctamente, aparecerá un mensaje en la parte inferior de la página que indica que se ha publicado.
Extraer los mensajes de la suscripción
En la Google Cloud consola, ve a la página Suscripciones de Pub/Sub.
Debería aparecer el mensaje que acabas de publicar. El mensaje contiene los datos Hello World y la hora en la que se publicó.
Cuando se usa la Google Cloud consola, una extracción individual de un volumen de mensajes bajo a menudo puede devolver cero mensajes. Si no ves ningún mensaje, haz clic en
Extraer varias veces para enviar varias solicitudes de extracción. No se trata de un problema de las bibliotecas de cliente de Pub/Sub.
Limpieza
Para evitar que se apliquen cargos en tu cuenta de Google Cloud por los recursos utilizados en esta página, sigue estos pasos.
Si ya no necesitas el tema y la suscripción que has creado, puedes eliminarlos.
Para eliminar el tema y la suscripción, sigue estos pasos:
Ve a la página
Temas.
Marca la casilla situada junto a MyTopic y haz clic en
Eliminar.
Completa los pasos que se indican en la ventana de confirmación para eliminar el tema de forma permanente.
[[["Es fácil de entender","easyToUnderstand","thumb-up"],["Me ofreció una solución al problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Es difícil de entender","hardToUnderstand","thumb-down"],["La información o el código de muestra no son correctos","incorrectInformationOrSampleCode","thumb-down"],["Me faltan las muestras o la información que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-09-11 (UTC)."],[],[],null,["# Quickstart: Publish and receive messages in Pub/Sub using the Google Cloud console\n\nPublish and receive messages in Pub/Sub using the Google Cloud console\n======================================================================\n\nThis page shows you how to perform basic tasks in Pub/Sub using the\nGoogle Cloud console.\n\n*** ** * ** ***\n\nTo follow step-by-step guidance for this task directly in the\nGoogle Cloud console, click **Guide me**:\n\n[Guide me](https://console.cloud.google.com/freetrial?redirectPath=/home/dashboard?tutorial=pubsub--publish_receive_messages_console)\n\n*** ** * ** ***\n\nBefore you begin\n----------------\n\n- Sign in to your Google Cloud account. If you're new to Google Cloud, [create an account](https://console.cloud.google.com/freetrial) to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n-\n\n\n Enable the Pub/Sub API.\n\n\n [Enable the API](https://console.cloud.google.com/flows/enableapi?apiid=pubsub.googleapis.com)\n-\n\n Make sure that you have the following role or roles on the project:\n\n Pub/Sub Admin\n\n #### Check for the roles\n\n 1.\n In the Google Cloud console, go to the **IAM** page.\n\n [Go to IAM](https://console.cloud.google.com/projectselector/iam-admin/iam?supportedpurview=project)\n 2. Select the project.\n 3.\n In the **Principal** column, find all rows that identify you or a group that\n you're included in. To learn which groups you're included in, contact your\n administrator.\n\n 4. For all rows that specify or include you, check the **Role** column to see whether the list of roles includes the required roles.\n\n #### Grant the roles\n\n 1.\n In the Google Cloud console, go to the **IAM** page.\n\n [Go to IAM](https://console.cloud.google.com/projectselector/iam-admin/iam?supportedpurview=project)\n 2. Select the project.\n 3. Click person_add **Grant access**.\n 4.\n In the **New principals** field, enter your user identifier.\n\n This is typically the email address for a Google Account.\n\n 5. In the **Select a role** list, select a role.\n 6. To grant additional roles, click add **Add\n another role** and add each additional role.\n 7. Click **Save**.\n\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n-\n\n\n Enable the Pub/Sub API.\n\n\n [Enable the API](https://console.cloud.google.com/flows/enableapi?apiid=pubsub.googleapis.com)\n-\n\n Make sure that you have the following role or roles on the project:\n\n Pub/Sub Admin\n\n #### Check for the roles\n\n 1.\n In the Google Cloud console, go to the **IAM** page.\n\n [Go to IAM](https://console.cloud.google.com/projectselector/iam-admin/iam?supportedpurview=project)\n 2. Select the project.\n 3.\n In the **Principal** column, find all rows that identify you or a group that\n you're included in. To learn which groups you're included in, contact your\n administrator.\n\n 4. For all rows that specify or include you, check the **Role** column to see whether the list of roles includes the required roles.\n\n #### Grant the roles\n\n 1.\n In the Google Cloud console, go to the **IAM** page.\n\n [Go to IAM](https://console.cloud.google.com/projectselector/iam-admin/iam?supportedpurview=project)\n 2. Select the project.\n 3. Click person_add **Grant access**.\n 4.\n In the **New principals** field, enter your user identifier.\n\n This is typically the email address for a Google Account.\n\n 5. In the **Select a role** list, select a role.\n 6. To grant additional roles, click add **Add\n another role** and add each additional role.\n 7. Click **Save**.\n\nCreate a topic\n--------------\n\n1. In the Google Cloud console, go to the **Pub/Sub**\n page.\n\n\n [Go to Pub/Sub](https://console.cloud.google.com/cloudpubsub/topicList)\n2. In the **Topics** page, click **Create topic**.\n\n3. In the window that opens, enter `MyTopic` in the **Topic ID** field.\n\n Leave the default values for the remaining options, and then click **Create**.\n\n You see the success message: `A new topic and a new subscription have been successfully created.`\n\n You have just created a topic called `MyTopic` and an associated default subscription `MyTopic-sub`.\n\nAdd a second subscription\n-------------------------\n\nTo add a second subscription to the topic you just created, complete these steps:\n\n1. In the Google Cloud console, go to the **Pub/Sub subscriptions** page.\n\n [Go to Subscriptions](https://console.cloud.google.com/cloudpubsub/subscription/list)\n2. In the **Subscriptions** page, click **Create subscription**.\n\n3. Enter `MySub` in the\n **Subscription ID** field.\n\n4. For **Select a Cloud Pub/Sub topic** , select the `MyTopic` topic from the drop-down menu.\n\n5. Leave the default values for the remaining options.\n\n6. Click **Create**.\n\n You see the success message: `Subscription successfully added.`\n\n The `MySub` subscription is now attached to the topic\n `MyTopic`. Pub/Sub delivers all messages sent to\n `MyTopic` to the `MySub` and `MyTopic-sub` subscriptions.\n\nPublish a message to the topic\n------------------------------\n\n1. In the Google Cloud console, go to the **Pub/Sub topics**\n page.\n\n [Go to Topics](https://console.cloud.google.com/cloudpubsub/topicList)\n2. Click the `MyTopic` topic.\n\n3. Click the\n **Topics**\n page and click `MyTopic`.\n\n4. In the `MyTopic` page, click the **Messages** tab.\n\n5. Click\n **Publish message**.\n\n6. In the **Message body** window, enter `Hello World`.\n\n7. Click **Publish**. A message displays at the bottom of the page that says \"Message published\" if the publish was successful.\n\nPull the messages from the subscription\n---------------------------------------\n\n1. In the Google Cloud console, go to the **Pub/Sub subscriptions** page.\n\n [Go to Subscriptions](https://console.cloud.google.com/cloudpubsub/subscription/list)\n2. In the **Messages** tab, click **Pull**.\n\nYou should see the message that you just published. The message has\nthe data, `Hello World`, and the time when the message was\npublished.\n\nWhen using the Google Cloud console, an individual pull for a low\nmessage volume can often return zero messages. If you do not see messages, click\n**Pull** multiple times to issue multiple pull requests. This is not an issue\nwith the [Pub/Sub Client Libraries](/pubsub/docs/publish-receive-messages-client-library).\n\nClean up\n--------\n\n\nTo avoid incurring charges to your Google Cloud account for\nthe resources used on this page, follow these steps.\n\nIf you no longer need the topic and subscription you created, you\ncan delete them.\n\nTo delete the topic and subscription, complete these steps:\n\n1. Go to the\n **Topics**\n page.\n\n2. Check the checkbox next to `MyTopic` and click\n **Delete**.\n\n3. Complete the steps in the confirmation window to permanently delete the\n topic.\n\nOr you can [delete the project](https://console.cloud.google.com/cloud-resource-manager) that you created.\n\nWhat's next\n-----------\n\n- Learn more about the Pub/Sub [concepts](/pubsub/docs/overview)\n discussed in this page.\n\n- Read the [basics of the Pub/Sub service](/pubsub/docs/pubsub-basics).\n\n- Work through an [end-to-end example](/pubsub/docs/building-pubsub-messaging-system)\n of a Pub/Sub system.\n\n- Try another Pub/Sub quickstart that\n uses [client libraries](/pubsub/docs/publish-receive-messages-client-library)\n or the [Google Cloud CLI](/pubsub/docs/publish-receive-messages-gcloud).\n\n- Learn how to create [topics](/pubsub/docs/create-topic)\n and publish [messages](/pubsub/docs/publisher).\n\n- [Choose](/pubsub/docs/subscriber) or [create](/pubsub/docs/create-subscription) a subscription.\n\n- Learn more about [Pub/Sub APIs](/pubsub/docs/reference/service_apis_overview)."]]