import{_ as i,c as a,a2 as t,o as e}from"./chunks/framework.DCdOmWbM.js";const d=JSON.parse('{"title":"Using Google Cloud Platform (GCP) Pub/Sub","description":"","frontmatter":{},"headers":[],"relativePath":"guide/messaging/transports/gcp-pubsub/index.md","filePath":"guide/messaging/transports/gcp-pubsub/index.md","lastUpdated":1730067567000}'),n={name:"guide/messaging/transports/gcp-pubsub/index.md"};function p(l,s,h,r,o,k){return e(),a("div",null,s[0]||(s[0]=[t(`<h1 id="using-google-cloud-platform-gcp-pub-sub" tabindex="-1">Using Google Cloud Platform (GCP) Pub/Sub <a class="header-anchor" href="#using-google-cloud-platform-gcp-pub-sub" aria-label="Permalink to &quot;Using Google Cloud Platform (GCP) Pub/Sub&quot;">​</a></h1><div class="tip custom-block"><p class="custom-block-title">TIP</p><p>Wolverine.Pubsub is able to support inline, buffered, or durable endpoints.</p></div><p>Wolverine supports <a href="https://cloud.google.com/pubsub" target="_blank" rel="noreferrer">GCP Pub/Sub</a> as a messaging transport through the WolverineFx.Pubsub package.</p><h2 id="connecting-to-the-broker" tabindex="-1">Connecting to the Broker <a class="header-anchor" href="#connecting-to-the-broker" aria-label="Permalink to &quot;Connecting to the Broker&quot;">​</a></h2><p>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 <code>UsePubsub()</code> extension method.</p><p>If you are running on Google Cloud or with Application Default Credentials (ADC), you just need to supply <a href="https://support.google.com/googleapi/answer/7014113" target="_blank" rel="noreferrer">your GCP project id</a>:</p><p><a id="snippet-sample_basic_setup_to_pubsub"></a></p><div class="language-cs vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">cs</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">var</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> host</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> await</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Host.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">CreateDefaultBuilder</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">()</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    .</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">UseWolverine</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">opts</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">        opts.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">UsePubsub</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;your-project-id&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">            // Let Wolverine create missing topics and subscriptions as necessary</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">            .</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">AutoProvision</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">()</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">            // Optionally purge all subscriptions on application startup.</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">            // Warning though, this is potentially slow</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">            .</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">AutoPurgeOnStartup</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">();</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    }).</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">StartAsync</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">();</span></span></code></pre></div><p><sup><a href="https://github.com/JasperFx/wolverine/blob/main/src/Transports/GCP/Wolverine.Pubsub.Tests/DocumentationSamples.cs#L15-L30" title="Snippet source file">snippet source</a> | <a href="#snippet-sample_basic_setup_to_pubsub" title="Start of snippet">anchor</a></sup></p><p>If you&#39;d like to connect to a GCP Pub/Sub emulator running on your development box, you set emulator detection throught this helper:</p><p><a id="snippet-sample_connect_to_pubsub_emulator"></a></p><div class="language-cs vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">cs</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">var</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> host</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> await</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Host.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">CreateDefaultBuilder</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">()</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    .</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">UseWolverine</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">opts</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">        opts.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">UsePubsub</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;your-project-id&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">            // Tries to use GCP Pub/Sub emulator, as it defaults</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">            // to EmulatorDetection.EmulatorOrProduction. But you can</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">            // supply your own, like EmulatorDetection.EmulatorOnly</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">            .</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">UseEmulatorDetection</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">();</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    }).</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">StartAsync</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">();</span></span></code></pre></div><p><sup><a href="https://github.com/JasperFx/wolverine/blob/main/src/Transports/GCP/Wolverine.Pubsub.Tests/DocumentationSamples.cs#L35-L48" title="Snippet source file">snippet source</a> | <a href="#snippet-sample_connect_to_pubsub_emulator" title="Start of snippet">anchor</a></sup></p><h2 id="request-reply" tabindex="-1">Request/Reply <a class="header-anchor" href="#request-reply" aria-label="Permalink to &quot;Request/Reply&quot;">​</a></h2><p><a href="https://www.enterpriseintegrationpatterns.com/patterns/messaging/RequestReply.html" target="_blank" rel="noreferrer">Request/reply</a> mechanics (<code>IMessageBus.InvokeAsync&lt;T&gt;()</code>) are possible with the GCP Pub/Sub transport <em>if</em> Wolverine has the ability to auto-provision a specific response topic and subscription for each node. That topic and subscription would be named like <code>wlvrn.response.[application node id]</code> if you happen to notice that in your GCP Pub/Sub.</p><h3 id="enable-system-endpoints" tabindex="-1">Enable System Endpoints <a class="header-anchor" href="#enable-system-endpoints" aria-label="Permalink to &quot;Enable System Endpoints&quot;">​</a></h3><p>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.</p><p><a id="snippet-sample_enable_system_endpoints_in_pubsub"></a></p><div class="language-cs vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">cs</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">var</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> host</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> await</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> Host.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">CreateDefaultBuilder</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">()</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    .</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">UseWolverine</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">opts</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =&gt;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    {</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">        opts.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">UsePubsub</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;your-project-id&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">            .</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">EnableSystemEndpoints</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">();</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    }).</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">StartAsync</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">();</span></span></code></pre></div><p><sup><a href="https://github.com/JasperFx/wolverine/blob/main/src/Transports/GCP/Wolverine.Pubsub.Tests/DocumentationSamples.cs#L53-L62" title="Snippet source file">snippet source</a> | <a href="#snippet-sample_enable_system_endpoints_in_pubsub" title="Start of snippet">anchor</a></sup></p>`,20)]))}const c=i(n,[["render",p]]);export{d as __pageData,c as default};
