Spring Boot Cloud GCP无法连接到本地Google PubSub模拟器 [英] Spring Boot cloud GCP cannot connect to local Google PubSub emulator

查看:247
本文介绍了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.

推荐答案

  1. src/test/resources/application.properties
  2. 下创建文件
  3. 在测试application.properties中设置spring.cloud.gcp.pubsub.emulator-host=localhost:8085.
  4. 注释您的测试类,以便Spring拾取您的测试application.properties:
  1. Create a file under src/test/resources/application.properties
  2. Set spring.cloud.gcp.pubsub.emulator-host=localhost:8085 inside the test application.properties.
  3. 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

这篇关于Spring Boot Cloud GCP无法连接到本地Google PubSub模拟器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