1

我尝试在本地运行 pubsub 模拟器,并使用我在 pubsub 上运行的现有服务向它发送消息。没有收到消息,我得到的只是日志中的身份验证错误。

[pubsub] Jan 22, 2017 3:43:16 PM com.google.cloud.iam.testing.v1.shared.authorization.AuthInterceptor interceptCall
[pubsub] INFO: Authentication interceptor: Header value is null
[pubsub] Jan 22, 2017 3:43:16 PM com.google.cloud.iam.testing.v1.shared.authorization.AuthInterceptor interceptCall
[pubsub] INFO: Authentication interceptor: invalid or missing token

我正在请求从 dotnet 和 nodejs 发布和拉取。

C#

var creds = GoogleCredential.GetApplicationDefaultAsync().Result;
if (creds.IsCreateScopedRequired) {
    creds = creds.CreateScoped(new [] { PubsubService.Scope.Pubsub } );
}

return new PubsubService(
    new BaseClientService.Initializer() {
        HttpClientInitializer = creds,
        ApplicationName = "My Wonderful App"
    }
);

节点

var pubsub = require('@google-cloud/pubsub');

var pubsubClient = pubsub({
  projectId: config.get('GCLOUD_PROJECT')
});
4

2 回答 2

1

我遇到了这个问题。

在研究它时,我发现了以下帖子:“没有任何问题。使用模拟器时,我们不传递任何凭据,这就是日志告诉你的,任何请求都没有提供身份验证标头。” - https://www.bountysource.com/issues/39093553-pubsub-emulator-authinterceptor-question

我的消息在研究该主题时开始发布,因此可能只是延迟。

于 2017-01-29T22:46:03.827 回答
0

标头值 null 是一个红色的麻烦。看起来 dotnet sdk 不像 nodejs sdk 那样尊重环境变量。我与 jskeet 通信,他创建了一个问题来添加文档以显示如何启用模拟器的使用:https ://github.com/GoogleCloudPlatform/google-cloud-dotnet/issues/859

这是我在 C# 中创建 PublisherClient 的方式

private static PublisherClient CreatePublisherClient() {
    var emulatorHostAndPort = Environment.GetEnvironmentVariable("PUBSUB_EMULATOR_HOST");
    if (String.IsNullOrWhiteSpace(emulatorHostAndPort)) {
        return PublisherClient.Create();
    } else {
        var channel = new Channel(emulatorHostAndPort, ChannelCredentials.Insecure);
        return PublisherClient.Create(channel);
    }
}
于 2017-12-14T01:25:47.873 回答