使用 CLI 启动 PubSub 模拟器gcloud并相应加载环境变量后,gcloudCLI 仍通过我们的 Google 生产帐户进行身份验证。基本上,我们做了:
# Starting the emulator in one shell
gcloud beta emulators pubsub start
# In a different shell
$(gcloud beta emulators pubsub env-init)
gcloud pubsub topics list
Run Code Online (Sandbox Code Playgroud)
不过,我们的制作主题已在此处列出。预期的输出将是一个空列表,因为我们试图列出新启动的 PubSub 模拟器中的主题,该模拟器在启动时不包含任何内容。
我们习惯于使用可cbt识别BIGTABLE_EMULATOR_HOST. 是否可以使用相同类型的工具来管理/检查 PubSub 模拟器资源?看起来只是gcloud不知道*_EMULATOR_HOST变量。
先感谢您,
PS:我们的输出gloud version:
Google Cloud SDK 182.0.0
alpha 2017.09.15
beta 2017.09.15
bigtable
bq 2.0.27
cbt
core 2017.12.01
gcloud
gsutil 4.28
kubectl
pubsub-emulator 2017.09.15
Run Code Online (Sandbox Code Playgroud) google-cloud-platform 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, …Run Code Online (Sandbox Code Playgroud) 更新:存储库链接已移至答案,因为存储库现在已使用下面答案中的代码进行更新。
问题描述
当前代码正在运行,但它使用来自google/cloud-sdk的gcloud beta 模拟器 pubsub进行集成测试。
我需要在maven-surefire-plugin.
<environmentVariables>
<PUBSUB_EMULATOR_HOST>localhost:8085</PUBSUB_EMULATOR_HOST>
</environmentVariables>
Run Code Online (Sandbox Code Playgroud)
如何在 Spring Boot 中完成此操作
根据测试容器 | Gcloud Module,在Spring Boot中与PubSubEmulatorContainer实现集成测试的正确方法是这样的:https: //github.com/saturnism/testcontainers-gcloud-examples/blob/main/springboot/pubsub-example/src/test/java /com/example/springboot/pubsub/PubSubIntegrationTests.java
这将在随机端口上启动容器,这在DynamicPropertyRegistrySpring 中是可能的。看来Micronaut缺少这种可能性。
文档: https: //www.testcontainers.org/modules/gcloud/
我正在寻找在 Micronaut 3.x 中实现的 JUnit5 或 Spock 集成测试的工作示例,该测试使用PubSubEmulatorContainer上述文档中描述的方式。
相关文档:https://micronaut-projects.github.io/micronaut-gcp/latest/guide/#emulator
GitHub 上有一些关于配置的评论TransportChannelProvider。我能够注入一个实例并检查它,但我仍然不知道到底要做什么。
这些是迄今为止最接近的线索: https://github.com/micronaut-projects/micronaut-gcp/issues/257 https://github.com/micronaut-projects/micronaut-gcp/pull/259
每次我重新启动 PubSub 模拟器时,主题/订阅都会消失。目前,我有一个脚本,可以在每次模拟器启动时创建主题和订阅:
这种状态不持续吗?有没有办法持久化状态?
google-cloud-platform google-cloud-pubsub google-cloud-pubsub-emulator
我正在尝试在本地使用 pubsub 运行 firebase 函数。
\n已配置模拟器firebase init emulators。
firebase emulators:start --only pubsub工作正常,我可以看到日志:
\xe2\x94\x8c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xac\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x90\n\xe2\x94\x82 Emulator \xe2\x94\x82 Host:Port \xe2\x94\x82\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xbc\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xa4\n\xe2\x94\x82 Pub/Sub \xe2\x94\x82 localhost:8085 \xe2\x94\x82\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xb4\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x98\nRun Code Online (Sandbox Code Playgroud)\nfirebase.json 中的 pubsub 模拟器配置:
\n"pubsub": {\n "host": "localhost",\n "port": 8085\n},\nRun Code Online (Sandbox Code Playgroud)\n导出 pubsub 处理函数:
\nexports.testPubsub = functions.pubsub.topic("test-pubsub").onPublish(async (message) => {\n console.log(`test event received by pubsub handler: ${message.json}`);\n});\nRun Code Online (Sandbox Code Playgroud)\n我运行 firebase 函数:firebase serve --only functions
此行出现在控制台输出中:
\nfunctions[pubsub-testPubsub]: function ignored because the pubsub emulator does not exist or is …Run Code Online (Sandbox Code Playgroud)