Class Snapshot (4.4.0)

A Snapshot object will give you access to your Cloud Pub/Sub snapshot.

Snapshots are sometimes retrieved when using various methods:


Snapshots may be created with:

  • You can use snapshots to seek a subscription to a specific point in time.

-

Package

@google-cloud/pubsub

Example

  //- 
 // From {@link PubSub#getSnapshots}: 
 //- 
 pubsub 
 . 
 getSnapshots 
 (( 
 err 
 , 
  
 snapshots 
 ) 
  
 = 
>  
 { 
  
 // `snapshots` is an array of Snapshot objects. 
 }); 
 //- 
 // From {@link PubSub#getSnapshotsStream}: 
 //- 
 pubsub 
 . 
 getSnapshotsStream 
 () 
  
 . 
 on 
 ( 
 'error' 
 , 
  
 console 
 . 
 error 
 ) 
  
 . 
 on 
 ( 
 'data' 
 , 
  
 ( 
 snapshot 
 ) 
  
 = 
>  
 { 
  
 // `snapshot` is a Snapshot object. 
  
 }); 
 //- 
 // From {@link PubSub#snapshot}: 
 //- 
 const 
  
 snapshot 
  
 = 
  
 pubsub 
 . 
 snapshot 
 ( 
 'my-snapshot' 
 ); 
 // snapshot is a Snapshot object. 
 //- 
 // Create a snapshot with {module:pubsub/subscription#createSnapshot}: 
 //- 
 const 
  
 subscription 
  
 = 
  
 pubsub 
 . 
 subscription 
 ( 
 'my-subscription' 
 ); 
 subscription 
 . 
 createSnapshot 
 ( 
 'my-snapshot' 
 , 
  
 ( 
 err 
 , 
  
 snapshot 
 ) 
  
 = 
>  
 { 
  
 if 
  
 ( 
 ! 
 err 
 ) 
  
 { 
  
 // `snapshot` is a Snapshot object. 
  
 } 
 }); 
 //- 
 // Seek to your snapshot: 
 //- 
 const 
  
 subscription 
  
 = 
  
 pubsub 
 . 
 subscription 
 ( 
 'my-subscription' 
 ); 
 subscription 
 . 
 seek 
 ( 
 'my-snapshot' 
 , 
  
 ( 
 err 
 ) 
  
 = 
>  
 { 
  
 if 
  
 ( 
 err 
 ) 
  
 { 
  
 // Error handling omitted. 
  
 } 
 }); 
 

Constructors

(constructor)(parent, name)

  constructor 
 ( 
 parent 
 : 
  
 Subscription 
  
 | 
  
 PubSub 
 , 
  
 name 
 : 
  
 string 
 ); 
 

Constructs a new instance of the Snapshot class

Parameters
Name
Description
parent
name
string

Properties

  metadata 
 ?: 
  
 google 
 . 
 pubsub 
 . 
 v1 
 . 
 ISnapshot 
 ; 
 

name

  name 
 : 
  
 string 
 ; 
 

parent

  parent 
 : 
  
 Subscription 
  
 | 
  
 PubSub 
 ; 
 

Methods

create(gaxOpts)

  create 
 ( 
 gaxOpts 
 ?: 
  
 CallOptions 
 ) 
 : 
  
 Promise<CreateSnapshotResponse> 
 ; 
 

Create a snapshot with the given name.

**This is only available if you accessed this object through .**

Snapshot#create

Parameter
Name
Description
gaxOpts
CallOptions
Returns
Type
Description
Example
  const 
  
 subscription 
  
 = 
  
 pubsub 
 . 
 subscription 
 ( 
 'my-subscription' 
 ); 
 const 
  
 snapshot 
  
 = 
  
 subscription 
 . 
 snapshot 
 ( 
 'my-snapshot' 
 ); 
 const 
  
 callback 
  
 = 
  
 ( 
 err 
 , 
  
 snapshot 
 , 
  
 apiResponse 
 ) 
  
 = 
