Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

how to set google pub/sub message attribute in react-native?

Kun
Bronze 2
Bronze 2

I want to use multiple subscriptions on one topic using React-Native and NestJs. and I use the 'React-Native-IAP' API.

The reason is that I use the test server and the actual server.

I would like to distinguish each subscription as a value of RTDN's Message.attributes.

To do this, I think that when purchasing the item from React-Native, I should create and send attributes.

But I don't know this.

In summary, I want to create a message.attributes for RTDN in REACT-NATIVE.

Please let me know if my thoughts are wrong.

1 1 793
1 REPLY 1

To use multiple subscriptions on one topic in your React Native and NestJS application, you can follow these steps:

  1. Set up Topics: Create multiple topics in your messaging service (e.g., Firebase Cloud Messaging) to represent different subscriptions. Each topic will correspond to a specific type of subscription.

  2. Subscribe to Topics: In your React Native app, use the 'React-Native-IAP' API to handle in-app purchases and subscriptions. After a user successfully purchases or subscribes to a specific plan, subscribe them to the corresponding topic using the messaging service's API. This step will associate the user with the specific subscription topic.

  3. Receive Notifications: In your NestJS backend, set up the necessary endpoints to receive notifications from the messaging service. When a user receives a notification, the backend can process the message and perform any required actions based on the subscription type.

  4. Extract Subscription Information: In your backend, you can access the received message's attributes (such as RTDN's Message.attributes) to determine the subscription type. The attributes can contain custom metadata or identifiers that distinguish each subscription. Based on this information, you can handle the message accordingly.