and*_*vom 6 emulation google-cloud-pubsub google-cloud-pubsub-emulator
启动 pubsub 模拟器后,我尝试使用 HTTP API 创建主题和订阅。创建主题成功,但我不明白为什么创建订阅失败。我是否做错了什么或者这是工具中的错误?您可以看到以下日志:
$ curl -s -X PUT http://localhost:8085/v1/projects/myproject/topics/mytopic
{
"name": "projects/myproject/topics/mytopic"
}
$ curl -s -X PUT http://localhost:8085/v1/projects/myproject/subscriptions/mysub \
--data '{"topic":"projects/myproject/topics/mytopic"}'
Not Found
Run Code Online (Sandbox Code Playgroud)
在模拟器方面,我看到以下内容:
# create topic logs
[pubsub] Apr 29, 2020 10:37:19 AM io.gapi.emulators.grpc.GrpcServer$3 operationComplete
[pubsub] INFO: Adding handler(s) to newly registered Channel.
[pubsub] Apr 29, 2020 10:37:19 AM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
[pubsub] INFO: Detected non-HTTP/2 connection.
[pubsub] Apr 29, 2020 10:37:19 AM io.gapi.emulators.grpc.GrpcServer$3 operationComplete
[pubsub] INFO: Adding handler(s) to newly registered Channel.
[pubsub] Apr 29, 2020 10:37:19 AM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
[pubsub] INFO: Detected HTTP/2 connection.
# create subscription logs
[pubsub] Apr 29, 2020 10:37:27 AM io.gapi.emulators.grpc.GrpcServer$3 operationComplete
[pubsub] INFO: Adding handler(s) to newly registered Channel.
[pubsub] Apr 29, 2020 10:37:27 AM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
[pubsub] INFO: Detected non-HTTP/2 connection.
[pubsub] Apr 29, 2020 10:37:27 AM io.gapi.emulators.netty.NotFoundHandler handleRequest
[pubsub] INFO: Unknown request URI: /v1/projects/myproject/subscriptions/mysub
Run Code Online (Sandbox Code Playgroud)
即使使用上述命令创建主题(不需要内容类型),为了使用选项发送数据--data '...',您还需要发送内容类型标头。所以下面的命令确实有效:
$ curl -s -X PUT http://localhost:8085/v1/projects/myproject/subscriptions/mysub \
-H 'content-type: application/json' \
--data '{"topic":"projects/myproject/topics/mytopic"}'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3022 次 |
| 最近记录: |