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

Publish a message with c# not working

I am trying to get the sample C# class to work for publishing a message, but as soon as it hits the 

PublisherClient publisher = await PublisherClient.CreateAsync(topicName);

line the program ends and never publishes the message or executes the lines that follow.

My program code snippet is:

System.Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS",@"C:\xxx..." ); //where xxx is the full path to my local key
PublishMessagesAsyncSample pub = new PublishMessagesAsyncSample();
IEnumerable<string> msg = new string[] { "Hello GoogleLine1", "Hello GoogleLine2", "Hello GoogleLine3" };
Task<int> rc = pub.PublishMessagesAsync("payrolltransformationtest", "my-topic", msg);

Any insights would be appreciated.

Thanks,
David

0 3 1,479
3 REPLIES 3

Hi, dgordon,

Are you following this documentation? If not, what documentation or sample code are you following?

I was using a different sample. I tried your samples in the attached documentation using both the async and regular APIs. 

Both times is was getting errors on Grpc.core.RpcException on the statement:
 publisher.CreateTopic(topicName); or publisherService.CreateTopic(topicName);

Grpc.Core.RpcException: 'Status(StatusCode="Unavailable", Detail="failed to connect to all addresses", DebugException="Grpc.Core.Internal.CoreErrorDetailException: {"created":"@1655062431.124000000","description":"Failed to pick subchannel","file":"..\..\..\src\core\ext\filters\client_channel\client_channel.cc","file_line":3159,"referenced_errors":[{"created":"@1655062431.124000000","description":"failed to connect to all addresses","file":"..\..\..\src\core\lib\transport\error_utils.cc","file_line":147,"grpc_status":14}]}")'

It might be my setting of: System.Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", @"C:\Users\app1dwg\Downloads\payrolltransformationtest-3ce80e663ca0.json");

However, I suspect my problem is because of the way I have my Google network configured. My publish and subscribe work because when I use Google Console, I can create a message and have it read by the subscription.

Any ideas would be welcome.

Thanks,
Davod

Hi, David,

Could you share your project’s Pub/Sub client error logs within the timeframe of the incident?