Skip to content

The search box in the website knows all the secrets—try it!

For any queries, join our Discord Channel to reach us faster.

JasperFx Logo

JasperFx provides formal support for Wolverine and other JasperFx libraries. Please check our Support Plans for more details.

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:

cs
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();

snippet source | anchor

If you'd like to connect to a GCP Pub/Sub emulator running on your development box, you set emulator detection throught this helper:

cs
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();

snippet source | anchor

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.

cs
var host = await Host.CreateDefaultBuilder()
    .UseWolverine(opts =>
    {
        opts.UsePubsub("your-project-id")
            .EnableSystemEndpoints();
    }).StartAsync();

snippet source | anchor

Released under the MIT License.