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.0Minimum supported node version is v12.22.0.
#
API ChangesWe stopped exporting pubsub internals from the index file, for more details compare the v1 API and v2 API docs.
#
Configuration ChangesGOOGLE_CLOUD_PUB_SUB_PROJECT_ID
is now GOOGLE_CLOUD_PROJECT
#
To follow similar pattern to Google's automatic injected env vars.
grpc
module support is removed#
Native The PUBSUBS_USE_GRPC
option is removed.
#
Throws error on no subscriptions foundIf 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 Classname
and project
are now static properties:#
Topic - v1 Topic
- v2 Topic
#
Topic class now accepts generic type argumentsRather 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.
SubscriberObject
accepts generic type argument forPayload
- This type is also picked up by the
Message
param and thetoJson
returns this type
- This type is also picked up by the
Message
wrapper has atoJson
utility now
- v1 Subscription
- v2 Subscription
ackDeadlineSeconds
is now ackDeadline
#
Previously we supported both options, but now only ackDeadline
is accepted.
#
Typescript ChangesSince 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: