2017-01-23 43 views
1

我試着在本地運行pubsub模擬器並使用我在pubsub上運行的現有服務向其發送消息。郵件沒有收到,我得到的只是日誌中的auth錯誤。GCloud pubsub模擬器不尊重「PUBSUB_EMULATOR_HOST」環境變量

[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" 
    } 
); 

的NodeJS

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

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

回答

0

頭null值是一個紅色哈林。它看起來像dotnet sdk不像nodejs sdk那樣尊重環境變量。我對應了與jskeet和他所造成的問題,添加文檔顯示如何能夠使用仿真器:https://github.com/GoogleCloudPlatform/google-cloud-dotnet/issues/859

下面是如何創建的PublisherClient在C#

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); 
    } 
}