AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / coding / 问题 / 77698752
Accepted
al.truisme
al.truisme
Asked: 2023-12-21 22:51:11 +0800 CST2023-12-21 22:51:11 +0800 CST 2023-12-21 22:51:11 +0800 CST

spring-integration 5.5.18 消息传递网关超时

  • 772

我使用它是@MessagingGateway为了在spring-mvc @Controller和之间架起桥梁spring-integration。该@MessagingGateway声明如下所示:

package a.b.c;

import org.springframework.integration.annotation.*;
import org.springframework.stereotype.Component;

@MessagingGateway(name="inboundGateway" defaultRequestTimeout="2000"
                                        defaultReplyTimeout="2000")

@Component
public interace InboundGateway {

    @Gateway(requestChannel = "getSomething")
    Message<SomeValue> getSomething(@Headers Map<String, Object> headers);

}

这是从控制器引用的

@Controller
@RequestMapping("/some/base/path")
public class SomeController {

    private final InboundGateway inboundGateway;

    public SomeController(InboundGateway inboundGateway) {
        this.inboundGateway = inboundGateway;
    }

    @GetMapping(value = "things", produces = { "application/json" })
    public ResponseEntity<SomeValue> getSomething(RequestContext<String> requestContext) {
        Message<SomeValue> response = inboundGateway.getSomething(requestContext);
        ....
}

我认为如果在指定时间内没有返回响应,defaultRequestTimeout和 的定义defaultReplyTimeout会引发超时。inboundGateway

然而,我发现该方法中使用的时间getSomething()可能超过指定的时间,在本例中为 2 秒。看来2秒是作为调用下游系统的超时时间,而不是作为返回的超时时间getSomething()。

我的理解正确吗?是否有一些简单的、声明性的方法来管理该inboundGateway级别的超时?任何指示表示赞赏。

spring-mvc
  • 1 1 个回答
  • 19 Views

1 个回答

  • Voted
  1. Best Answer
    Artem Bilan
    2023-12-21T23:01:22+08:002023-12-21T23:01:22+08:00

    您所解释的行为对于您的流来说是典型inboundGateway的DirectChannel。这样,消息处理就直接在生成该消息的线程上执行。因此,它无法到达replyTimeoutfor 结果,因为该线程被阻塞等待消息处理。

    请参阅不同渠道的文档中的更多信息:https://docs.spring.io/spring-integration/reference/channel/implementations.html

    另请参阅有关网关上的超时的文档:https://docs.spring.io/spring-integration/reference/gateway.html

    作为满足您期望的简单解决方案,您可以考虑使用aQueueChnanel或. 这样,处理将被移交给不同的线程,并且网关将能够轻松地转到答复等待块。这就是它会产生影响的地方。inboundGatewayExecutorChannelreplyTimeout

    该注释属性 JavaDocs 中也有解释:

    /**
     * Provides the amount of time dispatcher would wait to send a {@code Message}. This
     * timeout would only apply if there is a potential to block in the send call. For
     * example if this gateway is hooked up to a {@code QueueChannel}. Value is specified
     * in milliseconds; it can be a simple long value or a SpEL expression; array variable
     * #args is available.
     * See {@link Gateway#requestTimeout()} for per-method configuration.
     * @return the suggested timeout in milliseconds, if any
     */
    String defaultRequestTimeout() default IntegrationContextUtils.DEFAULT_TIMEOUT_STRING;
    
    • 1

相关问题

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    使用 <font color="#xxx"> 突出显示 html 中的代码

    • 2 个回答
  • Marko Smith

    为什么在传递 {} 时重载解析更喜欢 std::nullptr_t 而不是类?

    • 1 个回答
  • Marko Smith

    您可以使用花括号初始化列表作为(默认)模板参数吗?

    • 2 个回答
  • Marko Smith

    为什么列表推导式在内部创建一个函数?

    • 1 个回答
  • Marko Smith

    我正在尝试仅使用海龟随机和数学模块来制作吃豆人游戏

    • 1 个回答
  • Marko Smith

    java.lang.NoSuchMethodError: 'void org.openqa.selenium.remote.http.ClientConfig.<init>(java.net.URI, java.time.Duration, java.time.Duratio

    • 3 个回答
  • Marko Smith

    为什么 'char -> int' 是提升,而 'char -> Short' 是转换(但不是提升)?

    • 4 个回答
  • Marko Smith

    为什么库中不调用全局变量的构造函数?

    • 1 个回答
  • Marko Smith

    std::common_reference_with 在元组上的行为不一致。哪个是对的?

    • 1 个回答
  • Marko Smith

    C++17 中 std::byte 只能按位运算?

    • 1 个回答
  • Martin Hope
    fbrereto 为什么在传递 {} 时重载解析更喜欢 std::nullptr_t 而不是类? 2023-12-21 00:31:04 +0800 CST
  • Martin Hope
    比尔盖子 您可以使用花括号初始化列表作为(默认)模板参数吗? 2023-12-17 10:02:06 +0800 CST
  • Martin Hope
    Amir reza Riahi 为什么列表推导式在内部创建一个函数? 2023-11-16 20:53:19 +0800 CST
  • Martin Hope
    Michael A fmt 格式 %H:%M:%S 不带小数 2023-11-11 01:13:05 +0800 CST
  • Martin Hope
    God I Hate Python C++20 的 std::views::filter 未正确过滤视图 2023-08-27 18:40:35 +0800 CST
  • Martin Hope
    LiDa Cute 为什么 'char -> int' 是提升,而 'char -> Short' 是转换(但不是提升)? 2023-08-24 20:46:59 +0800 CST
  • Martin Hope
    jabaa 为什么库中不调用全局变量的构造函数? 2023-08-18 07:15:20 +0800 CST
  • Martin Hope
    Panagiotis Syskakis std::common_reference_with 在元组上的行为不一致。哪个是对的? 2023-08-17 21:24:06 +0800 CST
  • Martin Hope
    Alex Guteniev 为什么编译器在这里错过矢量化? 2023-08-17 18:58:07 +0800 CST
  • Martin Hope
    wimalopaan C++17 中 std::byte 只能按位运算? 2023-08-17 17:13:58 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve