Google Cloud Run pubSub Pull Listener应用程序无法启动 [英] Google Cloud Run pubsub pull listener app fails to start

查看:0
本文介绍了Google Cloud Run pubSub Pull Listener应用程序无法启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下示例Java代码的侦听器部分(SubscribeAsyncExample...略微修改以适应我的SpringBoot应用程序)在Cloud Run上测试pubSub;Pull";订阅者: https://cloud.google.com/pubsub/docs/quickstart-client-libraries#java_1 它在部署期间无法启动……但当它尝试启动时,它确实从pubSub队列中拉出了项目。最初,我在另一个发布订阅主题上有一个HTTP&Push&Quot;Receiver(@RestController),它工作得很好。有什么建议吗?我是Cloud Run的新手。谢谢。

Deploying...
  Creating Revision... Cloud Run error: Container failed to start. Failed to start and then listen on the port defined
  by the PORT environment variable. Logs for this revision might contain more information....failed
Deployment failed
In logs:
2020-08-11 18:43:22.688 INFO 1 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 4606 ms
2020-08-11T18:43:25.287759Z Listening for messages on projects/ce-cxmo-dev/subscriptions/AndySubscriptionPull:
2020-08-11T18:43:25.351650801Z Container Sandbox: Unsupported syscall setsockopt(0x18,0x29,0x31,0x3eca02dfd974,0x4,0x28). 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.
2020-08-11T18:43:25.351770555Z Container Sandbox: Unsupported syscall setsockopt(0x18,0x29,0x12,0x3eca02dfd97c,0x4,0x28). 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.
2020-08-11 18:43:25.680 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: ae:2c:fb:e7:92:9c:2b:24
2020-08-11T18:45:36.282714Z Id: 1421389098497572
2020-08-11T18:45:36.282763Z Data: We be pub-sub'n in pull mode2!!
Nothing else after this and the app stops running.

@Component
public class AndyTopicPullRecv {
  
  public AndyTopicPullRecv() 
  {
    subscribeAsyncExample("ce-cxmo-dev", "AndySubscriptionPull");
  }
  
  public static void subscribeAsyncExample(String projectId, String subscriptionId) {
    ProjectSubscriptionName subscriptionName =
        ProjectSubscriptionName.of(projectId, subscriptionId);

    // Instantiate an asynchronous message receiver.
    MessageReceiver receiver =
        (PubsubMessage message, AckReplyConsumer consumer) -> {
          // Handle incoming message, then ack the received message.
          System.out.println("Id: " + message.getMessageId());
          System.out.println("Data: " + message.getData().toStringUtf8());
          consumer.ack();
        };

    Subscriber subscriber = null;
    try {
      subscriber = Subscriber.newBuilder(subscriptionName, receiver).build();
      // Start the subscriber.
      subscriber.startAsync().awaitRunning();
      System.out.printf("Listening for messages on %s:
", subscriptionName.toString());
      // Allow the subscriber to run for 30s unless an unrecoverable error occurs.
      // subscriber.awaitTerminated(30, TimeUnit.SECONDS);
      subscriber.awaitTerminated();
      System.out.printf("Async subscribe terminated on %s:
", subscriptionName.toString());
    // } catch (TimeoutException timeoutException) {
    } catch (Exception e) {
      // Shut down the subscriber after 30s. Stop receiving messages.
      subscriber.stopAsync();
      System.out.printf("Async subscriber exception: " + e); 
    }
  }
}

推荐答案

科尔班问题非常重要!!有了共享代码,我想说不。Cloud Run contract很清楚:

  • 您的服务必须响应HTTP请求。在请求之外,您无需支付任何费用,并且没有CPU专用于您的实例(当没有请求正在处理时,该实例就像一个守护进程)
  • 您的服务必须是无状态的(这里不是您的情况,我不会在此花费时间)
如果要提取您的PubSub订阅,请在code with a Rest controller中创建终结点。在处理此请求时,请运行请求机制并处理消息。

Cloud Scheduler可以定期调用此终结点以保持进程正常运行。

小心,您有a max request processing timeout at 15 minutes(今天,可能在不久的将来会有变化)。因此,您不能运行您的流程超过15分钟。使其具有故障恢复能力,并将您的计划程序设置为每15分钟调用一次服务

这篇关于Google Cloud Run pubSub Pull Listener应用程序无法启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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