Class PubSub (2.13.0)

[Cloud Pub/Sub]( https://developers.google.com/pubsub/overview ) is a reliable, many-to-many, asynchronous messaging service from Cloud Platform.

[Cloud Pub/Sub overview] https://developers.google.com/pubsub/overview

Package

@google-cloud/pubsub!

Constructors

(constructor)(options)

  constructor 
 ( 
 options 
 ?: 
  
 ClientConfig 
 ); 
 

Constructs a new instance of the PubSub class

Parameter
Name Description
options ClientConfig

Properties

api

  api 
 : 
  
 { 
  
 [ 
 key 
 : 
  
 string 
 ] 
 : 
  
 gax 
 . 
 ClientStub 
 ; 
  
 }; 
 
Property Value
Type Description
{ [key: string]: gax. ClientStub ; }

auth

  auth 
 : 
  
 GoogleAuth 
 ; 
 
Property Value
Type Description
GoogleAuth

getSnapshotsStream

  getSnapshotsStream 
 : 
  
 () 
  
 = 
>  
 ObjectStream<Snapshot> 
 ; 
 
Property Value
Type Description
() => ObjectStream < Snapshot >

getSubscriptionsStream

  getSubscriptionsStream 
 : 
  
 () 
  
 = 
>  
 ObjectStream<Subscription> 
 ; 
 
Property Value
Type Description
() => ObjectStream < Subscription >

getTopicsStream

  getTopicsStream 
 : 
  
 () 
  
 = 
>  
 ObjectStream<Topic> 
 ; 
 
Property Value
Type Description
() => ObjectStream < Topic >

isEmulator

  isEmulator 
 : 
  
 boolean 
 ; 
 
Property Value
Type Description
boolean

isIdResolved

  get 
  
 isIdResolved 
 () 
 : 
  
 boolean 
 ; 
 

Returns true if we have actually resolved the full project name.

Property Value
Type Description
boolean

isOpen

  isOpen 
 : 
  
 boolean 
 ; 
 
Property Value
Type Description
boolean

name

  name 
 ?: 
  
 string 
 ; 
 
Property Value
Type Description
string

options

  options 
 : 
  
 ClientConfig 
 ; 
 
Property Value
Type Description
ClientConfig

projectId

  projectId 
 : 
  
 string 
 ; 
 
Property Value
Type Description
string

Promise

  Promise 
 ?: 
  
 PromiseConstructor 
 ; 
 
Property Value
Type Description
PromiseConstructor

Methods

close()

  close 
 () 
 : 
  
 Promise<void> 
 ; 
 
Returns
Type Description
Promise <void>

close(callback)

  close 
 ( 
 callback 
 : 
  
 EmptyCallback 
 ) 
 : 
  
 void 
 ; 
 
Parameter
Name Description
callback EmptyCallback
Returns
Type Description
void

closeAllClients_()

  closeAllClients_ 
 () 
 : 
  
 Promise<void> 
 ; 
 

Close all open client objects.

Returns
Type Description
Promise <void>

{Promise}

createSchema(schemaId, type, definition, gaxOpts)

  createSchema 
 ( 
 schemaId 
 : 
  
 string 
 , 
  
 type 
 : 
  
 SchemaType 
 , 
  
 definition 
 : 
  
 string 
 , 
  
 gaxOpts 
 ?: 
  
 CallOptions 
 ) 
 : 
  
 Promise<Schema> 
 ; 
 

Create a schema in the project.

[Schemas: create API Documentation] https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.schemas/create

Parameters
Name Description
schemaId string

The name or ID of the subscription.

type SchemaType

The type of the schema (Protobuf, Avro, etc).

definition string

The text describing the schema in terms of the type.

gaxOpts CallOptions
Returns
Type Description
Promise < Schema >

{Promise

createSubscription(topic, name, options)

  createSubscription 
 ( 
 topic 
 : 
  
 Topic 
  
 | 
  
 string 
 , 
  
 name 
 : 
  
 string 
 , 
  
 options 
 ?: 
  
 CreateSubscriptionOptions 
 ) 
 : 
  
 Promise<CreateSubscriptionResponse> 
 ; 
 
Parameters
Name Description
topic Topic | string
name string
options CreateSubscriptionOptions
Returns
Type Description
Promise < CreateSubscriptionResponse >

createSubscription(topic, name, callback)

  createSubscription 
 ( 
 topic 
 : 
  
 Topic 
  
 | 
  
 string 
 , 
  
 name 
 : 
  
 string 
 , 
  
 callback 
 : 
  
 CreateSubscriptionCallback 
 ) 
 : 
  
 void 
 ; 
 
Parameters
Name Description
topic Topic | string
name string
callback CreateSubscriptionCallback
Returns
Type Description
void

createSubscription(topic, name, options, callback)

  createSubscription 
 ( 
 topic 
 : 
  
 Topic 
  
 | 
  
 string 
 , 
  
 name 
 : 
  
 string 
 , 
  
 options 
 : 
  
 CreateSubscriptionOptions 
 , 
  
 callback 
 : 
  
 CreateSubscriptionCallback 
 ) 
 : 
  
 void 
 ; 
 
Parameters
Name Description
topic Topic | string
name string
options CreateSubscriptionOptions
callback CreateSubscriptionCallback
Returns
Type Description
void

createTopic(name, gaxOpts)

  createTopic 
 ( 
 name 
 : 
  
 string 
  
 | 
  
 TopicMetadata 
 , 
  
 gaxOpts 
 ?: 
  
 CallOptions 
 ) 
 : 
  
 Promise<CreateTopicResponse> 
 ; 
 
Parameters
Name Description
name string | TopicMetadata
gaxOpts CallOptions
Returns
Type Description
Promise < CreateTopicResponse >

createTopic(name, callback)

  createTopic 
 ( 
 name 
 : 
  
 string 
  
 | 
  
 TopicMetadata 
 , 
  
 callback 
 : 
  
 CreateTopicCallback 
 ) 
 : 
  
 void 
 ; 
 
Parameters
Name Description
name string | TopicMetadata
callback CreateTopicCallback
Returns
Type Description
void

createTopic(name, gaxOpts, callback)

  createTopic 
 ( 
 name 
 : 
  
 string 
  
 | 
  
 TopicMetadata 
 , 
  
 gaxOpts 
 : 
  
 CallOptions 
 , 
  
 callback 
 : 
  
 CreateTopicCallback 
 ) 
 : 
  
 void 
 ; 
 
Parameters
Name Description
name string | TopicMetadata
gaxOpts CallOptions
callback CreateTopicCallback
Returns
Type Description
void

detachSubscription(name, gaxOpts)

  detachSubscription 
 ( 
 name 
 : 
  
 string 
 , 
  
 gaxOpts 
 ?: 
  
 CallOptions 
 ) 
 : 
  
 Promise<DetachSubscriptionResponse> 
 ; 
 
Parameters
Name Description
name string
gaxOpts CallOptions
Returns
Type Description
Promise < DetachSubscriptionResponse >

detachSubscription(name, callback)

  detachSubscription 
 ( 
 name 
 : 
  
 string 
 , 
  
 callback 
 : 
  
 DetachSubscriptionCallback 
 ) 
 : 
  
 void 
 ; 
 
Parameters
Name Description
name string
callback DetachSubscriptionCallback
Returns
Type Description
void

detachSubscription(name, gaxOpts, callback)

  detachSubscription 
 ( 
 name 
 : 
  
 string 
 , 
  
 gaxOpts 
 : 
  
 CallOptions 
 , 
  
 callback 
 : 
  
 DetachSubscriptionCallback 
 ) 
 : 
  
 void 
 ; 
 
Parameters
Name Description
name string
gaxOpts CallOptions
callback DetachSubscriptionCallback
Returns
Type Description
void

determineBaseUrl_()

  determineBaseUrl_ 
 () 
 : 
  
 void 
 ; 
 

Determine the appropriate endpoint to use for API requests, first trying the apiEndpoint parameter. If that isn't set, we try the Pub/Sub emulator environment variable (PUBSUB_EMULATOR_HOST). If that is also null, we try the standard gcloud alpha pubsub environment variable (CLOUDSDK_API_ENDPOINT_OVERRIDES_PUBSUB). Otherwise the default production API is used.

Note that if the URL doesn't end in '.googleapis.com', we will assume that it's an emulator and disable strict SSL checks.

Returns
Type Description
void

formatName_(name)

  static 
  
 formatName_ 
 ( 
 name 
 : 
  
 string 
 ) 
 : 
  
 string 
 ; 
 
Parameter
Name Description
name string
Returns
Type Description
string

getClient_(config, callback)

  getClient_ 
 ( 
 config 
 : 
  
 GetClientConfig 
 , 
  
 callback 
 : 
  
 GetClientCallback 
 ) 
 : 
  
 void 
 ; 
 

Get the PubSub client object.

Parameters
Name Description
config GetClientConfig

Configuration object.

callback GetClientCallback

The callback function.

Returns
Type Description
void

getClientAsync_(config)

  getClientAsync_ 
 ( 
 config 
 : 
  
 GetClientConfig 
 ) 
 : 
  
 Promise<gax 
 . 
 ClientStub 
> ; 
 

Get the PubSub client object.

Parameter
Name Description
config GetClientConfig

Configuration object.

Returns
Type Description
Promise <gax. ClientStub >

{Promise}

getClientConfig()

  getClientConfig 
 () 
 : 
  
 Promise<ClientConfig> 
 ; 
 

Retrieve a client configuration, suitable for passing into a GAPIC 'v1' class constructor. This will fill out projectId, emulator URLs, and so forth.

Returns
Type Description
Promise < ClientConfig >

{Promise

getSchemaClient_()

  getSchemaClient_ 
 () 
 : 
  
 Promise<SchemaServiceClient> 
 ; 
 

Gets a schema client, creating one if needed.

Returns
Type Description
Promise < SchemaServiceClient >

getSnapshots(options)

  getSnapshots 
 ( 
 options 
 ?: 
  
 PageOptions 
 ) 
 : 
  
 Promise<GetSnapshotsResponse> 
 ; 
 
Parameter
Name Description
options PageOptions
Returns
Type Description
Promise < GetSnapshotsResponse >

getSnapshots(callback)

  getSnapshots 
 ( 
 callback 
 : 
  
 GetSnapshotsCallback 
 ) 
 : 
  
 void 
 ; 
 
Parameter
Name Description
callback GetSnapshotsCallback
Returns
Type Description
void

getSnapshots(options, callback)

  getSnapshots 
 ( 
 options 
 : 
  
 PageOptions 
 , 
  
 callback 
 : 
  
 GetSnapshotsCallback 
 ) 
 : 
  
 void 
 ; 
 
Parameters
Name Description
options PageOptions
callback GetSnapshotsCallback
Returns
Type Description
void

getSubscriptions(options)

  getSubscriptions 
 ( 
 options 
 ?: 
  
 GetSubscriptionsOptions 
 ) 
 : 
  
 Promise<GetSubscriptionsResponse> 
 ; 
 
Parameter
Name Description
options GetSubscriptionsOptions
Returns
Type Description
Promise < GetSubscriptionsResponse >

getSubscriptions(callback)

  getSubscriptions 
 ( 
 callback 
 : 
  
 GetSubscriptionsCallback 
 ) 
 : 
  
 void 
 ; 
 
Parameter
Name Description
callback GetSubscriptionsCallback
Returns
Type Description
void

getSubscriptions(options, callback)

  getSubscriptions 
 ( 
 options 
 : 
  
 GetSubscriptionsOptions 
 , 
  
 callback 
 : 
  
 GetSubscriptionsCallback 
 ) 
 : 
  
 void 
 ; 
 
Parameters
Name Description
options GetSubscriptionsOptions
callback GetSubscriptionsCallback
Returns
Type Description
void

getTopics(options)

  getTopics 
 ( 
 options 
 ?: 
  
 PageOptions 
 ) 
 : 
  
 Promise<GetTopicsResponse> 
 ; 
 
Parameter
Name Description
options PageOptions
Returns
Type Description
Promise < GetTopicsResponse >

getTopics(callback)

  getTopics 
 ( 
 callback 
 : 
  
 GetTopicsCallback 
 ) 
 : 
  
 void 
 ; 
 
Parameter
Name Description
callback GetTopicsCallback
Returns
Type Description
void

getTopics(options, callback)

  getTopics 
 ( 
 options 
 : 
  
 PageOptions 
 , 
  
 callback 
 : 
  
 GetTopicsCallback 
 ) 
 : 
  
 void 
 ; 
 
Parameters
Name Description
options PageOptions
callback GetTopicsCallback
Returns
Type Description
void

listSchemas(view, options)

  listSchemas 
 ( 
 view 
 ?: 
  
 SchemaView 
 , 
  
 options 
 ?: 
  
 CallOptions 
 ) 
 : 
  
 AsyncIterable<google 
 . 
 pubsub 
 . 
 v1 
 . 
 ISchema 
> ; 
 

Get a list of schemas associated with your project.

The returned AsyncIterable will resolve to objects.

This method returns an async iterable. These objects can be adapted to work in a Promise/then framework, as well as with callbacks, but this discussion is considered out of scope for these docs.

[Schemas: list API Documentation] https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.schemas/list [More about async iterators] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of

Parameters
Name Description
view SchemaView

The type of schema objects requested, which should be an enum value from SchemaViews . Defaults to Full.

options CallOptions

Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html .

Returns
Type Description
AsyncIterable < google.pubsub.v1.ISchema >

{AsyncIterable

request(config, callback)

  request<T 
 , 
  
 R 
  
 = 
  
 void 
> ( 
 config 
 : 
  
 RequestConfig 
 , 
  
 callback 
 : 
  
 RequestCallback<T 
 , 
  
 R 
> ) 
 : 
  
 void 
 ; 
 

Funnel all API requests through this method, to be sure we have a project ID.

Parameters
Name Description
config RequestConfig

Configuration object.

callback RequestCallback <T, R>

The callback function.

Returns
Type Description
void
Type Parameters
Name Description
T
R

schema(idOrName)

  schema 
 ( 
 idOrName 
 : 
  
 string 
 ) 
 : 
  
 Schema 
 ; 
 

Create a Schema object, representing a schema within the project. See or to create a schema.

Parameter
Name Description
idOrName string
Returns
Type Description
Schema

{Schema} A Schema instance.

snapshot(name)

  snapshot 
 ( 
 name 
 : 
  
 string 
 ) 
 : 
  
 Snapshot 
 ; 
 

Create a Snapshot object. See to create a snapshot.

Parameter
Name Description
name string

The name of the snapshot.

Returns
Type Description
Snapshot

{Snapshot} A Snapshot instance.

subscription(name, options)

  subscription 
 ( 
 name 
 : 
  
 string 
 , 
  
 options 
 ?: 
  
 SubscriptionOptions 
 ) 
 : 
  
 Subscription 
 ; 
 

Create a Subscription object. This command by itself will not run any API requests. You will receive a Subscription object, which will allow you to interact with a subscription.

Parameters
Name Description
name string

Name of the subscription.

options SubscriptionOptions

Configuration object.

Returns
Type Description
Subscription

{Subscription} A Subscription instance.

topic(name, options)

  topic 
 ( 
 name 
 : 
  
 string 
 , 
  
 options 
 ?: 
  
 PublishOptions 
 ) 
 : 
  
 Topic 
 ; 
 

Create a Topic object. See to create a topic.

Parameters
Name Description
name string

The name of the topic.

options PublishOptions

Publisher configuration object.

Returns
Type Description
Topic

{Topic} A Topic instance.

validateSchema(schema, gaxOpts)

  validateSchema 
 ( 
 schema 
 : 
  
 ISchema 
 , 
  
 gaxOpts 
 ?: 
  
 CallOptions 
 ) 
 : 
  
 Promise<void> 
 ; 
 

Validate a schema definition.

[Schemas: validateSchema API Documentation] https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.schemas/validate

Parameters
Name Description
schema ISchema

The schema definition you wish to validate.

gaxOpts CallOptions
Returns
Type Description
Promise <void>

{Promise

Create a Mobile Website
View Site in Mobile | Classic
Share by: