This document provides information about using concurrency control with messages published to a topic.
Concurrency control helps you override the default number of background (I/O) threads used by the client library to publish messages. This lets the publisher clients to send messages in parallel. You can also implement your own concurrency control when you're using a low-level library.
Support for concurrency control depends on the programming language of the client library. For language implementations that support parallel threads, such as C++, Go, and Java, the client libraries make a default choice for the number of threads.
Before you begin
Before configuring the publish workflow, ensure you have completed the following tasks:
- Learn about topics and the publishing workflow.
- Create a topic.
Required roles
To get the permissions that you need to publish messages to a topic,
ask your administrator to grant you the
Pub/Sub Publisher (roles/pubsub.publisher
) IAM role on topic.
For more information about granting roles, see Manage access to projects, folders, and organizations.
You might also be able to get the required permissions through custom roles or other predefined roles.
You need additional permissions to create or update topics and subscriptions.
Use Concurrency control with messages
Support for concurrency depends on your programming language. Refer to the API Reference documentation for more information.
The following sample illustrates how to control concurrency in a publisher:
C++
Before trying this sample, follow the C++ setup instructions in Quickstart: Using Client Libraries. For more information, see the Pub/Sub C++ API reference documentation.
Go
Before trying this sample, follow the Go setup instructions in Quickstart: Using Client Libraries. For more information, see the Pub/Sub Go API reference documentation.
Java
Before trying this sample, follow the Java setup instructions in Quickstart: Using Client Libraries. For more information, see the Pub/Sub Java API reference documentation.
Ruby
Before trying this sample, follow the Ruby setup instructions in Quickstart: Using Client Libraries. For more information, see the Pub/Sub Ruby API reference documentation.
What's next
To restrict the locations in which Pub/Sub stores message data, see Restricting Pub/Sub resource locations.
To learn more about receiving messages, see Choose a subscription type.