Spring boot Spring Boot cloud GCP无法连接到本地Google PubSub仿真器
正在尝试从Spring启动应用程序连接到本地Google PubSub emulator进行测试 使用下面的配置Spring boot Spring Boot cloud GCP无法连接到本地Google PubSub仿真器,spring-boot,google-cloud-pubsub,Spring Boot,Google Cloud Pubsub,正在尝试从Spring启动应用程序连接到本地Google PubSub emulator进行测试 使用下面的配置 spring.cloud.gcp.pubsub.emulator主机=localhost:8085 在8085上成功地在本地启动了emulator,还设置了 PUBSUB\u EMULATOR\u HOST=localhost:8085 注意:当连接到实际的Google PubSub主题时,一切正常。当使用Pub/Sub模拟器时,使用FixedTransportChannelProv
spring.cloud.gcp.pubsub.emulator主机=localhost:8085
在8085上成功地在本地启动了emulator,还设置了
PUBSUB\u EMULATOR\u HOST=localhost:8085
注意:当连接到实际的Google PubSub主题时,一切正常。当使用Pub/Sub模拟器时,使用
FixedTransportChannelProvider
和NoRedentialsProvider
创建发布者
或订户
。这表现在:
src/test/resources/application.properties下创建一个文件
spring.cloud.gcp.pubsub.emulator host=localhost:8085
李>
String hostport = System.getenv("PUBSUB_EMULATOR_HOST");
ManagedChannel channel = ManagedChannelBuilder.forTarget(hostport).usePlaintext(true).build();
TransportChannelProvider channelProvider = FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel));
CredentialsProvider credentialsProvider = NoCredentialsProvider.create();
ProjectTopicName topicName = ...
// Use the channel and credentials provider when creating a Publisher or Subscriber.
Publisher publisher =
Publisher.newBuilder(topicName)
.setChannelProvider(channelProvider)
.setCredentialsProvider(credentialsProvider)
.build();
@RunWith(SpringRunner::class)
@SpringBootTest