Reference documentation and code samples for the Cloud Pub/Sub API class Google::Cloud::PubSub::Schema.
Schema
A schema resource.
Inherits
- Object
Example
require "google/cloud/pubsub" pubsub = Google::Cloud::PubSub.new schema = pubsub.schema "my-schema" schema.name #=> "projects/my-project/schemas/my-schema" schema.type #=> :PROTOCOL_BUFFER
Methods
#commit
def commit(definition, type) -> Google::Cloud::PubSub::SchemaCommits a new schema revision to an existing schema.
-
definition (String) — The definition of the schema. This should
contain a string representing the full definition of the schema that
is a valid schema definition of the type specified in
type. See https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.schemas#Schema for details. -
type (String, Symbol) —
The type of the schema. Possible values are case-insensitive and include:
PROTOCOL_BUFFER- A Protocol Buffer schema definition.AVRO- An Avro schema definition.
require "google/cloud/pubsub" pubsub = Google::Cloud::PubSub.new schema = pubsub.schema "my-schema" definition = File.read /path/to/file revision_schema = schema.commit definition, type: :protocol_buffer
#definition
def definition() -> String, nilThe definition of the schema. This should be a string representing the full definition of the schema that is a valid schema definition of the type specified in #type.
- (String, nil) — The schema definition.
#delete
def delete() -> BooleanRemoves the schema, if it exists.
-
(Boolean) — Returns
trueif the schema was deleted.
require "google/cloud/pubsub" pubsub = Google::Cloud::PubSub.new schema = pubsub.schema "my-schema" schema.delete
#exists?
def exists?() -> BooleanDetermines whether the schema exists in the Pub/Sub service.
- (Boolean)
require "google/cloud/pubsub" pubsub = Google::Cloud::PubSub.new schema = pubsub.schema "my-schema" schema.exists? #=> true
#list_revisions
def list_revisions(view: nil, page_size: nil, page_token: nil) -> Google::Cloud::PubSub::V1::ListSchemaRevisionsResponseLists all schema revisions for the named schema.
-
view (Symbol, String, nil) (defaults to: nil) —
The set of fields to return in the response. Possible values:
BASIC- Include thenameandtypeof the schema, but not thedefinition.FULL- Include all Schema object fields.
- (Google::Cloud::PubSub::V1::ListSchemaRevisionsResponse)
require "google/cloud/pubsub" pubsub = Google::Cloud::PubSub.new schema = pubsub.schema "my-schema" schema.list_revisions
#name
def name() -> StringThe name of the schema.
-
(String) — A fully-qualified schema name in the form
projects/{project_id}/schemas/{schema_id}.
#reference?
def reference?() -> BooleanDetermines whether the schema object was created without retrieving the resource representation from the Pub/Sub service.
-
(Boolean) —
truewhen the schema was created without a resource representation,falseotherwise.
require "google/cloud/pubsub" pubsub = Google::Cloud::PubSub.new schema = pubsub.schema "my-schema", skip_lookup: true schema.reference? #=> true
#refresh!
def refresh!(view: nil) -> Google::Cloud::PubSub::SchemaReloads the schema with current data from the Pub/Sub service.
-
view (Symbol, String, nil) (defaults to: nil) — The set of fields to return in the response. Possible values:
BASIC- Include thenameandtypeof the schema, but not thedefinition.FULL- Include all Schema object fields.
Optional. If not provided or
nil, the last non-nilviewargument to this method will be used if one has been given, othewiseFULLwill be used.
- (Google::Cloud::PubSub::Schema) — Returns the reloaded schema.
Skip retrieving the schema from the service, then load it:
require "google/cloud/pubsub" pubsub = Google::Cloud::PubSub.new schema = pubsub.schema "my-schema", skip_lookup: true schema.reload!
Use the view option to load the basic or full resource:
require "google/cloud/pubsub" pubsub = Google::Cloud::PubSub.new schema = pubsub.schema "my-schema", view: :basic schema.resource_partial? #=> true schema.reload! view: :full schema.resource_partial? #=> false
#reload!
def reload!(view: nil) -> Google::Cloud::PubSub::SchemaReloads the schema with current data from the Pub/Sub service.
-
view (Symbol, String, nil) (defaults to: nil) — The set of fields to return in the response. Possible values:
BASIC- Include thenameandtypeof the schema, but not thedefinition.FULL- Include all Schema object fields.
Optional. If not provided or
nil, the last non-nilviewargument to this method will be used if one has been given, othewiseFULLwill be used.
- (Google::Cloud::PubSub::Schema) — Returns the reloaded schema.
Skip retrieving the schema from the service, then load it:
require "google/cloud/pubsub" pubsub = Google::Cloud::PubSub.new schema = pubsub.schema "my-schema", skip_lookup: true schema.reload!
Use the view option to load the basic or full resource:
require "google/cloud/pubsub" pubsub = Google::Cloud::PubSub.new schema = pubsub.schema "my-schema", view: :basic schema.resource_partial? #=> true schema.reload! view: :full schema.resource_partial? #=> false
#resource?
def resource?() -> BooleanDetermines whether the schema object was created with a resource representation from the Pub/Sub service.
-
(Boolean) —
truewhen the schema was created with a resource representation,falseotherwise.
require "google/cloud/pubsub" pubsub = Google::Cloud::PubSub.new schema = pubsub.schema "my-schema" schema.resource? #=> true
#resource_full?
def resource_full?() -> BooleanWhether the schema was created with a full resource representation from the Pub/Sub service.
-
(Boolean) —
truewhen the schema was created with a full resource representation,falseotherwise.
require "google/cloud/pubsub" pubsub = Google::Cloud::PubSub.new schema = pubsub.schema "my-schema" schema.resource_full? #=> true
#resource_partial?
def resource_partial?() -> BooleanWhether the schema was created with a partial resource representation from the Pub/Sub service.
-
(Boolean) —
truewhen the schema was created with a partial resource representation,falseotherwise.
require "google/cloud/pubsub" pubsub = Google::Cloud::PubSub.new schema = pubsub.schema "my-schema", view: :basic schema.resource_partial? #=> true schema.reload! view: :full # Loads the full resource. schema.resource_partial? #=> false
#revision_id
def revision_id() -> String, nilThe revision ID of the schema.
- (String) — The revision id.
- (nil) — If this object is a reference.
#type
def type() -> String, nilThe type of the schema. Possible values include:
PROTOCOL_BUFFER- A Protocol Buffer schema definition.AVRO- An Avro schema definition.
- (String, nil) — The upper-case type name.
#validate_message
def validate_message(message_data, message_encoding) -> BooleanValidates a message against a schema.
-
message_data (String) — Message to validate against the provided
schema_spec. -
message_encoding (Symbol, String) —
The encoding of the message validated against the schema. Values include:
JSON- JSON encoding.BINARY- Binary encoding, as defined by the schema type. For some schema types, binary encoding may not be available.
-
(Boolean) — Returns
trueif the message validiation succeeds,falseotherwise.
require "google/cloud/pubsub" pubsub = Google::Cloud::PubSub.new schema = pubsub.schema "my-schema" message_data = { "name" => "Alaska", "post_abbr" => "AK" }.to_json schema.validate_message message_data, :json