英文:
Configure RestTemplate for HttpRequestExecutingMessageHandler per message
问题
我正在进行一个Spring集成项目,其中我正在使用HttpRequestExecutingMessageHandler类创建出站网关。我想要使用单个网关执行经过Bearer身份验证令牌认证的不同API。我有不同的RestTemplate配置来处理每种类型的消息。
我无法找到如何在此类中按消息基础配置restTemplate的方法。该类仅在构建时接受restTemplate。
目前,我通过扩展AbstractHttpRequestExecutingMessageHandler类创建了自定义网关类,它是HttpRequestExecutingMessageHandler类的父类,并且复制了exchange方法的内容。我将restTemplate的bean名称作为消息头进行传递,并在exchange方法的开始处解析它。
有更好的方法吗?
英文:
I am working on a spring integration project where I am creating outbound gateway using HttpRequestExecutingMessageHandler class. I want to execute different APIs which are authenticated using bearer authentication tokens using single gateway. I have different RestTemplate configured to handle each type of message.
I could not find how to configure restTemplate per message basis using this class. This class only accepts restTemplate at construction time.
https://docs.spring.io/spring-integration/api/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandler.html
For now, I have created custom gateway class by extended AbstractHttpRequestExecutingMessageHandler which is parent of HttpRequestExecutingMessageHandler and copied contents of exchange method from HttpRequestExecutingMessageHandler class. I am passing restTemplate bean name as message header and resolving it at the start of exchange method.
Is there any better approach?
答案1
得分: 0
“使用单网关”从设计上来看已经是一个错误的决定。
您可能需要考虑为这些目的使用不同的 HttpRequestExecutingMessageHandler
。根据您的逻辑,您可以添加一个路由器来决定将消息发送到哪个HTTP出站网关。
更多信息请参阅文档:https://docs.spring.io/spring-integration/docs/5.3.2.RELEASE/reference/html/message-routing.html#messaging-routing-chapter
英文:
The "using single gateway" is already a wrong decision from design.
You probably need to think about having different HttpRequestExecutingMessageHandler
for those purposes. In your logic you can add then a router to decide to which HTTP Outbound Gateway to send a message.
See more info in docs: https://docs.spring.io/spring-integration/docs/5.3.2.RELEASE/reference/html/message-routing.html#messaging-routing-chapter
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论