Spring Boot Cloud GCP无法连接到本地Google PubSub模拟器
尝试从Spring启动应用程序连接到本地Google PubSub模拟器进行测试.
Trying to connect to local Google PubSub emulator from Spring boot application for tests.
使用以下配置spring.cloud.gcp.pubsub.emulator-host=localhost:8085
Using below config spring.cloud.gcp.pubsub.emulator-host=localhost:8085
在8085上成功在本地启动仿真器,也已设置
PUBSUB_EMULATOR_HOST=localhost:8085
Started emulator in local successfully on 8085, Also have set
PUBSUB_EMULATOR_HOST=localhost:8085
注意:在连接到实际的Google PubSub主题时,一切正常.
Note: While connecting to the actual Google PubSub topic everything just works fine.
- 在
src/test/resources/application.properties
下创建文件
- 在测试application.properties中设置
spring.cloud.gcp.pubsub.emulator-host=localhost:8085
. - 注释您的测试类,以便Spring拾取您的测试application.properties:
- Create a file under
src/test/resources/application.properties
- Set
spring.cloud.gcp.pubsub.emulator-host=localhost:8085
inside the test application.properties. - Annotate your test class so that Spring picks up your test application.properties:
@RunWith(SpringRunner::class)
@SpringBootTest
我创建了一个示例项目,该示例项目显示了如何在测试中将Spring与PubSub仿真器一起使用(这也需要创建主题和订阅):
I created an example project that shows how to use Spring with PubSub emulator in a test (which also requires creating the topic and subscription): https://github.com/nhartner/pubsub-emulator-demo