Reference documentation and code samples for the Cloud Pub/Sub API module Google::Cloud::PubSub.
Google Cloud Pub/Sub
Google Cloud Pub/Sub is designed to provide reliable, many-to-many,
asynchronous messaging between applications. Publisher applications can
send messages to a "topic" and other applications can subscribe to that
topic to receive the messages. By decoupling senders and receivers, Google
Cloud Pub/Sub allows developers to communicate between independently
written applications.
The following PubSub configuration parameters are supported:
project_id - (String) Identifier for a PubSub project.
credentials - (String, Hash, Google::Auth::Credentials) The path to
the keyfile as a String, the contents of the keyfile as a Hash, or a
Google::Auth::Credentials object. (See Credentials)
scope - (String, Array
quota_project - (String) The project ID for a project that can be
used by client libraries for quota and billing purposes.
timeout - (Numeric) Default timeout to use in requests.
endpoint - (String) Override of the endpoint host name, or nil
to use the default endpoint.
emulator_host - (String) Host name of the emulator. Defaults to
ENV["PUBSUB_EMULATOR_HOST"]
on_error - (Proc) A Proc to be run when an error is encountered
on a background thread. The Proc must take the error object as the
single argument. (See MessageListener#on_error.)
Yields
(Google::Cloud.configure.pubsub)
Returns
(Google::Cloud::Config) โ The configuration object the
Google::Cloud::PubSub library uses.
Creates a new object for connecting to the Pub/Sub service.
Each call creates a new connection.
For more information on connecting to Google Cloud see the
Authentication Guide.
Parameters
project_id (String) (defaults to: nil) โ Project identifier for the Pub/Sub service
you are connecting to. If not present, the default project for the
credentials is used.
credentials (String, Hash, Google::Auth::Credentials) (defaults to: nil) โ The path to
the keyfile as a String, the contents of the keyfile as a Hash, or a
Google::Auth::Credentials object. (See Credentials)
scope (String, Array<String>) (defaults to: nil) โ
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["# Cloud Pub/Sub API - Module Google::Cloud::PubSub (v3.0.2)\n\nVersion latestkeyboard_arrow_down\n\n- [3.0.2 (latest)](/ruby/docs/reference/google-cloud-pubsub/latest/Google-Cloud-PubSub)\n- [3.0.1](/ruby/docs/reference/google-cloud-pubsub/3.0.1/Google-Cloud-PubSub)\n- [2.23.0](/ruby/docs/reference/google-cloud-pubsub/2.23.0/Google-Cloud-PubSub)\n- [2.22.0](/ruby/docs/reference/google-cloud-pubsub/2.22.0/Google-Cloud-PubSub)\n- [2.21.0](/ruby/docs/reference/google-cloud-pubsub/2.21.0/Google-Cloud-PubSub)\n- [2.20.0](/ruby/docs/reference/google-cloud-pubsub/2.20.0/Google-Cloud-PubSub)\n- [2.19.0](/ruby/docs/reference/google-cloud-pubsub/2.19.0/Google-Cloud-PubSub)\n- [2.18.1](/ruby/docs/reference/google-cloud-pubsub/2.18.1/Google-Cloud-PubSub)\n- [2.17.0](/ruby/docs/reference/google-cloud-pubsub/2.17.0/Google-Cloud-PubSub)\n- [2.16.0](/ruby/docs/reference/google-cloud-pubsub/2.16.0/Google-Cloud-PubSub)\n- [2.15.5](/ruby/docs/reference/google-cloud-pubsub/2.15.5/Google-Cloud-PubSub)\n- [2.14.0](/ruby/docs/reference/google-cloud-pubsub/2.14.0/Google-Cloud-PubSub)\n- [2.12.1](/ruby/docs/reference/google-cloud-pubsub/2.12.1/Google-Cloud-PubSub)\n- [2.11.0](/ruby/docs/reference/google-cloud-pubsub/2.11.0/Google-Cloud-PubSub)\n- [2.10.0](/ruby/docs/reference/google-cloud-pubsub/2.10.0/Google-Cloud-PubSub)\n- [2.9.2](/ruby/docs/reference/google-cloud-pubsub/2.9.2/Google-Cloud-PubSub) \nReference documentation and code samples for the Cloud Pub/Sub API module Google::Cloud::PubSub.\n\nGoogle Cloud Pub/Sub\n--------------------\n\nGoogle Cloud Pub/Sub is designed to provide reliable, many-to-many,\nasynchronous messaging between applications. Publisher applications can\nsend messages to a \"topic\" and other applications can subscribe to that\ntopic to receive the messages. By decoupling senders and receivers, Google\nCloud Pub/Sub allows developers to communicate between independently\nwritten applications.\n\nSee [Google Cloud Pub/Sub Overview](./OVERVIEW \"Google Cloud Pub/Sub Overview\").\n\nMethods\n-------\n\n### .configure\n\n def self.configure() -\u003e Google::Cloud::Config\n\nConfigure the Google Cloud PubSub library.\n\nThe following PubSub configuration parameters are supported:\n\n- `project_id` - (String) Identifier for a PubSub project.\n- `credentials` - (String, Hash, Google::Auth::Credentials) The path to the keyfile as a String, the contents of the keyfile as a Hash, or a Google::Auth::Credentials object. (See [Credentials](/ruby/docs/reference/google-cloud-pubsub/latest/Google-Cloud-PubSub-Credentials \"Google::Cloud::PubSub::Credentials (class)\"))\n- `scope` - (String, Array\n- `quota_project` - (String) The project ID for a project that can be used by client libraries for quota and billing purposes.\n- `timeout` - (Numeric) Default timeout to use in requests.\n- `endpoint` - (String) Override of the endpoint host name, or `nil` to use the default endpoint.\n- `emulator_host` - (String) Host name of the emulator. Defaults to `ENV[\"PUBSUB_EMULATOR_HOST\"]`\n- `on_error` - (Proc) A Proc to be run when an error is encountered on a background thread. The Proc must take the error object as the single argument. (See [MessageListener#on_error](/ruby/docs/reference/google-cloud-pubsub/latest/Google-Cloud-PubSub-MessageListener#Google__Cloud__PubSub__MessageListener_on_error_instance_ \"Google::Cloud::PubSub::MessageListener#on_error (method)\").) \n**Yields**\n\n- (Google::Cloud.configure.pubsub) \n**Returns**\n\n- (Google::Cloud::Config) --- The configuration object the Google::Cloud::PubSub library uses.\n\n### .new\n\n def self.new(project_id: nil, credentials: nil, scope: nil, timeout: nil, universe_domain: nil, endpoint: nil, emulator_host: nil) -\u003e Google::Cloud::PubSub::Project\n\nCreates a new object for connecting to the Pub/Sub service.\nEach call creates a new connection.\n\n\n\u003cbr /\u003e\n\nFor more information on connecting to Google Cloud see the\n[Authentication Guide](./AUTHENTICATION \"Authentication Guide\"). \n**Parameters**\n\n- **project_id** (String) *(defaults to: nil)* --- Project identifier for the Pub/Sub service you are connecting to. If not present, the default project for the credentials is used.\n- **credentials** (String, Hash, Google::Auth::Credentials) *(defaults to: nil)* --- The path to the keyfile as a String, the contents of the keyfile as a Hash, or a Google::Auth::Credentials object. (See [Credentials](/ruby/docs/reference/google-cloud-pubsub/latest/Google-Cloud-PubSub-Credentials \"Google::Cloud::PubSub::Credentials (class)\"))\n- **scope** (String, Array\\\u003cString\\\u003e) *(defaults to: nil)* ---\n\n The OAuth 2.0 scopes controlling\n the set of resources and operations that the connection can access.\n See [Using OAuth 2.0 to Access Google\n APIs](https://developers.google.com/identity/protocols/OAuth2).\n\n The default scope is:\n - `https://www.googleapis.com/auth/pubsub`\n- **timeout** (Numeric) *(defaults to: nil)* --- Default timeout to use in requests. Optional.\n- **endpoint** (String) *(defaults to: nil)* --- Override of the endpoint host name. Optional. If the param is nil, uses the default endpoint.\n- **emulator_host** (String) *(defaults to: nil)* --- Pub/Sub emulator host. Optional. If the param is nil, uses the value of the `emulator_host` config.\n- **universe_domain** (String) *(defaults to: nil)* --- A custom universe domain. Optional. \n**Returns**\n\n- ([Google::Cloud::PubSub::Project](./Google-Cloud-PubSub-Project)) \n**Raises**\n\n- (ArgumentError)\n**Example** \n\n```ruby\nrequire \"google/cloud/pubsub\"\n\npubsub = Google::Cloud::PubSub.new\n\npublisher = pubsub.publisher \"my-topic\"\npublisher.publish \"task completed\"\n```\n\nConstants\n---------\n\n### DEFAULT_COMPRESS\n\n**value:**false\n\n### DEFAULT_COMPRESSION_BYTES_THRESHOLD\n\n**value:**240\n\n### VERSION\n\n**value:**\"3.0.2\".freeze"]]