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.
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.
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.
Na página Assinaturas, clique em Criar assinatura.
Insira MySub no campo
ID da assinatura.
Em Selecionar um tópico do Cloud Pub/Sub, selecione o tópico MyTopic no menu suspenso.
Nas opções restantes, mantenha os valores padrão.
Clique em Criar.
Você verá a mensagem de sucesso: Subscription successfully added.
A assinatura MySub agora está anexada ao tópico
MyTopic. O Pub/Sub entrega todas as mensagens enviadas para
as assinaturas MyTopic, MySub e MyTopic-sub.
Publique uma mensagem no tópico
No console Google Cloud , acesse a página Tópicos do Pub/Sub.
Você vai ver a mensagem que acabou de publicar. A mensagem tem
os dados, Hello World, e o horário em que a mensagem foi
publicada.
Ao usar o console Google Cloud , um pull individual para um baixo volume de mensagens geralmente não retorna mensagens. Se nenhuma mensagem aparecer, clique em
Extrair várias vezes para emitir várias solicitações de envio. Isso não é um problema
com as bibliotecas de cliente do Pub/Sub.
Limpar
Para evitar cobranças na sua conta do Google Cloud pelos
recursos usados nesta página, siga estas etapas.
Se você não precisar mais do tópico e da assinatura que criou, poderá
excluí-los.
Para excluir o tópico e a assinatura, siga estas etapas:
Acesse a página
Tópicos.
Marque a caixa de seleção ao lado de MyTopic e clique em
Excluir.
Conclua as etapas na janela de confirmação para excluir permanentemente o tópico.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-08-17 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)."]]