我已经设法创建了一个c#工具来推送消息到谷歌云pubsub。我似乎找不到任何地方如何将消息推送给模拟器。从我所读到的以下内容应该通过传递端点到ClientCreationSettings来工作。但我从模拟器得到的请求响应很差......
public static async Task PublishMessage()
{
var endpoint = new ServiceEndpoint("localhost", 8085);
ClientCreationSettings clientSettings = new ClientCreationSettings(1, null, null, endpoint);
string message = "hello world";
publisherClient = await PublisherClient.CreateAsync(new TopicName("project1", "topic1"), clientSettings);
await publisherClient.PublishAsync(message);
await publisherClient.ShutdownAsync(TimeSpan.FromSeconds(15));
}
感谢任何见解
对于C#,在启动仿真器后,用 gcloud beta emulators pubsub start --project=PUBSUB_PROJECT_ID [options]
并设置环境变量为 PUBSUB_EMULATOR_HOST
通过一个方便的CLI,如图所示 此处你需要更新你的应用程序代码,如图所示。样品:
string emulatorHostAndPort = Environment.GetEnvironmentVariable("PUBSUB_EMULATOR_HOST");
PublisherServiceApiClient client = new PublisherServiceApiClientBuilder
{
Endpoint = emulatorHostAndPort,
ChannelCredentials = ChannelCredentials.Insecure
}.Build();
// do things using client..