>  
 { 
  
 if 
  
 ( 
 ! 
 err 
 ) 
  
 { 
  
 // The snapshot was created successfully. 
  
 } 
 }; 
 snapshot 
 . 
 create 
 ( 
 'my-snapshot' 
 , 
  
 callback 
 ); 
 //- 
 // If the callback is omitted, we'll return a Promise. 
 //- 
 snapshot 
 . 
 create 
 ( 
 'my-snapshot' 
 ). 
 then 
 (( 
 data 
 ) 
  
 = 
>  
 { 
  
 const 
  
 snapshot 
  
 = 
  
 data 
 [ 
 0 
 ]; 
  
 const 
  
 apiResponse 
  
 = 
  
 data 
 [ 
 1 
 ]; 
 }); 
 

create(callback)

  create 
 ( 
 callback 
 : 
  
 CreateSnapshotCallback 
 ) 
 : 
  
 void 
 ; 
 
Parameter
Name
Description
Returns
Type
Description
void

create(gaxOpts, callback)

  create 
 ( 
 gaxOpts 
 : 
  
 CallOptions 
 , 
  
 callback 
 : 
  
 CreateSnapshotCallback 
 ) 
 : 
  
 void 
 ; 
 
Parameters
Name
Description
gaxOpts
CallOptions
Returns
Type
Description
void

delete()

  delete 
 () 
 : 
  
 Promise<EmptyResponse> 
 ; 
 

Delete the snapshot.

Returns
Type
Description
Promise < EmptyResponse >
Example
  snapshot 
 . 
 delete 
 (( 
 err 
 , 
  
 apiResponse 
 ) 
  
 = 
>  
 {}); 
 //- 
 // If the callback is omitted, we'll return a Promise. 
 //- 
 snapshot 
 . 
 delete 
 (). 
 then 
 (( 
 data 
 ) 
  
 = 
>  
 { 
  
 const 
  
 apiResponse 
  
 = 
  
 data 
 [ 
 0 
 ]; 
 }); 
 

delete(callback)

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

formatName_(projectId, name)

  static 
  
 formatName_ 
 ( 
 projectId 
 : 
  
 string 
 , 
  
 name 
 : 
  
 string 
 ) 
 : 
  
 string 
 ; 
 
Parameters
Name
Description
projectId
string
name
string
Returns
Type
Description
string

seek(gaxOpts)

  seek 
 ( 
 gaxOpts 
 ?: 
  
 CallOptions 
 ) 
 : 
  
 Promise<SeekResponse> 
 ; 
 

Seeks an existing subscription to the snapshot.

**This is only available if you accessed this object through .**

Snapshot#seek

Parameter
Name
Description
gaxOpts
CallOptions
Returns
Type
Description
Promise < SeekResponse >
Example
  const 
  
 subscription 
  
 = 
  
 pubsub 
 . 
 subscription 
 ( 
 'my-subscription' 
 ); 
 const 
  
 snapshot 
  
 = 
  
 subscription 
 . 
 snapshot 
 ( 
 'my-snapshot' 
 ); 
 snapshot 
 . 
 seek 
 (( 
 err 
 , 
  
 apiResponse 
 ) 
  
 = 
>  
 {}); 
 //- 
 // If the callback is omitted, we'll return a Promise. 
 //- 
 snapshot 
 . 
 seek 
 (). 
 then 
 (( 
 data 
 ) 
  
 = 
>  
 { 
  
 const 
  
 apiResponse 
  
 = 
  
 data 
 [ 
 0 
 ]; 
 }); 
 

seek(callback)

  seek 
 ( 
 callback 
 : 
  
 SeekCallback 
 ) 
 : 
  
 void 
 ; 
 
Parameter
Name
Description
callback
Returns
Type
Description
void

seek(gaxOpts, callback)

  seek 
 ( 
 gaxOpts 
 : 
  
 CallOptions 
 , 
  
 callback 
 : 
  
 SeekCallback 
 ) 
 : 
  
 void 
 ; 
 
Parameters
Name
Description
gaxOpts
CallOptions
callback
Returns
Type
Description
void
Design a Mobile Site
View Site in Mobile | Classic
Share by: