Send feedback
Class Topic (2.13.0)
Stay organized with collections
Save and categorize content based on your preferences.
Version 2.13.0 keyboard_arrow_down
A Topic object allows you to interact with a Cloud Pub/Sub topic.
Package
@google-cloud/pubsub!
Constructors
(constructor)(pubsub, name, options)
constructor ( pubsub : PubSub , name : string , options ?: PublishOptions );
Constructs a new instance of the Topic
class
Parameters
Name Description pubsub
PubSub
name
string
options
PublishOptions
Properties
getSubscriptionsStream
getSubscriptionsStream : () = > ObjectStream<Subscription> ;
Property Value
iam
Property Value
metadata ?: TopicMetadata ;
Property Value
Type Description TopicMetadata
name
Property Value
parent
Property Value
publisher
Property Value
pubsub
Property Value
request
request : typeof PubSub . prototype . request ;
Property Value
Type Description typeof PubSub#request
Methods
create(gaxOpts)
create ( gaxOpts ?: CallOptions ) : Promise<CreateTopicResponse> ;
Parameter
Name Description gaxOpts
CallOptions
Returns
Type Description Promise <CreateTopicResponse >
create(callback)
create ( callback : CreateTopicCallback ) : void ;
Parameter
Name Description callback
CreateTopicCallback
Returns
create(gaxOpts, callback)
create ( gaxOpts : CallOptions , callback : CreateTopicCallback ) : void ;
Parameters
Name Description gaxOpts
CallOptions
callback
CreateTopicCallback
Returns
createSubscription(name, callback)
createSubscription ( name : string , callback : CreateSubscriptionCallback ) : void ;
Parameters
Name Description name
string
callback
CreateSubscriptionCallback
Returns
createSubscription(name, options)
createSubscription ( name : string , options ?: CreateSubscriptionOptions ) : Promise<CreateSubscriptionResponse> ;
Parameters
Name Description name
string
options
CreateSubscriptionOptions
Returns
Type Description Promise <CreateSubscriptionResponse >
createSubscription(name, options, callback)
createSubscription ( name : string , options : CreateSubscriptionOptions , callback : CreateSubscriptionCallback ) : void ;
Parameters
Name Description name
string
options
CreateSubscriptionOptions
callback
CreateSubscriptionCallback
Returns
delete(callback)
delete ( callback : EmptyCallback ) : void ;
Parameter
Name Description callback
EmptyCallback
Returns
delete(gaxOpts)
delete ( gaxOpts ?: CallOptions ) : Promise<EmptyResponse> ;
Parameter
Name Description gaxOpts
CallOptions
Returns
Type Description Promise <EmptyResponse >
delete(gaxOpts, callback)
delete ( gaxOpts : CallOptions , callback : EmptyCallback ) : void ;
Parameters
Name Description gaxOpts
CallOptions
callback
EmptyCallback
Returns
exists()
exists () : Promise<ExistsResponse> ;
Returns
Type Description Promise <ExistsResponse >
exists(callback)
exists ( callback : ExistsCallback ) : void ;
Parameter
Name Description callback
ExistsCallback
Returns
flush()
Returns
Type Description Promise <void>
flush(callback)
flush ( callback : EmptyCallback ) : void ;
Parameter
Name Description callback
EmptyCallback
Returns
static formatName_ ( projectId : string , name : string ) : string ;
Format the name of a topic. A Topic's full name is in the format of 'projects/{projectId}/topics/{topicName}'.
{string}
Parameters
Name Description projectId
string
name
string
Returns
get(callback)
get ( callback : GetTopicCallback ) : void ;
Parameter
Name Description callback
GetTopicCallback
Returns
get(gaxOpts)
get ( gaxOpts ?: GetTopicOptions ) : Promise<GetTopicResponse> ;
Parameter
Name Description gaxOpts
GetTopicOptions
Returns
Type Description Promise <GetTopicResponse >
get(gaxOpts, callback)
get ( gaxOpts : GetTopicOptions , callback : GetTopicCallback ) : void ;
Parameters
Name Description gaxOpts
GetTopicOptions
callback
GetTopicCallback
Returns
getMetadata ( callback : GetTopicMetadataCallback ) : void ;
Parameter
Name Description callback
GetTopicMetadataCallback
Returns
getMetadata ( gaxOpts : CallOptions , callback : GetTopicMetadataCallback ) : void ;
Parameters
Name Description gaxOpts
CallOptions
callback
GetTopicMetadataCallback
Returns
getMetadata ( gaxOpts ?: CallOptions ) : Promise<GetTopicMetadataResponse> ;
Parameter
Name Description gaxOpts
CallOptions
Returns
Type Description Promise <GetTopicMetadataResponse >
getPublishOptionDefaults()
getPublishOptionDefaults () : PublishOptions ;
Get the default publisher options. These may be modified and passed back into .
Returns
Type Description PublishOptions
getSubscriptions(callback)
getSubscriptions ( callback : GetTopicSubscriptionsCallback ) : void ;
Parameter
Name Description callback
GetTopicSubscriptionsCallback
Returns
getSubscriptions(options, callback)
getSubscriptions ( options : PageOptions , callback : GetTopicSubscriptionsCallback ) : void ;
Parameters
Name Description options
PageOptions
callback
GetTopicSubscriptionsCallback
Returns
getSubscriptions(options)
getSubscriptions ( options ?: PageOptions ) : Promise<GetTopicSubscriptionsResponse> ;
Parameter
Returns
Type Description Promise <GetTopicSubscriptionsResponse >
publish(data, attributes)
publish ( data : Buffer , attributes ?: Attributes ) : Promise<string> ;
Parameters
Returns
Type Description Promise <string>
publish(data, callback)
publish ( data : Buffer , callback : PublishCallback ) : void ;
Parameters
Name Description data
Buffer
callback
PublishCallback
Returns
publish(data, attributes, callback)
publish ( data : Buffer , attributes : Attributes , callback : PublishCallback ) : void ;
Parameters
Name Description data
Buffer
attributes
Attributes
callback
PublishCallback
Returns
publishJSON(json, attributes)
publishJSON ( json : object , attributes ?: Attributes ) : Promise<string> ;
Parameters
Returns
Type Description Promise <string>
publishJSON(json, callback)
publishJSON ( json : object , callback : PublishCallback ) : void ;
Parameters
Name Description json
object
callback
PublishCallback
Returns
publishJSON(json, attributes, callback)
publishJSON ( json : object , attributes : Attributes , callback : PublishCallback ) : void ;
Parameters
Name Description json
object
attributes
Attributes
callback
PublishCallback
Returns
publishMessage(message)
publishMessage ( message : MessageOptions ) : Promise <[ string ]>;
Parameter
Name Description message
MessageOptions
Returns
Type Description Promise <[string]>
publishMessage(message, callback)
publishMessage ( message : MessageOptions , callback : PublishCallback ) : void ;
Parameters
Name Description message
MessageOptions
callback
PublishCallback
Returns
resumePublishing(orderingKey)
resumePublishing ( orderingKey : string ) : void ;
In the event that the client fails to publish an ordered message, all subsequent publish calls using the same ordering key will fail. Calling this method will disregard the publish failure, allowing the supplied ordering key to be used again in the future.
Parameter
Name Description orderingKey
string
The ordering key in question.
Returns
setMetadata ( options : TopicMetadata , gaxOpts ?: CallOptions ) : Promise<SetTopicMetadataResponse> ;
Parameters
Name Description options
TopicMetadata
gaxOpts
CallOptions
Returns
Type Description Promise <SetTopicMetadataResponse >
setMetadata ( options : TopicMetadata , callback : SetTopicMetadataCallback ) : void ;
Parameters
Name Description options
TopicMetadata
callback
SetTopicMetadataCallback
Returns
setMetadata ( options : TopicMetadata , gaxOpts : CallOptions , callback : SetTopicMetadataCallback ) : void ;
Parameters
Name Description options
TopicMetadata
gaxOpts
CallOptions
callback
SetTopicMetadataCallback
Returns
setPublishOptions(options)
setPublishOptions ( options : PublishOptions ) : void ;
Set the publisher options.
Parameter
Name Description options
PublishOptions
The publisher options.
Returns
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 {module:pubsub/subscription} object, which will allow you to interact with a subscription.
Parameters
Name Description name
string
Name of the subscription.
options
SubscriptionOptions
Configuration object. {Subscription}
Returns
Send feedback
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License , and code samples are licensed under the Apache 2.0 License . For details, see the Google Developers Site Policies . Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-03-05 UTC.
Need to tell us more?
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-03-05 UTC."],[],[]]