# Google Cloud Pub/Sub Destination Config Reference

<p><a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/google-pub-sub/" >Google Cloud Pub/Sub</a> is a streaming destination. RudderStack publishes each event as a JSON message to the Pub/Sub topic its name or type maps to, optionally with message attributes copied from the event.</p>
<p>In a Google Cloud Pub/Sub destination spec:</p>
<ul>
<li><code>type: googlepubsub</code></li>
<li><code>definition_version: 1</code></li>
</ul>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="sample-configuration">Sample configuration</h2><div class="rs-code">
  <div class="rs-code__head">yaml<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-yaml" data-lang="yaml">version: rudder/v1
kind: destination
metadata:
  name: pubsub-prod
spec:
  id: pubsub-prod
  display_name: PubSub Production
  type: googlepubsub
  definition_version: 1
  enabled: true
  config:
    project_id: acme-analytics
    credentials: &#39;{{ .PUBSUB_CREDENTIALS }}&#39;

    event_to_topic_map:
      - from: Order Completed
        to: rudder-orders
      - from: identify
        to: rudder-users
      - from: &#34;*&#34;
        to: rudder-events
    event_to_attribute_map:
      - from: Order Completed
        to: order_id
      - from: Order Completed
        to: currency

    connection_mode:
      web: cloud
      cloud: cloud
    consent_management:
      web:
        - provider: oneTrust
          consents:
            - analytics</code></pre></div>
</div>
<p>The above example sends <code>Order Completed</code> and <code>identify</code> events to their own topics, and every other event to <code>rudder-events</code> — see <a href="#topic-mapping" >Topic mapping</a>. <code>credentials</code> is JSON, so its reference is single-quoted — see <a href="#secrets" >Secrets</a>.</p>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="config-keys">Config keys</h2><p><code>config</code> accepts only the keys listed below. The <a href="https://www.rudderstack.com/docs/dev-tools/rudder-cli/destination-types/#config-key-rules" >shared config key rules</a> cover unknown keys, defaults, and immutability.</p>
<!-- end-chunk -->
<!-- begin-chunk -->
<h3 id="connection">Connection</h3><div class="rs-ckeys">
<div class="rs-ckey" id="project_id">
  <div class="rs-ckey__title">
    <p class="rs-ckey__name">project_id</p>Required</div>
  <p class="rs-ckey__field">
    Type:
    <code>string</code>
  </p>
<p class="rs-ckey__field">
  Description:
  ID of the GCP project that holds the topics.
</p>

<div class="rs-ckey__notes">
  <p class="rs-ckey__field">Notes:</p>
  <ul>
<li>At most 100 characters, and must not contain line breaks.</li>
<li>A <code>{{ path || fallback }}</code> template is accepted by <code>validate</code>, but RudderStack connects with the project ID as written, so use a literal.</li>
</ul>

</div>

</div>

<div class="rs-ckey" id="credentials">
  <div class="rs-ckey__title">
    <p class="rs-ckey__name">credentials</p>RequiredSecret</div>
  <p class="rs-ckey__field">
    Type:
    <code>string</code>
  </p>
<p class="rs-ckey__field">
  Description:
  Contents of the JSON key file for a GCP service account with the <strong>Pub/Sub Publisher</strong> role on the topics.
</p>

<div class="rs-ckey__notes">
  <p class="rs-ckey__field">Notes:</p>
  <ul>
<li>Only checked for presence locally. RudderStack accepts only a service account key — any other kind of Google credential fails at delivery.</li>
</ul>

</div>

<div class="rs-ckey__extra">
  <p>Supply it as a <code>{{ .VAR }}</code> reference rather than a literal — see <a href="#secrets" >Secrets</a>.</p>
<p>See <a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/google-pub-sub/#get-started" >Get started</a> for creating the service account and its key.</p>

</div>

</div>

</div>

