【问题记录】【Apache Camel】Apache Camel 报 413Request Entity Too Large

1  前言

Apache Camel 不知道大家有没有用过。它是一个基于企业应用集成模式(EIP)的强大开源集成框架。能够快速、轻松地集成,用于在各种系统之间消费或生产数据。说白了可以用于系统之间的不同方式的交互支撑。

最近出现一个问题,来记录一下。

2  问题现象

有客户反应说一个单子卡单了,发现 Camel 报错,报错类似如下:

从 HTTP 返回的状态码 413 来看,也就是客户端错误,再看报错信息,因为我们是 POST请求,说明请求体过大了。

再看一下这个单子,发现这个单子的明细特别多,将近1000行,那大概确实是请求体过长了。因为是生产环境,我们要迅速解决问题,那可以直接先手动的比如通过 Postman,Apifox 直接调用第三方系统的接口先把数据传过去对吧,先把客户的问题解决掉,别让人卡单,然后再慢慢看Camel 是哪里限制了大小,再做排查。

3  问题答案

Camel 这玩意之前也没研究过,也是一点点找,花了半天时间,终于是解决了,我这里先贴下最后的解决办法,就加了下边三行加红的代码:

private void initContext() throws Throwable {
    Registry registry = camelContext.getRegistry();
    registry.bind("RouteCacheManage", routeCacheManage);
    registry.bind("TemplateCacheManage", templateCacheManage);
    camelContext.setUuidGenerator(uuidGenerator);
    camelContext.setTracer(stargateTracer);
    camelContext.setRestConfiguration(buildRestConfiguration());
}
private RestConfiguration buildRestConfiguration(){
    // Rest 组件的配置
    RestConfiguration restConfiguration = new RestConfiguration();
    // 端口
    restConfiguration.setPort(8888);
    // 路径
    restConfiguration.setContextPath("/api");
    // 采用的组件类型
    restConfiguration.setComponent("netty-http");
    // !!!就加了下边三行代码
    Map<String, Object> map = new HashMap<>();
    // 默认是 1048576(1024*1024)即1M 改成10M
    map.put("configuration.chunkedMaxContentLength", 10485760);
    restConfiguration.setConsumerProperties(map);
    return restConfiguration;
}

 

posted @ 2024-08-16 15:26  酷酷-  阅读(2)  评论(0编辑  收藏  举报