Class: Google::Cloud::PubSub::Project
- Inherits:
-
Object
- Object
- Google::Cloud::PubSub::Project
- Defined in:
- lib/google/cloud/pubsub/project.rb
Overview
Project
Represents the project that pubsub messages are pushed to and pulled from. Topic is a named resource to which messages are sent by publishers. Subscription is a named resource representing the stream of messages from a single, specific topic, to be delivered to the subscribing application. Message is a combination of data and attributes that a publisher sends to a topic and is eventually delivered to subscribers.
Instance Method Summary collapse
-
#create_schema(schema_id, type, definition, project: nil) ⇒ Google::Cloud::PubSub::Schema
(also: #new_schema)
Creates a new schema.
-
#create_topic(topic_name, labels: nil, kms_key: nil, persistence_regions: nil, async: nil, schema_name: nil, message_encoding: nil) ⇒ Google::Cloud::PubSub::Topic
(also: #new_topic)
Creates a new topic.
-
#project_id ⇒ Object
(also: #project)
The Pub/Sub project connected to.
-
#schema(schema_name, view: nil, project: nil, skip_lookup: nil) ⇒ Google::Cloud::PubSub::Schema?
(also: #get_schema, #find_schema)
Retrieves schema by name.
-
#schemas(view: nil, token: nil, max: nil) ⇒ Array<Google::Cloud::PubSub::Schema>
(also: #find_schemas, #list_schemas)
Retrieves a list of schemas for the given project.
-
#snapshots(token: nil, max: nil) ⇒ Array<Google::Cloud::PubSub::Snapshot>
(also: #find_snapshots, #list_snapshots)
Retrieves a list of snapshots for the given project.
-
#subscription(subscription_name, project: nil, skip_lookup: nil) ⇒ Google::Cloud::PubSub::Subscription?
(also: #get_subscription, #find_subscription)
Retrieves subscription by name.
-
#subscriptions(token: nil, max: nil) ⇒ Array<Google::Cloud::PubSub::Subscription>
(also: #find_subscriptions, #list_subscriptions)
Retrieves a list of subscriptions for the given project.
-
#topic(topic_name, project: nil, skip_lookup: nil, async: nil) ⇒ Google::Cloud::PubSub::Topic?
(also: #get_topic, #find_topic)
Retrieves topic by name.
-
#topics(token: nil, max: nil) ⇒ Array<Google::Cloud::PubSub::Topic>
(also: #find_topics, #list_topics)
Retrieves a list of topics for the given project.
-
#valid_schema?(type, definition, project: nil) ⇒ Boolean
(also: #validate_schema)
Validates a schema type and definition.
Instance Method Details
#create_schema(schema_id, type, definition, project: nil) ⇒ Google::Cloud::PubSub::Schema Also known as: new_schema
Creates a new schema.
518 519 520 521 522 523 |
# File 'lib/google/cloud/pubsub/project.rb', line 518 def create_schema schema_id, type, definition, project: nil ensure_service! type = type.to_s.upcase grpc = service.create_schema schema_id, type, definition, project: project Schema.from_grpc grpc, service end |
#create_topic(topic_name, labels: nil, kms_key: nil, persistence_regions: nil, async: nil, schema_name: nil, message_encoding: nil) ⇒ Google::Cloud::PubSub::Topic Also known as: new_topic
Creates a new topic.
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/google/cloud/pubsub/project.rb', line 230 def create_topic topic_name, labels: nil, kms_key: nil, persistence_regions: nil, async: nil, schema_name: nil, message_encoding: nil ensure_service! grpc = service.create_topic topic_name, labels: labels, kms_key_name: kms_key, persistence_regions: persistence_regions, schema_name: schema_name, message_encoding: Topic.from_grpc grpc, service, async: async end |
#project_id ⇒ Object Also known as: project
The Pub/Sub project connected to.
71 72 73 |
# File 'lib/google/cloud/pubsub/project.rb', line 71 def project_id service.project end |
#schema(schema_name, view: nil, project: nil, skip_lookup: nil) ⇒ Google::Cloud::PubSub::Schema? Also known as: get_schema, find_schema
Retrieves schema by name.
471 472 473 474 475 476 477 478 479 480 |
# File 'lib/google/cloud/pubsub/project.rb', line 471 def schema schema_name, view: nil, project: nil, skip_lookup: nil ensure_service! = { project: project } return Schema.from_name schema_name, view, service, if skip_lookup view ||= :BASIC grpc = service.get_schema schema_name, view, Schema.from_grpc grpc, service rescue Google::Cloud::NotFoundError nil end |
#schemas(view: nil, token: nil, max: nil) ⇒ Array<Google::Cloud::PubSub::Schema> Also known as: find_schemas, list_schemas
Retrieves a list of schemas for the given project.
The default value is BASIC.
562 563 564 565 566 567 568 |
# File 'lib/google/cloud/pubsub/project.rb', line 562 def schemas view: nil, token: nil, max: nil ensure_service! view ||= :BASIC = { token: token, max: max } grpc = service.list_schemas view, Schema::List.from_grpc grpc, service, view, max end |
#snapshots(token: nil, max: nil) ⇒ Array<Google::Cloud::PubSub::Snapshot> Also known as: find_snapshots, list_snapshots
Retrieves a list of snapshots for the given project.
406 407 408 409 410 411 |
# File 'lib/google/cloud/pubsub/project.rb', line 406 def snapshots token: nil, max: nil ensure_service! = { token: token, max: max } grpc = service.list_snapshots Snapshot::List.from_grpc grpc, service, max end |
#subscription(subscription_name, project: nil, skip_lookup: nil) ⇒ Google::Cloud::PubSub::Subscription? Also known as: get_subscription, find_subscription
Retrieves subscription by name.
324 325 326 327 328 329 330 331 332 |
# File 'lib/google/cloud/pubsub/project.rb', line 324 def subscription subscription_name, project: nil, skip_lookup: nil ensure_service! = { project: project } return Subscription.from_name subscription_name, service, if skip_lookup grpc = service.get_subscription subscription_name, Subscription.from_grpc grpc, service rescue Google::Cloud::NotFoundError nil end |
#subscriptions(token: nil, max: nil) ⇒ Array<Google::Cloud::PubSub::Subscription> Also known as: find_subscriptions, list_subscriptions
Retrieves a list of subscriptions for the given project.
366 367 368 369 370 371 |
# File 'lib/google/cloud/pubsub/project.rb', line 366 def subscriptions token: nil, max: nil ensure_service! = { token: token, max: max } grpc = service.list_subscriptions Subscription::List.from_grpc grpc, service, max end |
#topic(topic_name, project: nil, skip_lookup: nil, async: nil) ⇒ Google::Cloud::PubSub::Topic? Also known as: get_topic, find_topic
Retrieves topic by name.
151 152 153 154 155 156 157 158 159 |
# File 'lib/google/cloud/pubsub/project.rb', line 151 def topic topic_name, project: nil, skip_lookup: nil, async: nil ensure_service! = { project: project } return Topic.from_name topic_name, service, if skip_lookup grpc = service.get_topic topic_name, Topic.from_grpc grpc, service, async: async rescue Google::Cloud::NotFoundError nil end |
#topics(token: nil, max: nil) ⇒ Array<Google::Cloud::PubSub::Topic> Also known as: find_topics, list_topics
Retrieves a list of topics for the given project.
279 280 281 282 283 284 |
# File 'lib/google/cloud/pubsub/project.rb', line 279 def topics token: nil, max: nil ensure_service! = { token: token, max: max } grpc = service.list_topics Topic::List.from_grpc grpc, service, max end |
#valid_schema?(type, definition, project: nil) ⇒ Boolean Also known as: validate_schema
Validates a schema type and definition.
597 598 599 600 601 602 603 604 |
# File 'lib/google/cloud/pubsub/project.rb', line 597 def valid_schema? type, definition, project: nil ensure_service! type = type.to_s.upcase service.validate_schema type, definition, project: project # return type is empty true rescue Google::Cloud::InvalidArgumentError false end |