Stream sharing with Pub/Sub
You can share Pub/Sub topics through BigQuery sharing to curateand distribute a library of streaming data across multiple internal and externalorganizational boundaries. Real-time streaming data is shared usingBigQuery sharing exchanges and listings, allowing you to logicallycategorize and group large sets of Pub/Sub topics and provision accessat scale.
You can share streaming data to do the following:
- Financial services:
- Share rapidly changing instrument prices, quotes, and orders in real-time
- Detect money laundering and payment fraud
- Support trading risk computations
- Retail and consumer packaged goods (CPG):
- Help stores manage inventory in real-time
- Personalize marketing and customer support
- Adjust prices dynamically
- Monitor social media channels
- Optimize physical store layouts
- Healthcare:
- Power predictive algorithms to monitor patients and analyze risk in real time
- Monitor vitals with wearable medical devices
- Automatic acquisition, structuring, storage, and processing of data from patients, healthcare professionals, and facility administration
- Telecommunications:
- Review network health and predict failures
- Discover user behavior patterns to better locate devices and antennas
Required roles
The roles for sharing Pub/Sub topics are analogous to sharing BigQuery datasets:
- Administrator: a user that manages permissions, visibility, and membership ofexchanges and listings. This role is analogous to theAnalytics Hub Admin(
roles/analyticshub.admin)IAM role. - Shared topic publisher: a user that creates, manages, and grantsaccess to listings of the shared Pub/Sub topics. This role is analogousto theAnalytics Hub Publisher or Analytics Hub Listing AdminIAM role. The publisher referred to here is a user and not thepublisher applicationthat creates and sends the messages to the topic.
- Shared topic subscriber: a user that subscribes to the shared topiclisting. Shared topic subscribers can configure how topic messages will bedelivered. This role is analogous to theAnalytics Hub SubscriberorAnalytics Hub Subscription OwnerIAM role. Depending on how the message data is delivered,additional permissions may be required, such asPub/Sub service account permissionsfor writing messages to BigQuery.
Architecture
The following diagram describes how publishers and subscribers ofPub/Sub resources interact with BigQuery sharing:
Limitations
Stream sharing with Pub/Sub has the following limitations:
- A shared topic can have a maximum of 10,000 Pub/Sub subscriptions. This limit includes linked Pub/Sub subscriptions and Pub/Sub subscriptions created outside of Sharing, for example, subscriptions created directly from Pub/Sub.
Shared topics are indexed in Data Catalog (deprecated) and Dataplex Universal Catalog, but you cannot filter specifically for its resource type.
Usage metrics are captured and displayed in the Metrics dashboard forshared Pub/Sub topics and subscriptions, but are notavailable in
INFORMATION_SCHEMA.SHARED_DATASET_USAGE.To monitor metrics, seeMonitor Pub/Sub inCloud Monitoring.
These metrics can include the following:
- Publish message count
- Publish requests
- Publish throughput in bytes
- Top 5 subscriptions
- Ingested bytes
- Others
Enable the Analytics Hub API
To enable the Analytics Hub API, do the following:
Console
Go to the API library and enable the Analytics Hub API for your Google Cloud project.
gcloud
Run thegcloud services enablecommand:
gcloud services enable analyticshub.googleapis.com
Enable the Pub/Sub API
Go to the API library and enable the Pub/Sub API for your Google Cloud project.
Shared topic publisher workflows
As a shared topic publisher, you can do the following:
- Add shared topics to an exchange by creating a listing
- Update a listing
- Delete a listing
- Share a listing
- Manage subscriptions to your listing
- Remove subscribers from your listing
Additional publisher permissions
To perform shared topic publisher tasks, you must have theAnalytics Hub Publisher role(roles/analyticshub.publisher) on an exchange or listing. To view all thedata exchangesacross projects in an organization that you have access to, you must have theresourcemanager.organizations.get permission.
In addition, you need thepubsub.topics.setIamPolicy permission on thePub/Sub topic you want to list. To share topics with a schema attached,you must grant BigQuery sharing subscribers thepubsub.schemas.getpermission on the schema attached to the topic. This permission allowsBigQuery sharing subscribers to properly parse messages from thePub/Sub subscription.
Create a listing (to add a shared topic)
To add a shared topic to a listing, select one of the following options:
Console
Go to theSharing (Analytics Hub) page.
A page appears that lists all data exchanges that you can access.
Click the data exchange name in which you want to create the listing.
ClickCreate listing.
On theCreate listing page, select "Pub/Sub Topic" in theResource type drop-down.
Select an existing Pub/Sub topic in theShared topic drop-down, or clickCreate a topic.
On theListing details page, inDisplay name, enter the name of the listing.
Enter the following optional details:
Category: select up to two categories that best represent yourlisting. Shared topic subscribers canfilter listingsbased on these categories.
Data affinity: region(s) used by the shared topic publisher forpublishing the data. This information is useful for shared topic subscribersto minimize or avoid Pub/Sub network egress costs by reading thedata from the same region. For more information about egress costs, seeData transfer costs.
Icon: an icon for your listing. PNG and JPEG file formats aresupported. Icons must have a file size of less than 512 KiB anddimensions of no more than 512 x 512 pixels.
Description: a brief description about your listing. Shared topicsubscribers cansearch for listingsbased on the description.
Public Discoverability: enable public discoverability of your listing inthe BigQuery sharing catalog. You must also set permissions for thelisting. ClickActions of the exchange andSet permissions. Give
allUsersorallAuthenticateduserstheAnalytics Hub Viewer role(roles/analyticshub.viewer). ClickAllow Public Access.Documentation> Markdown: additional information such aslinks to any relevant documentation and any additional information thatcan help shared topic subscribers use your topic.
On theListing contact information page, enter the following optional details:
Primary contact: enter an email or a URL of the primary contact forthe listing.
Request access contact: enter an email or URL of the intake form for shared topic subscribers to contact you.
Provider: expand theProvider section and specify details in thefollowing fields:
- Provider name: the name of the topic provider.
- Provider primary contact: an email or a URL of the topicprovider's primary contact.
Shared topic subscribers can filter listings based on the data providers.
Publisher: expand thePublisher section and specify details inthe following fields:
- Publisher name: the name of the shared topic publisher who'screating the listing.
- Publisher primary contact: an email or a URL of the sharedtopic publisher's primary contact.
Review theListing preview page.
ClickPublish.
API
Use theprojects.locations.dataExchanges.listings.createmethod.
POST https://analyticshub.googleapis.com/v1/projects/PROJECT_ID/location/LOCATION/dataExchanges/DATAEXCHANGE_ID/listings?listingId=LISTING_ID
Replace the following:
PROJECT_ID: the project ID that contains the dataexchange in which you want to create the listing.LOCATION: the location for your data exchange. Formore information about locations thatsupport Sharing, seeSupported regions.DATAEXCHANGE_ID: the data exchange ID.LISTING_ID: the listing ID.
In the body of the request, provide thelisting details.If the request is successful, then the response body contains details of the listing.
For more information about the tasks that you can perform on listings usingAPIs, seeprojects.locations.dataExchanges.listings methods.
Update a listing
To update a listing, select one of the following options:
Console
Go to theSharing (Analytics Hub) page.
Click the data exchange name that contains the listing.
Click the listing that you want to update.
ClickEdit listing.
Modify values in the fields. You can modify all values except the shared topic of the listing.
To save changes, clickPublish.
API
Use theprojects.locations.dataExchanges.listings.patch method.
PATCH https://analyticshub.googleapis.com/v1/projects/PROJECT_ID/location/LOCATION/dataExchanges/DATAEXCHANGE_ID/listings/LISTING_ID?updateMask=UPDATEMASK
Replace the following:
PROJECT_ID: the project ID that contains the dataexchange in which you want to create the listing.LOCATION: the location for your data exchange. Formore information about locations thatsupport Sharing, seeSupported regions.DATAEXCHANGE_ID: the data exchange ID.LISTING_ID: the listing ID.UPDATEMASK: the list of fieldsthat you want to update. For updating multiple values, use a comma-separatedlist.
In the body of the request, specify the updated values.
For more information about the tasks that you can perform on listings usingAPIs, seeprojects.locations.dataExchanges.listings methods.
Delete a listing
Listings with shared Pub/Sub topics cannot be deleted with active subscriptions.Revoke all active subscriptions before attempting to delete a shared topic listing. Once a listing is deleted, you cannot undo it. To delete a listing, select one of the following options:
Console
Go to theSharing (Analytics Hub) page.
Click the data exchange name that contains the listing.
Click the listing that you want to delete.
ClickDelete.
In theDelete listing? dialog, confirm deletion by typingdelete.
ClickDelete.
API
Use theprojects.locations.dataExchanges.listings.delete method.
DELETE https://analyticshub.googleapis.com/v1/projects/PROJECT_ID/location/LOCATION/dataExchanges/DATAEXCHANGE_ID/listings/LISTING_ID
Replace the following:
PROJECT_ID: the project ID that contains the dataexchange in which you want to create the listing.LOCATION: the location for your data exchange. Formore information about locations thatsupport Sharing, seeSupported regions.DATAEXCHANGE_ID: the data exchange ID.LISTING_ID: the listing ID.
For more information about the tasks that you can perform on listings usingAPIs, seeprojects.locations.dataExchanges.listings methods.
Share a listing
If you want to give users access to a private listing, you must set IAM policy for an individual or a group for that listing. For a commercial listing, yourdata exchange must be public. Listings in a public data exchange appears in Sharing for allGoogle Cloud users (allAuthenticatedUsers). To enable users to request access for commercial listings, you must grant users theAnalytics Hub Viewer role(roles/analyticshub.viewer).
To give users access to view or subscribe to your listing, do the following steps:
Go to theSharing (Analytics Hub) page.
Click the data exchange name that contains the listing.
Click the listing for which you want to add shared topic subscribers.
ClickSet permissions.
To add principals, clickAdd principal.
In theNew principals field, add the following details based on the type of listing:
- For a private listing, enter emails of the identity to whom you want to grant access.
- For a public listing, add
allAuthenticatedUsers.
In theSelect a role menu, selectAnalytics Hub, and then based on the type of listing, select one of the following roles:
- For a commercial listing, select theAnalytics Hub Viewer role. Thisrole lets usersview the listing and request access.
- For a private or non-commercial public listing, select theAnalytics Hub Subscriber role. This role lets userssubscribe to your listing.
ClickSave.
For more information, seeAnalytics Hub Subscriber and Viewer roles.
Manage subscriptions
To allow a user to subscribe to a listing with a shared topic, grant them theAnalytics Hub Subscriber(roles/analyticshub.subscriber) andAnalytics Hub Subscription Owner(roles/analyticshub.subscriptionOwner) roles on a specific listing:
Go to theSharing (Analytics Hub) page.
Click the data exchange name that contains the listing for which you want to manage the subscriptions.
Click the listing for which you want to list all shared topic subscribers.
ClickSet permissions.
To add principals, clickAdd principal.
In theNew principals field, enter the usernames or emails of the subscribers that you want to add.
ForSelect a role, selectAnalytics Hub> Analytics Hub Subscriber.
ClickAdd another role.
ForSelect a role, selectAnalytics Hub> Analytics Hub Subscription Owner.
ClickSave.
You can delete and update subscribers at any time by clickingSet Permissions.
Revoke a subscription
To remove a subscription to a shared topic listing from BigQuery sharing, select one of the following options:
Console
To list all shared topic subscribers of a listing, follow theGoogle Cloud console instructions inView all subscriptions.
Click theSubscriptions tab to view all the subscriptions to the dataexchange.
Select the checkbox next to the subscriptions you want to remove, or selectall subscriptions.
In theRevoke subscription? dialog, enter revoke to confirm.
ClickRevoke.
API
To remove a subscription, use theprojects.locations.subscriptions.revokemethod.
POST https://analyticshub.googleapis.com/v1/projects/PROJECT_ID/location/LOCATION/subscriptions/SUBSCRIPTION_ID:revoke
Replace the following:
PROJECT_ID: the project ID of the subscription that youwant to remove.LOCATION: the location of the subscription.SUBSCRIPTION_ID: the ID of the subscription that you want to remove.
By revoking a subscription from BigQuery sharing, a shared topic subscriberno longer receives message data from the shared topic. The Pub/Subsubscription is detached from the shared topic. If a subscription is deleteddirectly from Pub/Sub, the BigQuery sharing subscription willpersist and need to be cleaned up.
Subscriber workflows
As a BigQuery sharing subscriber, you can view and subscribe to a listing.Subscribing to a listing of a shared topic creates one linked Pub/Subsubscription in the subscriber's project. The Pub/Sub subscription will bevisible in the shared topic publisher's project.
Additional subscriber permissions
You must have theAnalytics Hub Subscriber(roles/analyticshub.subscriber) role granted at the project, exchange, or listing-level to perform subscriber tasks.
Subscribe to a shared topic listing
To subscribe to a listing with a shared topic, select one of the following options:
Console
To view a list of listings that you have access to, follow the steps inView listings.
Browse through the listings and click a listing that you want to subscribe to. A dialog containing the details of the listing appears.
ClickSubscribe to open theCreate subscription dialog.
If you don't have the Analytics Hub API enabled in your project, an error message appears with a link to enable the API. ClickEnable Analytics Hub API.
In theCreate subscription dialog, specify the following details:
- Subscription ID: specify the name of the subscription you are creating.
- Delivery type: select the mechanism on how the message data will be delivered.
- Message retention duration: set the message retention duration.
- Expiration period: set when the subscription will expire after inactivity, if ever.
- Acknowledgement deadline: set the acknowledgement deadline time.
- Subscription filter: set filter syntax on messages.
- Exactly once delivery: enable exactly once delivery.
- Message ordering: enable ordering of messages with an order key.
- Dead lettering: enable dead lettering.
- Retry policy: set a retry policy.
For more information about Pub/Sub subscription properties, seesubscription properties.
To save your changes, clickCreate. The linked Pub/Sub subscription is created in your project.
API
Use theprojects.locations.dataExchanges.listings.subscribe method.
POST https://analyticshub.googleapis.com/v1/projects/PROJECT_ID/location/LOCATION/dataExchanges/DATAEXCHANGE_ID/listings/LISTING_ID:subscribe
Replace the following:
PROJECT_ID: the project ID of the listing that youwant to subscribe to.LOCATION: the location for your listing that youwant to subscribe to.DATAEXCHANGE_ID: the data exchange ID of thelisting that you want to subscribe to.LISTING_ID: the listing ID that you want tosubscribe to.
In the body of the request, specify the Pub/Sub subscription where you want to create thelinked Pub/Sub subscription.If successful, the response body is empty.
For more information about Pub/Sub subscriptions, seesubscription overview.
Pricing
There is no additional charge for Pub/Sub topic publishers to list andshare topics through BigQuery sharing. Shared topic publishers are chargedfor the total number of bytes written (publish throughput) to the shared topicand network egress (if applicable). Shared topic subscribers are charged for thetotal number of bytes read (subscribe throughput) from the linked subscription andnetwork egress (if applicable). SeePub/Sub pricingfor additional details.
VPC Service Controls
For shared topics from projects that have VPC Service Controls perimeters, you can set the appropriate ingress and egress rules required to grant access to shared topic publishers and subscribers.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.