Spring Integration http模块使用遇到的坑

本文介绍了在Spring Integration中使用HTTP模块进行请求转发时遇到的问题及解决方案。通过配置HTTP inbound和outbound通道,实现了多对多适配的随机权重推送,并探讨了动态配置转发地址的挑战。在实践中发现,即使设置了poller,HTTP请求仍需手动触发,响应无法直接返回原发送处,需借助管道处理。此外,对于转发地址的动态管理,尚未找到理想的集成Spring Integration的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近使用Spring Integration,集成进一个项目,大致是做渠道管理需要转发http请求,多对多适配。权重随机推送,最多三次。

看了很多文章例子

比如这个,https://blog.youkuaiyun.com/w_x_z_/article/details/53316618
还有这个,https://www.cnblogs.com/pekkle/p/7906919.html
还是copy一些过来吧

使用Spring-Integration不仅节省了很多配置,还增加了可用性。

更多关于Spring-Integration的介绍可参照官网:http://spring.io/projects/spring-integration

样例已上传至Github:https://github.com/hackyoMa/spring-integration-http-demo

项目基于Spring Boot2.0。

依赖:

        <dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-http</artifactId>
            <scope>compile</scope>
            <exclusions>
                <exclusion>
                    <artifactId>jackson-module-kotlin</artifactId>
                    <groupId>com.fasterxml.jackson.module</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.47</version>
        </dependency>

配置文件application.properties:

server.port=8080
receive.path=/receiveGateway
forward.path=https://oapi.dingtalk.com/robot/send?access_token=xxx

主类:

package com.integration.http;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportResource;

@SpringBootApplication
@ImportResource(locations = "classpath:http-inbound-config.xml")
public class HttpApp
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值