Nachrichten über die gcloud CLI in Pub/Sub veröffentlichen und empfangen
Auf dieser Seite wird beschrieben, wie Sie mit der Google Cloud CLI die folgenden Vorgänge in Pub/Sub ausführen:
- Thema und Abo erstellen
- Veröffentlichen Sie Nachrichten zum Thema:
- Nachrichten aus dem Abo empfangen
Klicken Sie auf Anleitung, um eine detaillierte Anleitung für diese Aufgabe direkt in der Google Cloud Console aufzurufen.
Hinweise
- Melden Sie sich bei Ihrem Google Cloud-Konto an. Wenn Sie mit Google Cloud noch nicht vertraut sind, erstellen Sie ein Konto, um die Leistungsfähigkeit unserer Produkte in der Praxis sehen und bewerten zu können. Neukunden erhalten außerdem ein Guthaben von 300 $, um Arbeitslasten auszuführen, zu testen und bereitzustellen.
-
Set up a Google Cloud console project.
Click to:
- Create or select a project.
- Enable the Pub/Sub API for that project.
You can view and manage these resources at any time in the Google Cloud console.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Set up a Google Cloud console project.
Click to:
- Create or select a project.
- Enable the Pub/Sub API for that project.
You can view and manage these resources at any time in the Google Cloud console.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
Thema erstellen
Erstellen Sie ein Thema mit der ID my-topic
:
gcloud pubsub topics create my-topic
Abo erstellen
Erstellen Sie ein Abo mit der ID my-sub
und hängen Sie es an my-topic
an:
gcloud pubsub subscriptions create my-sub --topic=my-topic
Nachrichten veröffentlichen
Veröffentlichen Sie eine Nachricht in my-topic
:
gcloud pubsub topics publish my-topic --message="hello"
Nachrichten empfangen
Empfangen Sie die Nachricht von my-sub
:
gcloud pubsub subscriptions pull my-sub --auto-ack
Die gcloud CLI gibt die Nachricht in der Befehlszeile aus.
Wie ist es gelaufen?
Nächste Schritte
Alle verfügbaren gcloud CLI-Befehle für Pub/Sub
Weitere Informationen zu den auf dieser Seite beschriebenen Pub/Sub-Konzepten
Probieren Sie einen anderen Pub/Sub-Schnellstart aus, Verwendet Clientbibliotheken oder in der Console.
Weitere Informationen zum Erstellen von Themen und veröffentliche Mitteilungen.