<!-- end-chunk -->
<!-- begin-chunk -->
<h3 id="topic-mapping">Topic mapping</h3><p>Each event is matched against the <code>from</code> field of both mappings by its event name first, then by its type — <code>track</code>, <code>page</code>, <code>identify</code>, and so on — then by <code>*</code>, which matches every event. Matching ignores case.</p>
<div class="rs-ckeys">
<div class="rs-ckey" id="event_to_topic_map">
  <div class="rs-ckey__title">
    <p class="rs-ckey__name">event_to_topic_map</p></div>
  <p class="rs-ckey__field">
    Type:
    <code>array of objects</code>
  </p>
<p class="rs-ckey__field">
  Description:
  Maps events to the topics RudderStack publishes them to.
</p>

<div class="rs-ckey__notes">
  <p class="rs-ckey__field">Notes:</p>
  <ul>
<li><code>from</code> — an event name, an event type, or <code>*</code>.</li>
<li><code>to</code> — ID of the topic, exactly as it appears in Pub/Sub. Topic IDs are case-sensitive.</li>
<li>Each field is at most 100 characters, and must not contain line breaks.</li>
<li>A <code>{{ path || fallback }}</code> template is accepted by <code>validate</code> in either field, but RudderStack prepares a publisher for each <code>to</code> value as written, so keep <code>to</code> literal.</li>
</ul>

</div>

<div class="rs-ckey__extra">
  <p>Rudder CLI doesn&rsquo;t require this key, but an event that matches no entry isn&rsquo;t delivered. Map <code>*</code> to send everything else to one topic:</p>
<div class="rs-code">
  <div class="rs-code__head">yaml<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-yaml" data-lang="yaml">event_to_topic_map:
  - from: Order Completed
    to: rudder-orders
  - from: &#34;*&#34;
    to: rudder-events</code></pre></div>
</div>
<p>Quote <code>&quot;*&quot;</code> — unquoted, YAML reads it as an alias and the spec fails to parse.</p>
<p>See <a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/google-pub-sub/#how-does-event-mapping-work-with-the-topic-id" >How does event mapping work with the topic ID?</a>.</p>

</div>

</div>

<div class="rs-ckey" id="event_to_attribute_map">
  <div class="rs-ckey__title">
    <p class="rs-ckey__name">event_to_attribute_map</p></div>
  <p class="rs-ckey__field">
    Type:
    <code>array of objects</code>
  </p>
<p class="rs-ckey__field">
  Description:
  Adds message attributes copied from the event. Each entry names a field whose value RudderStack attaches as an attribute.
</p>

<div class="rs-ckey__notes">
  <p class="rs-ckey__field">Notes:</p>
  <ul>
<li><code>from</code> — an event name, an event type, or <code>*</code>, matched as described above. Only one set of entries applies to an event: those for its name, or else its type, or else <code>*</code>.</li>
<li><code>to</code> — path of the field, in dot notation. RudderStack looks it up at the event&rsquo;s root, then in <code>properties</code>, <code>traits</code>, and <code>context.traits</code>. The attribute takes the last segment of the path as its name, so <code>metadata.order_id</code> becomes <code>order_id</code>.</li>
<li>Repeat a <code>from</code> to attach several attributes. A field the event doesn&rsquo;t carry adds no attribute.</li>
<li>Attribute values are strings. A number or boolean is converted, and an object or array is sent as JSON.</li>
<li>Each field is at most 100 characters, and must not contain line breaks. Both accept a <code>{{ path || fallback }}</code> template in place of a literal.</li>
</ul>

</div>

<div class="rs-ckey__extra">
  <div class="rs-code">
  <div class="rs-code__head">yaml<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-yaml" data-lang="yaml">event_to_attribute_map:
  - from: Order Completed
    to: order_id
  - from: Order Completed
    to: metadata.coupon</code></pre></div>
</div>
<p>See <a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/google-pub-sub/#attributes" >Attributes</a>.</p>
</div>

</div>

</div>

<!-- end-chunk -->
<!-- begin-chunk -->
<h3 id="per-source-keys">Per-source keys</h3><p>Both keys are objects keyed by the local source type — the tokens listed under <a href="#source-types" >Source types</a>. A key naming a source type this destination doesn&rsquo;t support fails validation.</p>
<div class="rs-ckeys">
<div class="rs-ckey" id="connection_mode">
  <div class="rs-ckey__title">
    <p class="rs-ckey__name">connection_mode</p></div>
  <p class="rs-ckey__field">
    Type:
    <code>object</code>
  </p>
<p class="rs-ckey__field">
  Description:
  Maps each source type you connect to the mode its events reach Pub/Sub in, using the modes in <a href="#source-types" >Source types</a>.
</p>

<div class="rs-ckey__notes">
  <p class="rs-ckey__field">Notes:</p>
  <ul>
<li>An entry is required for each source type you connect — see <a href="#connect-a-source" >Connect a source</a>.</li>
</ul>

</div>

<div class="rs-ckey__extra">
  <div class="rs-code">
  <div class="rs-code__head">yaml<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-yaml" data-lang="yaml">connection_mode:
  web: cloud
  cloud: cloud</code></pre></div>
</div>

</div>

</div>

<div class="rs-ckey" id="consent_management">
  <div class="rs-ckey__title">
    <p class="rs-ckey__name">consent_management</p></div>
  <p class="rs-ckey__field">
    Type:
    <code>object</code>
  </p>
<p class="rs-ckey__field">
  Description:
  Consent provider configuration per source type. The entry shape, accepted providers, and the rules on <code>resolution_strategy</code> and <code>consents</code> are shared across all destination types — see <a href="https://www.rudderstack.com/docs/dev-tools/rudder-cli/destination-types/#consent-management" >Consent management</a>.
</p>

</div>

</div>

<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="source-types">Source types</h2><p>Google Cloud Pub/Sub accepts events from these source types in the mentioned connection modes:</p>
<table>
  <thead>
      <tr>
          <th>Source type</th>
          <th>Connection mode</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><code>android</code></td>
          <td><code>cloud</code></td>
      </tr>
      <tr>
          <td><code>android_kotlin</code></td>
          <td><code>cloud</code></td>
      </tr>
      <tr>
          <td><code>ios</code></td>
          <td><code>cloud</code></td>
      </tr>
      <tr>
          <td><code>ios_swift</code></td>
          <td><code>cloud</code></td>
      </tr>
      <tr>
          <td><code>web</code></td>
          <td><code>cloud</code></td>
      </tr>
      <tr>
          <td><code>unity</code></td>
          <td><code>cloud</code></td>
      </tr>
      <tr>
          <td><code>react_native</code></td>
          <td><code>cloud</code></td>
      </tr>
      <tr>
          <td><code>flutter</code></td>
          <td><code>cloud</code></td>
      </tr>
      <tr>
          <td><code>cordova</code></td>
          <td><code>cloud</code></td>
      </tr>
      <tr>
          <td><code>cloud</code></td>
          <td><code>cloud</code></td>
      </tr>
      <tr>
          <td><code>warehouse</code></td>
          <td><code>cloud</code></td>
      </tr>
  </tbody>
</table>
<p>Every source type is <code>cloud</code> only — events reach the topics from RudderStack&rsquo;s servers, never in device mode.</p>

<p><code>warehouse</code> is the token a <a href="https://www.rudderstack.com/docs/sources/reverse-etl/" >Reverse ETL source</a> resolves to. Rudder CLI manages the destination’s <code>warehouse</code> entry — if the destination is connected to a Reverse ETL source, set <code>connection_mode.warehouse: cloud</code> in its spec, or <code>apply</code> removes it.</p>
<p>Rudder CLI can also declare the Reverse ETL connection itself, for the types listed under <a href="https://www.rudderstack.com/docs/dev-tools/rudder-cli/yaml-retl-connections/#supported-destinations" >Supported destinations</a> — see <a href="https://www.rudderstack.com/docs/dev-tools/rudder-cli/retl-connections/" >Manage Reverse ETL Connections using Rudder CLI</a>.</p>

<html lang="en">
<blockquote class="info">
  <div class="tip-quote">
    
    <div class="tip-text">The dashboard additionally offers Google Cloud Pub/Sub to AMP and Shopify sources. Rudder CLI doesn&rsquo;t manage those connections, so <code>amp</code> and <code>shopify</code> are invalid here.</div>
  </div>
</blockquote>

</html>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="connect-a-source">Connect a source</h2><p>An event stream connection to this destination is checked against two rules at <code>validate</code> time.</p>
<p><strong>The source&rsquo;s type must be supported.</strong> A source&rsquo;s type resolves to one of the tokens above before the check — a JavaScript source resolves to <code>web</code>, and webhook and server-side SDK sources resolve to <code>cloud</code>. Every type an event stream source can resolve to is supported here, so this check always passes.</p>
<p><strong>The destination config must carry a <code>connection_mode</code> entry for that source type.</strong> This lives on the destination spec, not on the <a href="https://www.rudderstack.com/docs/dev-tools/rudder-cli/yaml-connections/" >connection spec</a>. Without it:</p>
<div class="rs-code">
  <div class="rs-code__head"><button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-text" data-lang="text">destination &#39;pubsub-prod&#39; config has no &#39;connection_mode&#39; entry for source type &#39;web&#39;</code></pre></div>
</div>
<p>Google Cloud Pub/Sub needs no additional config keys to connect a source of any type.</p>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="secrets">Secrets</h2><p><code>credentials</code> is the only secret key. Write it as a <code>{{ .VAR }}</code> reference and supply the value at apply time:</p>
<div class="rs-code">
  <div class="rs-code__head">yaml<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-yaml" data-lang="yaml">config:
  credentials: &#39;{{ .PUBSUB_CREDENTIALS }}&#39;</code></pre></div>
</div>
<div class="rs-code">
  <div class="rs-code__head">bash<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-bash" data-lang="bash">export RUDDER_PUBSUB_CREDENTIALS=&#34;$(cat service-account.json)&#34;
rudder-cli apply

# or
rudder-cli apply --var-file secrets.vars.yaml</code></pre></div>
</div>
<p>Note that:</p>
<ul>
<li><code>credentials</code> is JSON, so write its reference in single quotes, as above. Rudder CLI pastes the value into the YAML before parsing it, and the JSON&rsquo;s double quotes would end a double-quoted string.</li>
<li><code>rudder-cli import</code> writes only the secrets the API returns, as <code>{{ .VAR }}</code> references, and leaves the others out. Add any secret key it leaves out, then supply the variables before you apply — see <a href="https://www.rudderstack.com/docs/dev-tools/rudder-cli/destination-types/#secrets" >Secrets</a>.</li>
</ul>
<p>See <a href="https://www.rudderstack.com/docs/dev-tools/rudder-cli/variable-substitution/" >How to Use Variable Substitution in Rudder CLI</a>.</p>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="changes-by-release">Changes by release</h2>
<p>No changes since this type became available.</p>
<p>For changes across every destination type, see <a href="https://www.rudderstack.com/docs/dev-tools/rudder-cli/destination-types/changes/" >Destination Type Changes by Release</a>.</p>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="see-more">See more</h2><ul>
<li><a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/google-pub-sub/" >Google Pub/Sub Destination</a> for service account setup, topic mapping, and attributes</li>
<li><a href="https://www.rudderstack.com/docs/dev-tools/rudder-cli/destination-types/" >Destination Type Reference for Rudder CLI</a> for the rules shared across destination types</li>
<li><a href="https://www.rudderstack.com/docs/dev-tools/rudder-cli/yaml-destinations/" >Destination YAML Reference</a> for the spec envelope</li>
</ul>

