Module: Google::Cloud

Defined in:
lib/google-cloud-pubsub.rb,
lib/google/cloud/pubsub.rb,
lib/google/cloud/pubsub/errors.rb,
lib/google/cloud/pubsub/convert.rb,
lib/google/cloud/pubsub/message.rb,
lib/google/cloud/pubsub/project.rb,
lib/google/cloud/pubsub/service.rb,
lib/google/cloud/pubsub/version.rb,
lib/google/cloud/pubsub/publisher.rb,
lib/google/cloud/pubsub/subscriber.rb,
lib/google/cloud/pubsub/credentials.rb,
lib/google/cloud/pubsub/admin_clients.rb,
lib/google/cloud/pubsub/publish_result.rb,
lib/google/cloud/pubsub/async_publisher.rb,
lib/google/cloud/pubsub/batch_publisher.rb,
lib/google/cloud/pubsub/flow_controller.rb,
lib/google/cloud/pubsub/internal_logger.rb,
lib/google/cloud/pubsub/message_listener.rb,
lib/google/cloud/pubsub/received_message.rb,
lib/google/cloud/pubsub/acknowledge_result.rb,
lib/google/cloud/pubsub/async_publisher/batch.rb,
lib/google/cloud/pubsub/message_listener/stream.rb,
lib/google/cloud/pubsub/message_listener/inventory.rb,
lib/google/cloud/pubsub/message_listener/sequencer.rb,
lib/google/cloud/pubsub/message_listener/enumerator_queue.rb,
lib/google/cloud/pubsub/message_listener/timed_unary_buffer.rb

Defined Under Namespace

Modules: PubSub

Constant Summary collapse

Pubsub =

Legacy veneer namespace

PubSub

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.pubsub(project_id = nil, credentials = nil, scope: nil, timeout: nil) ⇒ Google::Cloud::PubSub::Project

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.

Examples:

require "google/cloud"

pubsub = Google::Cloud.pubsub

publisher = pubsub.publisher "my-topic"
publisher.publish "task completed"

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 (Google::Auth::Credentials) (defaults to: nil)

    A Google::Auth::Credentials object. (See Google::Cloud::PubSub::Credentials) @note Warning: Passing a String to a keyfile path or a Hash of credentials is deprecated. Providing an unvalidated credential configuration to Google APIs can compromise the security of your systems and data.

    @example

    # The recommended way to provide credentials is to use the make_creds method # on the appropriate credentials class for your environment.

    require "googleauth"

    credentials = ::Google::Auth::ServiceAccountCredentials.make_creds( json_key_io: ::File.open("/path/to/keyfile.json") )

    pubsub = Google::Cloud::Pubsub.new project_id: "my-project", credentials: credentials

  • scope (String, Array<String>) (defaults to: nil)

    The OAuth 2.0 scopes controlling the set of resources and operations that the connection can access. See Using OAuth 2.0 to Access Google APIs.

    The default scope is:

    • https://www.googleapis.com/auth/pubsub
  • timeout (Numeric) (defaults to: nil)

    Default timeout to use in requests. Optional.

Returns:



118
119
120
121
122
123
124
# File 'lib/google-cloud-pubsub.rb', line 118

def self.pubsub project_id = nil,
                credentials = nil,
                scope: nil,
                timeout: nil
  require "google/cloud/pubsub"
  Google::Cloud::PubSub.new project_id: project_id, credentials: credentials, scope: scope, timeout: timeout
end

Instance Method Details

#pubsub(scope: nil, timeout: nil) ⇒ Google::Cloud::PubSub::Project

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.

Examples:

require "google/cloud"

gcloud = Google::Cloud.new
pubsub = gcloud.pubsub
topic_admin = pubsub.topic_admin
publisher = pubsub.publisher "my-topic"
publisher.publish "task completed"

The default scope can be overridden with the scope option:

require "google/cloud"

gcloud  = Google::Cloud.new
platform_scope = "https://www.googleapis.com/auth/cloud-platform"
pubsub = gcloud.pubsub scope: platform_scope

Parameters:

  • scope (String, Array<String>) (defaults to: nil)

    The OAuth 2.0 scopes controlling the set of resources and operations that the connection can access. See Using OAuth 2.0 to Access Google APIs.

    The default scope is:

    • https://www.googleapis.com/auth/pubsub
  • timeout (Numeric) (defaults to: nil)

    Default timeout to use in requests. Optional.

Returns:



65
66
67
68
# File 'lib/google-cloud-pubsub.rb', line 65

def pubsub scope: nil, timeout: nil
  timeout ||= @timeout
  Google::Cloud.pubsub @project, @keyfile, scope: scope, timeout: timeout
end