Class: Google::Cloud::PubSub::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/pubsub/project.rb

Overview

Project

Represents the project that pubsub messages are pushed to and pulled from.

V1::Topic is a named resource to which messages are sent by using Publisher. V1::Subscription is a named resource representing the stream of messages from a single, specific topic, to be delivered to the subscribing application via Subscriber. Message is a combination of data and attributes that a publisher sends to a topic and is eventually delivered to subscribers.

See Google::Cloud#pubsub

Examples:

require "google/cloud/pubsub"

pubsub = Google::Cloud::PubSub.new

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

Instance Method Summary collapse

Instance Method Details

#iamGoogle::Iam::V1::IAMPolicy::Client

Retrieve a client specific for Iam Policy related functions.

Returns:

  • (Google::Iam::V1::IAMPolicy::Client)


121
122
123
# File 'lib/google/cloud/pubsub/project.rb', line 121

def iam
  service.iam
end

#project_idObject Also known as: project

The Pub/Sub project connected to.

Examples:

require "google/cloud/pubsub"

pubsub = Google::Cloud::PubSub.new(
  project_id: "my-project",
  credentials: "/path/to/keyfile.json"
)

pubsub.project_id #=> "my-project"


75
76
77
# File 'lib/google/cloud/pubsub/project.rb', line 75

def project_id
  service.project
end

#project_path(project_name: nil) ⇒ Object

Returns a fully-qualified project path in the form of projects/{project_id}

Parameters:

  • project_name (String) (defaults to: nil)

    A project name. Optional. If provided, this will be used in place of the default project_id.



182
183
184
# File 'lib/google/cloud/pubsub/project.rb', line 182

def project_path project_name: nil
  service.project_path options: { "project" => project_name }.compact
end

#publisher(topic_name, project: nil, async: nil, skip_lookup: nil) ⇒ Google::Cloud::PubSub::Publisher

Retrieves a Publisher by topic name or full project path.

Parameters:

  • topic_name (String)

    Name of a topic. The value can be a simple topic ID (relative name) or a fully-qualified topic name.

  • project (String) (defaults to: nil)

    The alternate project ID can be specified here. Optional. Not used if a fully-qualified topic name is provided for topic_name.

  • async (Hash) (defaults to: nil)

    A hash of values to configure the topic's AsyncPublisher that is created when Google::Cloud::PubSub::Publisher#publish_async is called. Optional.

  • skip_lookup (Boolean) (defaults to: nil)

    Optionally create a Google::Cloud::PubSub::Publisher object without verifying the topic resource exists on the Pub/Sub service. Calls made on this object will raise errors if the service resource does not exist. Default is false.

Returns:



143
144
145
146
147
148
149
# File 'lib/google/cloud/pubsub/project.rb', line 143

def publisher topic_name, project: nil, async: nil, skip_lookup: nil
  ensure_service!
  options = { project: project, async: async }
  return Publisher.from_name topic_name, service, options if skip_lookup
  grpc = topic_admin.get_topic topic: service.topic_path(topic_name, options)
  Publisher.from_grpc grpc, service, async: async
end

#schema_path(schema_name, project_name: nil) ⇒ Object

Returns a fully-qualified schema path in the form of projects/{project_id}/schemas/{schema_name}

Parameters:

  • schema_name (String)

    A schema name.

  • project_name (String) (defaults to: nil)

    A project name. Optional. If provided, this will be used in place of the default project_id.



226
227
228
# File 'lib/google/cloud/pubsub/project.rb', line 226

def schema_path schema_name, project_name: nil
  service.schema_path schema_name, options: { "project" => project_name }.compact
end

#schemasGoogle::Cloud::PubSub::V1::SchemaService::Client

Retrieve a client for managing schemas.

Returns:

  • (Google::Cloud::PubSub::V1::SchemaService::Client)


112
113
114
# File 'lib/google/cloud/pubsub/project.rb', line 112

def schemas
  service.schemas
end

#snapshot_path(snapshot_name, project_name: nil) ⇒ Object

Returns a fully-qualified snapshot path in the form of projects/{project_id}/snapshots/{snapshot_name}

Parameters:

  • snapshot_name (String)

    A snapshot name.

  • project_name (String) (defaults to: nil)

    A project name. Optional. If provided, this will be used in place of the default project_id.



215
216
217
# File 'lib/google/cloud/pubsub/project.rb', line 215

def snapshot_path snapshot_name, project_name: nil
  service.snapshot_path snapshot_name, options: { "project" => project_name }.compact
end

#subscriber(subscription_name, project: nil, skip_lookup: nil) ⇒ Google::Cloud::PubSub::Subscriber?

Retrieves a Subscriber by subscription name or full project path.

Parameters:

  • subscription_name (String)

    Name of a subscription. The value can be a simple subscription ID (relative name) or a fully-qualified subscription name.

  • project (String) (defaults to: nil)

    The alternate project ID can be specified here. Optional. Not used if a fully-qualified topic name is provided for topic_name.

  • skip_lookup (Boolean) (defaults to: nil)

    Optionally create a V1::Subscription object without verifying the subscription resource exists on the Pub/Sub service. Calls made on this object will raise errors if the service resource does not exist. Default is false.

Returns:



168
169
170
171
172
173
174
# File 'lib/google/cloud/pubsub/project.rb', line 168

def subscriber subscription_name, project: nil, skip_lookup: nil
  ensure_service!
  options = { project: project }
  return Subscriber.from_name subscription_name, service, options if skip_lookup
  grpc = subscription_admin.get_subscription subscription: service.subscription_path(subscription_name, options)
  Subscriber.from_grpc grpc, service
end

#subscription_adminGoogle::Cloud::PubSub::SubscriptionAdmin::Client

Retrieve a client for managing subscriptions.



94
95
96
# File 'lib/google/cloud/pubsub/project.rb', line 94

def subscription_admin
  service.subscription_admin
end

#subscription_path(subscription_name, project_name: nil) ⇒ Object

Returns a fully-qualified subscription path in the form of projects/{project_id}/subscriptions/{subscription_name}

Parameters:

  • subscription_name (String)

    A subscription name.

  • project_name (String) (defaults to: nil)

    A project name. Optional. If provided, this will be used in place of the default project_id.



204
205
206
# File 'lib/google/cloud/pubsub/project.rb', line 204

def subscription_path subscription_name, project_name: nil
  service.subscription_path subscription_name, options: { "project" => project_name }.compact
end

#topic_adminGoogle::Cloud::PubSub::TopicAdmin::Client

Retrieve a client for managing topics.



103
104
105
# File 'lib/google/cloud/pubsub/project.rb', line 103

def topic_admin
  service.topic_admin
end

#topic_path(topic_name, project_name: nil) ⇒ Object

Returns a fully-qualified topic path in the form of projects/{project_id}/topics/{topic_name}

Parameters:

  • topic_name (String)

    A topic name.

  • project_name (String) (defaults to: nil)

    A project name. Optional. If provided, this will be used in place of the default project_id.



193
194
195
# File 'lib/google/cloud/pubsub/project.rb', line 193

def topic_path topic_name, project_name: nil
  service.topic_path topic_name, options: { "project" => project_name }.compact
end

#universe_domainString

The universe domain the client is connected to

Returns:

  • (String)


85
86
87
# File 'lib/google/cloud/pubsub/project.rb', line 85

def universe_domain
  service.universe_domain
end