Using Google Cloud Platform (GCP) Pub/Sub
TIP
Wolverine.Pubsub is able to support inline, buffered, or durable endpoints.
Wolverine supports GCP Pub/Sub as a messaging transport through the WolverineFx.Pubsub package.
Connecting to the Broker
After referencing the Nuget package, the next step to using GCP Pub/Sub within your Wolverine application is to connect to the service broker using the UsePubsub() extension method.
If you are running on Google Cloud or with Application Default Credentials (ADC), you just need to supply your GCP project id:
var host = await Host.CreateDefaultBuilder()
.UseWolverine(opts =>
{
opts.UsePubsub("your-project-id")
// Let Wolverine create missing topics and subscriptions as necessary
.AutoProvision()
// Optionally purge all subscriptions on application startup.
// Warning though, this is potentially slow
.AutoPurgeOnStartup();
}).StartAsync();If you'd like to connect to a GCP Pub/Sub emulator running on your development box, you set emulator detection throught this helper:
var host = await Host.CreateDefaultBuilder()
.UseWolverine(opts =>
{
opts.UsePubsub("your-project-id")
// Tries to use GCP Pub/Sub emulator, as it defaults
// to EmulatorDetection.EmulatorOrProduction. But you can
// supply your own, like EmulatorDetection.EmulatorOnly
.UseEmulatorDetection();
}).StartAsync();Request/Reply
Request/reply mechanics (IMessageBus.InvokeAsync<T>()) are possible with the GCP Pub/Sub transport if Wolverine has the ability to auto-provision a specific response topic and subscription for each node. That topic and subscription would be named like wlvrn.response.[application node id] if you happen to notice that in your GCP Pub/Sub.
Enable System Endpoints
If your application has permissions to create topics and subscriptions in GCP Pub/Sub, you can enable system endpoints and opt in to the request/reply mechanics mentioned above.
var host = await Host.CreateDefaultBuilder()
.UseWolverine(opts =>
{
opts.UsePubsub("your-project-id")
.EnableSystemEndpoints();
}).StartAsync();Identifier Prefixing for Shared Environments
When sharing a single GCP project between multiple developers or development environments, you can use PrefixIdentifiers() to automatically prepend a prefix to every topic and subscription name created by Wolverine. This helps isolate the cloud resources for each developer or environment:
using var host = await Host.CreateDefaultBuilder()
.UseWolverine(opts =>
{
opts.UsePubsub("your-project-id")
.AutoProvision()
// Prefix all topic and subscription names with "dev-john."
.PrefixIdentifiers("dev-john");
// A topic named "orders" becomes "dev-john.orders"
opts.ListenToPubsubTopic("orders");
}).StartAsync();You can also use PrefixIdentifiersWithMachineName() as a convenience to use the current machine name as the prefix:
opts.UsePubsub("your-project-id")
.AutoProvision()
.PrefixIdentifiersWithMachineName();The default delimiter between the prefix and the original name is . for GCP Pub/Sub (e.g., dev-john.orders).

