Migrating to v2
We simplified and improved the experience of using PubSub Framework (especially for Typescript users) in v2, that meant changing the way we do a few things.
These are the changes made for 2.0.0 that are breaking or just important to know:
Min node version is v12.22.0#
Minimum supported node version is v12.22.0.
API Changes#
We stopped exporting pubsub internals from the index file, for more details compare the v1 API and v2 API docs.
Configuration Changes#
GOOGLE_CLOUD_PUB_SUB_PROJECT_ID is now GOOGLE_CLOUD_PROJECT#
To follow similar pattern to Google's automatic injected env vars.
Native grpc module support is removed#
The PUBSUBS_USE_GRPC option is removed.
Throws error on no subscriptions found#
If PUBSUB_ROOT_DIR or the CLI arg (--root-dir) is not found or if the directory doesn't have any subscriptions then service will not start and instead exit with error.
Publishing#
Topic Class#
Topic name and project are now static properties:#
- v1 Topic
- v2 Topic
Topic class now accepts generic type arguments#
Rather than the publish method previously.
- v1 Topic
- v2 Topic
Retry Config is now under options field#
- v1 Topic
- v2 Topic
Subscribing#
- Class based subscriptions were already deprecated in v1.10.4 and have been removed. You can only use SubscriberObject to declare subscriptions now.
SubscriberObjectaccepts generic type argument forPayload- This type is also picked up by the
Messageparam and thetoJsonreturns this type
- This type is also picked up by the
Messagewrapper has atoJsonutility now
- v1 Subscription
- v2 Subscription
ackDeadlineSeconds is now ackDeadline#
Previously we supported both options, but now only ackDeadline is accepted.
Typescript Changes#
Since most of the classes/interfaces now accept generics for Payload types, the typescript workflow is considerably better. This is how the you would reuse types across topics/subscriptions: