Cloud PubSub Client - Class Schema (1.46.5)

Reference documentation and code samples for the Cloud PubSub Client class Schema.

Represents a Pub/Sub Schema resource.

Schema Support for Cloud Pub/Sub allows you to register schemas in common formats as standalone versioned resources, associates schemas with Pub/Sub topics, validates message structure on-publish, and provides APIs parameterized on your entity types.

Example:

 use Google\Cloud\PubSub\PubSubClient;

$client = new PubSubClient();
$schema = $client->schema('my-schema'); 

Namespace

Google \ Cloud \ PubSub

Methods

__construct

Parameters
Name
Description
connection
Google\Cloud\PubSub\Connection\ConnectionInterface

A connection to Cloud Pub/Sub This object is created by PubSubClient, and should not be instantiated outside of this client.

name
string

The schema name.

info
array

[optional] Schema data.

name

Get the schema resource name.

Example:

 $name = $schema->name(); 
Returns
Type
Description
string

delete

Delete the schema.

Example:

 $schema->delete(); 
Parameter
Name
Description
options
array

[optional] Configuration options

Returns
Type
Description
void

info

Get schema information.

Since this method will throw an exception if the schema is not found, you may find that Google\Cloud\PubSub\Schema::exists() is a better fit for a true/false check.

This method will use the previously cached result, if available. To force a refresh from the API, use Google\Cloud\PubSub\Schema::reload() .

Example:

 $info = $schema->info();
echo $info['name']; // projects/my-awesome-project/schemas/my-schema 
Parameters
Name
Description
options
array

Configuration Options

↳ view
string

The set of Schema fields to return in the response. If not set, returns Schemas with name and type , but not definition . Set to FULL to retrieve all fields. For allowed values, use constants defined on Google\Cloud\PubSub\V1\SchemaView . Note: for this method, $options.view defaults to FULL .

Returns
Type
Description
array

reload

Get schema information from the API.

Since this method will throw an exception if the schema is not found, you may find that Google\Cloud\PubSub\Schema::exists() is a better fit for a true/false check.

This method will retrieve a new result from the API. To use a previously cached result, if one exists, use Google\Cloud\PubSub\Schema::info() .

Example:

 $info = $schema->reload();
echo $info['name']; // projects/my-awesome-project/schemas/my-schema 
Parameters
Name
Description
options
array

Configuration Options

↳ view
string

The set of Schema fields to return in the response. If not set, returns Schemas with name and type , but not definition . Set to FULL to retrieve all fields. For allowed values, use constants defined on Google\Cloud\PubSub\V1\SchemaView . Note: for this method, $options.view defaults to FULL .

Returns
Type
Description
array

exists

Check if a schema exists.

Example:

 if ($schema->exists()) {
    echo 'Schema exists';
} 
Parameter
Name
Description
options
array

[optional] Configuration Options

Returns
Type
Description
bool
Create a Mobile Website
View Site in Mobile | Classic
Share by: