Publish Pub/Sub messages in a different target Google Cloud Platform (GCP) project

To change the target Google Cloud Platform (GCP) project for publishing messages from a registry to a different GCP project, follow these steps:

  1. Identify your original project (e.g., skysharma-gcp), your target project you want to publish (e.g., skysharma-gcp-2), your Pub/Sub topic (e.g., root), and subscription (e.g., root-sub).

  2. Give your original service account permissions in the target project as per Cloud Pub/Sub Documentation.

    1. Update the subscription policy:

      • Retrieve the current policy (change yours accordingly):

        gcloud pubsub subscriptions get-iam-policy projects/skysharma-gcp-2/subscriptions/root-sub --format json > ~/Temp/subscription_policy.json
      • Edit subscription_policy.json to add your service account with the role roles/pubsub.editor. This gives the original service account access to this subscription in the new project. The updated subscription_policy.json would look like this:

        • { "etag": "BwUjMhCsNvY=", "bindings": [ { "role": "roles/pubsub.admin", "members": [ "user:user-1@gmail.com" ] }, { "role": "roles/pubsub.editor", "members": [ "serviceAccount:skysharma-gcp-svc-acct@skysharma-gcp.iam.gserviceaccount.com" } ] }
      • Apply the updated policy (change yours accordingly):

        gcloud pubsub subscriptions set-iam-policy projects/skysharma-gcp-2/subscriptions/root-sub ~/Temp/subscription_policy.json
    2. Update the topic policy:

      • Retrieve the current policy (change yours accordingly):

         

      • Edit topic_policy.json similar to the subscription policy step to add the bindings item to allow the current service account access to this topic. The updated topic_policy.json would look like this:

      • Apply the updated policy (change yours accordingly):

  3. Have the API keys for your registry ready.

  4. Use the curl command to send a POST request to the changePubSubProject endpoint. This API changes the target project for your Pub/Sub topics.

     

    • Replace {SystemKey} and {Token} with your specific values.

    • If your URL is different (e.g., europe-west1.clearblade.com), adjust accordingly.

  5. Send a test MQTT message from your device into the registry. Verify the message appears in the target project’s Pub/Sub subscription.

Additional notes

  • The capability to change the target project is available as a new API endpoint using your registry API key.

  • Currently, this process has no UI; it's only available via API.

  • To validate, send a test message and check if it appears in the target project.