【问题标题】:Spring Integration - Annotation for HeaderValueRouterSpring Integration - HeaderValueRouter 的注解
【发布时间】:2014-06-04 19:14:05
【问题描述】:

如何注释方法以便它处理特定标头值的消息?我已经在 XML 配置中有一个 HeaderValueRouter,它路由到适当的类并根据有效负载类型执行正确的方法。我想像这样注释这个类中的一些方法(特别是没有参数):

@Router(header("operation")="one")
public String getOne() {}

@Router(header("operation")="two")
public String getTwo() {}

这样做的目的是启用类似 REST 的服务,用户可以调用类似 ../service/one 的 URL,Spring Integration 会将操作标头设置为“one”。基本上,我希望能够快速将方法添加到我的 Web 服务中,并且通过将上述注释添加到我的基础服务中,它们会自动工作。

【问题讨论】:

    标签: spring-integration


    【解决方案1】:

    没有这样的机制。即使它看起来很有趣,我也不确定我们应该引入它 - 它打破了一些消息传递问题

    无论如何,对于 XML,您有 <header-value-router>,它有一个 channel-mapping。那一个指定to send消息在哪里调用适当的service-activator

    所以,我建议你使用注释来做同样的事情:

    @MessagingGateway(defaultRequestChannel = "routerChannel")
    public interface ServiceGateway {
    
        Object invoke(String operation);
    
    }
    ....
    
    @Autowired
    private ServiceGateway serviceGateway;
    
    @RequestMapping("/service/{operation}")
    public Object operation(@PathVariable String operation) {
        return this.serviceGateway.invoke(operation);
    }
    
    @Router(inputChannel = "routerChannel")
    public String route(String operation) {
        return operation;
    }
    
    ...
    @ServiceActivator(inputChannel = "one")
    public String getOne() {}
    ...
    @ServiceActivator(inputChannel = "two")
    public String getTwo() {}
    

    【讨论】:

      猜你喜欢
      • 2017-03-27
      • 2018-11-05
      • 2019-06-29
      • 1970-01-01
      • 2016-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多