1
votes

I am trying to create C# desktop application that can receive Google Cloud Platform Pub/Sub message. I can't get it to work with Push approach(https://cloud.google.com/pubsub/docs/subscriber#push_pull). What I understand from documentation - when message is published Pub/Sub pushes HTTP request to the subscriber to an endpoint. Then endpoint sends back HTTP success status code. This is how I create my Subscriber:

        TopicName topicName = new TopicName("test-project-123", "myTopicName");
        SubscriberServiceApiClient subscriberService = await SubscriberServiceApiClient.CreateAsync();
        SubscriptionName subscriptionName = new SubscriptionName("test-project-123", "mySubscriberName");
        subscriberService.CreateSubscription(subscriptionName, topicName, pushConfig: null, ackDeadlineSeconds: 60);

Here, I assume, pushConfig is where I would specify endpoint to which Pub/Sub should send request to which my program in return should send success status code. What I don't understand is how my desktop application will know that request is pushed to this endpoint and how exactly does it have to respond to it? I believe the answer should be simple, but web development is a totally new thing for me so this solution is something I find very difficult to figure out. Any ideas or code samples would be highly appreciated

1

1 Answers

1
votes

To use Push, you would need to set up a service that hosts a URL. It's up to you to figure out how to connect your service to your desktop application. I think the easiest way to set up a service to accept Cloud Pub/Sub Pushes is to use Cloud Run, a GCP service for hosting services: https://cloud.google.com/run/docs/tutorials/pubsub

Another option is to use Cloud Functions to set up a Pub/Sub trigger: https://cloud.google.com/functions/docs/calling/pubsub

or Firebase Functions: https://firebase.google.com/docs/functions/pubsub-events

In general, Cloud Pub/Sub might not be the right tool for delivering notifications to your desktop application. For that, you might want to consider Firebase Cloud Messaging: https://firebase.google.com/docs/cloud-messaging/

It is possible for you to use FCM end-to-end, or you could bridge messages from Cloud Pub/Sub into FCM.