feat(pubsub): named-broker and broker-per-tenant support (GH-3306)#3318
Merged
Conversation
Bring the GCP Pub/Sub transport up to parity with the other transports on
the two established multi-broker features.
Named broker:
- PubsubTransport(string) now sets the transport Protocol (broker name / URI
scheme) instead of ProjectId, so TransportCollection.GetOrCreate<T>(name)
can spin up named brokers via Activator.CreateInstance. ProjectId is set
separately by UsePubsub/AddNamedPubsubBroker. ResourceUri derives from
Protocol so named brokers get scheme {brokerName}://{projectId}/{topic}.
- New AddNamedPubsubBroker + ListenToPubsubTopicOnNamedBroker +
ToPubsubTopicOnNamedBroker.
Broker-per-tenant (project-id-per-tenant, modeled after NATS):
- New PubsubTenant + PubsubClientSet; each tenant builds its own
Publisher/Subscriber client pair in ConnectAsync, seeded from the parent's
credential/emulator hooks. Senders/listeners are parameterized with a
PubsubClientSet so one endpoint per topic can publish/consume over a
different GCP project at runtime, keyed by Envelope.TenantId.
- CreateSender -> TenantedSender with fire-and-forget InlinePubsubSender for
the default fallback + every tenant (GH-2361). BuildListenerAsync ->
CompoundListener with a per-tenant listener wrapped in
ReceiverWithRules([TenantIdRule]). SetupAsync provisions the topology under
each tenant project, preserving per-node subscription naming.
- New PubsubConfiguration.TenantIdBehavior + AddTenant overloads.
Updates the ~25 test call sites of new PubsubTransport("x") to the object
initializer new PubsubTransport { ProjectId = "x" }. Adds named-broker and
per-tenant unit + integration tests (skip-guarded on the emulator) and docs.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
jeremydmiller
marked this pull request as ready for review
July 6, 2026 03:06
This was referenced Jul 9, 2026
Merged
This was referenced Jul 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3306
Brings the GCP Pub/Sub transport (
Wolverine.Pubsub) up to parity with the other transports on the two established multi-broker features. It had neither before.Feature 1 — Named broker
PubsubTransport(string)now sets the transport Protocol (broker name / URI scheme) instead ofProjectId, soTransportCollection.GetOrCreate<T>(name)can spin up named brokers viaActivator.CreateInstance(typeof(PubsubTransport), name.Name).ProjectIdis set separately byUsePubsub/AddNamedPubsubBroker.ResourceUrinow derives fromProtocol, so a named broker's endpoints get scheme{brokerName}://{projectId}/{topic}.AddNamedPubsubBroker(BrokerName, projectId, …),ListenToPubsubTopicOnNamedBroker,ToPubsubTopicOnNamedBroker(mirrors SQS/Kafka).new PubsubTransport("wolverine")were updated to the object initializernew PubsubTransport { ProjectId = "wolverine" }.Feature 2 — Broker-per-tenant (project-id-per-tenant, modeled after NATS)
PubsubTenant+PubsubClientSet: each tenant builds its ownPublisherServiceApiClient/SubscriberServiceApiClientpair inConnectAsync, seeded from the parent's credential/emulator hooks (a tenant only re-points the axes it overrides)._transport.PublisherApiClient/SubscriberApiClient) are parameterized with aPubsubClientSet, so one endpoint per topic can publish/consume over a different GCP project at runtime, keyed byEnvelope.TenantId— the same "swap the client" model NATS uses for its connection.CreateSender→TenantedSenderwith fire-and-forgetInlinePubsubSenderfor the default fallback and every tenant (neverBatchedSender, per the Message is stuck in outbox with multiple tenants and durable messaging #2361 outbox-deletion regression).BuildListenerAsync→CompoundListenerwith a per-tenant listener wrapped inReceiverWithRules([new TenantIdRule(tenant.TenantId)]). Pub/Sub acks inline in the streaming callback, so per-envelope completion never routes back through the compound listener.SetupAsyncprovisions the topic (+ subscription for listeners) under each tenant project, applying the per-node competing-consumer subscription naming once so all projects share the same subscription id.PubsubConfiguration.TenantIdBehavior(TenantedIdBehavior),AddTenant(tenantId, projectId),AddTenant(tenantId, projectId, Action<PubsubTenant>).GCP-specific note
Project-id-per-tenant is the natural isolation axis:
TopicName/SubscriptionNameembed the project id, so the same logical topic under a different project is already a physically distinct GCP resource — "shared by name, isolated by project". Topology is not fragmented per tenant.Tests
Full
Wolverine.Pubsub.Testsgreen: 178 passed, 0 failed, 0 skipped (against the emulator). New coverage:Protocol+ProjectId, endpoint URI scheme == broker name. Integration: round-trips a message published/listened exclusively via...OnNamedBrokeron a second project (wolverine2) on the same emulator.wolverine2and notwolverine; default message →wolverine; inbound message stamped with itsTenantId; auto-provision under the tenant project;TenantIdBehaviorvariants. Integration tests skip-guard when the emulator/Docker is unavailable.Build gate
dotnet build wolverine.slnx -c Release→ 0 errors, 0 warnings.Docs
Added "Multiple / Named Brokers" and "Multi-Tenancy with a Broker Per Tenant" sections to
docs/guide/messaging/transports/gcp-pubsub/index.mdwith compiling snippets inDocumentationSamples.cs.🤖 Generated with Claude Code