我正在尝试使用Google云端Pub / Sub模拟器来测试我的scala应用。 Documentation说明以下内容 -
运行env-init命令以确定和设置模拟器使用的环境变量。请注意,按照这些说明操作后,代码中的Google Cloud Pub / Sub客户端库会调用在本地实例中运行的API,而不是生产API。
但是当我发布消息或创建主题时,它会在云中执行,而不是在我的本地模拟器上执行。我已确认使用打印println(s"ENV: ${sys.env("PUBSUB_EMULATOR_HOST")}")
的{{1}}正确设置了环境变量。
我尝试强制库使用我的本地设置,如下所示
ENV: localhost:8085
这样我成功向本地设置发送请求,但会导致以下错误 -
val settings = TopicAdminSettings.defaultBuilder()
.setChannelProvider(InstantiatingChannelProvider.newBuilder()
.setEndpoint("localhost:8085")
.setCredentialsProvider(TopicAdminSettings.defaultCredentialsProviderBuilder().build())
.build())
.build()
val topicAdminClient = TopicAdminClient.create(settings)
topicAdminClient.createTopic(topicName)
我按如下方式启动了模拟器 -
[pubsub] 6 14, 2017 2:49:11 午後 io.gapi.emulators.grpc.GrpcServer$3 operationComplete
[pubsub] INFO: Adding handler(s) to newly registered Channel.
[pubsub] 6 14, 2017 2:49:11 午後io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
[pubsub] INFO: Detected non-HTTP/2 connection.
[pubsub] 6 14, 2017 2:49:11 午後 io.gapi.emulators.netty.NotFoundHandler handleRequest
[pubsub] INFO: Unknown request URI: /bad-request
[pubsub] 6 14, 2017 2:49:35 午後 io.gapi.emulators.grpc.GrpcServer$3 operationComplete
[pubsub] INFO: Adding handler(s) to newly registered Channel.
[pubsub] 6 14, 2017 2:49:35 午後 io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
[pubsub] INFO: Detected non-HTTP/2 connection.
[pubsub] 6 14, 2017 2:49:35 午後 io.gapi.emulators.netty.NotFoundHandler handleRequest
[pubsub] INFO: Unknown request URI: /bad-request