容器化 springboot 应用程序无法从服务总线队列中获取新消息

发布于 2025-01-18 14:22:15 字数 4941 浏览 4 评论 0原文

我们有一个在 Azure Web App 中运行的 springboot 应用程序(使用容器 docker)

该应用程序使用“azure-spring-cloud-stream-binder-servicebus-queue”连接到 Azure 服务总线并处理队列。

如果队列为空一段时间,并且当有新请求进入队列时,我们的应用程序将无法获取新请求,直到我们重新启动应用程序。

有没有人遇到过这种情况,可以分享一下经验。

@Bean
public Consumer<Message<String>> onReceive() {
   return message -> {
   String msg = message.getPayload();
   //logic to process the msg
   };
}

这是 POM.xml

    <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.5.6</version>
    <relativePath />
    <!-- lookup parent from repository -->
</parent>
<groupId>xxx</groupId>
<artifactId>xxx</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>xxx</name>
<description>xxx</description>
<properties>
    <java.version>11</java.version>
    <azure.version>3.10.0</azure.version>
    <spring-cloud.version>2020.0.4</spring-cloud.version>
    <maven.test.skip>true</maven.test.skip>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>com.azure.spring</groupId>
        <artifactId>azure-spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>mssql-jdbc</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-stream</artifactId>
    </dependency>
    <dependency>
        <groupId>com.azure.spring</groupId>
        <artifactId>azure-spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>com.azure.spring</groupId>
        <artifactId>azure-spring-cloud-stream-binder-servicebus-queue</artifactId>
        <version>2.10.0</version>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>redis.clients</groupId>
        <artifactId>jedis</artifactId>
        <version>3.7.0</version>
    </dependency>
</dependencies>
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>com.azure.spring</groupId>
            <artifactId>azure-spring-boot-bom</artifactId>
            <version>${azure.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
</project>

应用程序设置

spring.cloud.azure.servicebus.connection-string=${BRT_SMS_SB_CONNECTIONSTRING}
spring.cloud.stream.bindings.onReceive-in-0.group=consumer
spring.cloud.stream.bindings.onReceive-in-0.destination=${BRT_SMS_SB_QUEUE}
spring.cloud.azure.stream.function.definition=consume;
spring.cloud.azure.stream.poller.fixed-delay=5000
spring.cloud.azure.stream.poller.initial-delay=0

** 基本上我指的是这个 文章

We have a springboot application running in Azure Web App (using container docker)

The application is using "azure-spring-cloud-stream-binder-servicebus-queue" to connect to Azure Service Bus and process the queue.

If the queue was empty for some time, and when there is a new request coming into the queue, our application was not able to pick up the new request until we restart the application.

Has anyone encountered this before and can share their experience.

@Bean
public Consumer<Message<String>> onReceive() {
   return message -> {
   String msg = message.getPayload();
   //logic to process the msg
   };
}

Here is the POM.xml

    <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.5.6</version>
    <relativePath />
    <!-- lookup parent from repository -->
</parent>
<groupId>xxx</groupId>
<artifactId>xxx</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>xxx</name>
<description>xxx</description>
<properties>
    <java.version>11</java.version>
    <azure.version>3.10.0</azure.version>
    <spring-cloud.version>2020.0.4</spring-cloud.version>
    <maven.test.skip>true</maven.test.skip>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>com.azure.spring</groupId>
        <artifactId>azure-spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>mssql-jdbc</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-stream</artifactId>
    </dependency>
    <dependency>
        <groupId>com.azure.spring</groupId>
        <artifactId>azure-spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>com.azure.spring</groupId>
        <artifactId>azure-spring-cloud-stream-binder-servicebus-queue</artifactId>
        <version>2.10.0</version>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>redis.clients</groupId>
        <artifactId>jedis</artifactId>
        <version>3.7.0</version>
    </dependency>
</dependencies>
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>com.azure.spring</groupId>
            <artifactId>azure-spring-boot-bom</artifactId>
            <version>${azure.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
</project>

Application Setting

spring.cloud.azure.servicebus.connection-string=${BRT_SMS_SB_CONNECTIONSTRING}
spring.cloud.stream.bindings.onReceive-in-0.group=consumer
spring.cloud.stream.bindings.onReceive-in-0.destination=${BRT_SMS_SB_QUEUE}
spring.cloud.azure.stream.function.definition=consume;
spring.cloud.azure.stream.poller.fixed-delay=5000
spring.cloud.azure.stream.poller.initial-delay=0

** Basically I'm referring to this article

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文