Spring Boot 发布/订阅订阅者在部署后立即被删除

问题描述 投票:0回答:1

我有一个 spring boot 应用程序部署到谷歌云(通过自动 github 构建)。 不幸的是,我的 pub/sub 订阅者在部署后立即被删除 :( 有人知道原因吗?

Removing {service-activator:investobotAPIs.messageReceiver.serviceActivator} as a subscriber to the 'inputMessageChannel' channel

我在 google pub/sub 和订阅中创建了一个主题:

我添加了这些方法:

@RestController
@EnableAsync
public class InvestobotAPIs {

...
    
// [START pubsub_spring_inbound_channel_adapter]
        // Create a message channel for messages arriving from the subscription `sub-one`.
        @Bean
        public MessageChannel inputMessageChannel() {
            return new PublishSubscribeChannel();
        }
    
    // Create an inbound channel adapter to listen to the subscription `sub-one` and send
    // messages to the input message channel.
    @Bean
    public PubSubInboundChannelAdapter inboundChannelAdapter(
            @Qualifier("inputMessageChannel") MessageChannel messageChannel,
            PubSubTemplate pubSubTemplate) {
        PubSubInboundChannelAdapter adapter =
                new PubSubInboundChannelAdapter(pubSubTemplate, "fetch-gpw-sub");
        adapter.setOutputChannel(messageChannel);
        adapter.setAckMode(AckMode.MANUAL);
        adapter.setPayloadType(String.class);
        return adapter;
    }

    // Define what happens to the messages arriving in the message channel.
    @ServiceActivator(inputChannel = "inputMessageChannel")
    public void messageReceiver(
            String payload,
            @Header(GcpPubSubHeaders.ORIGINAL_MESSAGE) BasicAcknowledgeablePubsubMessage message) {
        logger.info("Message arrived via an inbound channel adapter from fetch-gpw! Payload: " + payload);
        message.ack();
    }
    // [END pubsub_spring_inbound_channel_adapter]

这是我的build.graddle:

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web:2.5.5'
    // get url and download files
    implementation 'commons-io:commons-io:2.6'
    implementation 'org.asynchttpclient:async-http-client:2.12.3'
    // parse xls files
    implementation 'org.apache.poi:poi:5.0.0'
    implementation 'org.apache.poi:poi-ooxml:5.0.0'
    // firebase messaging and db
    implementation 'com.google.firebase:firebase-admin:8.1.0'
    // subscribe pub/sub topic
    implementation 'com.google.cloud:spring-cloud-gcp-starter-pubsub:2.0.4'
    implementation 'com.google.cloud:spring-cloud-gcp-pubsub-stream-binder:2.0.4'
    implementation 'com.google.cloud:spring-cloud-gcp-dependencies:2.0.4'
}

不幸的是,当它被部署时,日志显示部署被删除后:

2021-10-20 11:51:16.190 CEST2021-10-20 09:51:16.190 INFO 1 --- [ main] o.s.i.channel.PublishSubscribeChannel : Channel 'application.inputMessageChannel' has 1 subscriber(s).
Default
2021-10-20 11:51:16.190 CEST2021-10-20 09:51:16.190 INFO 1 --- [ main] o.s.i.endpoint.EventDrivenConsumer : started bean 'investobotAPIs.messageReceiver.serviceActivator'
Default
2021-10-20 11:51:16.214 CEST2021-10-20 09:51:16.214 INFO 1 --- [ main] .g.c.s.p.i.i.PubSubInboundChannelAdapter : started bean 'inboundChannelAdapter'; defined in: 'class path resource [com/miloszdobrowolski/investobotbackend/InvestobotAPIs.class]'; from source: 'com.miloszdobrowolski.investobotbackend.InvestobotAPIs.inboundChannelAdapter(org.springframework.messaging.MessageChannel,com.google.cloud.spring.pubsub.core.PubSubTemplate)'
Default
2021-10-20 11:51:16.295 CEST2021-10-20 09:51:16.294 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
Default
2021-10-20 11:51:19.076 CEST2021-10-20 09:51:19.075 INFO 1 --- [ main] c.m.i.InvestobotBackendApplication : Started InvestobotBackendApplication in 14.475 seconds (JVM running for 19.248)
Info
2021-10-20 11:51:22.386 CESTCloud Runinvestobot-backend-autobuild {@type: type.googleapis.com/google.cloud.audit.AuditLog, resourceName: namespaces/our-shield-329019/services/investobot-backend-autobuild, response: {…}, serviceName: run.googleapis.com, status: {…}}
Debug
2021-10-20 11:51:54.075 CESTContainer Sandbox: Unsupported syscall setsockopt(0x16,0x29,0x31,0x3e96fd1f3a9c,0x4,0x0). It is very likely that you can safely ignore this message and that this is not the cause of any error you might be troubleshooting. Please, refer to https://gvisor.dev/c/linux/amd64/setsockopt for more information.
Debug
2021-10-20 11:51:54.075 CESTContainer Sandbox: Unsupported syscall setsockopt(0x16,0x29,0x12,0x3e96fd1f3a9c,0x4,0x0). It is very likely that you can safely ignore this message and that this is not the cause of any error you might be troubleshooting. Please, refer to https://gvisor.dev/c/linux/amd64/setsockopt for more information.
Default
2021-10-20 11:52:59.196 CEST2021-10-20 09:52:59.195 WARN 1 --- [ault-executor-0] i.g.n.s.i.n.u.internal.MacAddressUtil : Failed to find a usable hardware address from the network interfaces; using random bytes: d1:79:21:a2:71:29:47:49
Default
2021-10-20 11:53:01.010 CEST2021-10-20 09:53:01.010 INFO 1 --- [ionShutdownHook] .g.c.s.p.i.i.PubSubInboundChannelAdapter : stopped bean 'inboundChannelAdapter'; defined in: 'class path resource [com/miloszdobrowolski/investobotbackend/InvestobotAPIs.class]'; from source: 'com.miloszdobrowolski.investobotbackend.InvestobotAPIs.inboundChannelAdapter(org.springframework.messaging.MessageChannel,com.google.cloud.spring.pubsub.core.PubSubTemplate)'
Default
2021-10-20 11:53:01.010 CEST2021-10-20 09:53:01.010 INFO 1 --- [ionShutdownHook] o.s.i.endpoint.EventDrivenConsumer : Removing {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
Default
2021-10-20 11:53:01.010 CEST2021-10-20 09:53:01.010 INFO 1 --- [ionShutdownHook] o.s.i.channel.PublishSubscribeChannel : Channel 'application.errorChannel' has 0 subscriber(s).
Default
2021-10-20 11:53:01.011 CEST2021-10-20 09:53:01.011 INFO 1 --- [ionShutdownHook] o.s.i.endpoint.EventDrivenConsumer : stopped bean '_org.springframework.integration.errorLogger'
Default
2021-10-20 11:53:01.011 CEST2021-10-20 09:53:01.011 INFO 1 --- [ionShutdownHook] o.s.i.endpoint.EventDrivenConsumer : Removing {service-activator:investobotAPIs.messageReceiver.serviceActivator} as a subscriber to the 'inputMessageChannel' channel
Default
2021-10-20 11:53:01.011 CEST2021-10-20 09:53:01.011 INFO 1 --- [ionShutdownHook] o.s.i.channel.PublishSubscribeChannel : Channel 'application.inputMessageChannel' has 0 subscriber(s).
Default
2021-10-20 11:53:01.011 CEST2021-10-20 09:53:01.011 INFO 1 --- [ionShutdownHook] o.s.i.endpoint.EventDrivenConsumer : stopped bean 'investobotAPIs.messageReceiver.serviceActivator'

我尝试将 gradle 中的依赖项从 com.google.cloud 更改为 org.springframework.cloud(不确定它们有何不同)

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web:2.5.5'
    // get url and download files
    implementation 'commons-io:commons-io:2.6'
    implementation 'org.asynchttpclient:async-http-client:2.12.3'
    // parse xls files
    implementation 'org.apache.poi:poi:5.0.0'
    implementation 'org.apache.poi:poi-ooxml:5.0.0'
    // firebase messaging and db
    implementation 'com.google.firebase:firebase-admin:8.1.0'
    // subscribe pub/sub topic
//  implementation 'com.google.cloud:spring-cloud-gcp-starter-pubsub:2.0.4'
//  implementation 'com.google.cloud:spring-cloud-gcp-pubsub-stream-binder:2.0.4'
//  implementation 'com.google.cloud:spring-cloud-gcp-dependencies:2.0.4'
    implementation 'org.springframework.cloud:spring-cloud-gcp-starter-bus-pubsub:1.2.8.RELEASE'
    implementation 'org.springframework.cloud:spring-cloud-gcp-pubsub:1.2.8.RELEASE'
    implementation 'org.springframework.cloud:spring-cloud-gcp-autoconfigure:1.2.8.RELEASE'
    implementation 'org.springframework.integration:spring-integration-core:5.5.4'
}

但它只会在部署期间导致不同的错误: 错误:(gcloud.run.services.update) Cloud Run 错误:容器无法启动。无法启动然后侦听 PORT 环境变量定义的端口。此修订的日志可能包含更多信息。

spring google-cloud-platform deployment environment google-cloud-pubsub
1个回答
0
投票

我看到类似的问题,关于解决这个问题的任何建议。

© www.soinside.com 2019 - 2024. All rights reserved.