简体   繁体   English

我可以使用哪种弹簧集成模式?

[英]Which spring integration pattern can I use?

I have a message that comes to my project. 我有一条消息要传达给我的项目。 I need to persist the message and publish the message in a spring channel for subscriber to pick up the message and process it. 我需要保留该消息,并在一个春季频道中发布该消息,以便订阅者接收该消息并对其进行处理。

The publisher then sends back HTTP OK to the sender. 然后,发布者将HTTP OK发送回发送者。

The subscriber needs to process the message with some business logic and retrying for a maximum of 3 times if there is an exception/error. 订户需要使用某种业务逻辑来处理消息,如果存在异常/错误,则最多重试3次。

Which spring integration pattern can I use? 我可以使用哪种弹簧集成模式?

I am thinking about using PublishSubscribeChannel, the publisher sends the message to the subscriber channel and subscriber picks up the message and publisher needs to return OK to the sender. 我正在考虑使用PublishSubscribeChannel,发布者将消息发送到订阅者通道,订阅者接收消息,发布者需要向发送者返回OK。 Not sure if this is right approach. 不确定这是否正确。

I am also trying to use spring annotations, could you give me links on which annotations can I use? 我也在尝试使用spring注释,能否给我链接我可以使用的注释?

Your use-case is typical for the Spring Integration and it is fully valid for integration stuff at all. 您的用例对于Spring Integration是典型的,并且对于集成的东西完全有效。

Looks like you should spend more time for the EIP theory, as you aren't sure what to do. 似乎您应该花更多的时间来研究EIP理论,因为您不确定该怎么做。

Well, PublishSubscribeChannel is for cases, when you need send the same message to several subscribers, however, of course, it works with the single subscriber as well. 好吧, PublishSubscribeChannel用于需要将同一条消息发送给多个订阅者的情况,但是,当然,它也适用于单个订阅者。 It is like topic in terms of JMS. 就JMS而言,这就像topic

I'd implement your use-case like: 我将实现您的用例,例如:

<int-http:ibound-gateway path="/foo" request-channel="input"/>

<int:channel id="input"/>

<int:service-activator input-channel="input" ref="myService" method="serviceMethod">
    <int:request-hadnler-advice-chain>
         <beans:bean class="org.springframework.integration.handler.advice.RequestHandlerRetryAdvice"/>
    </int:request-hadnler-advice-chain>
</int:service-activator>

Where the myService just should return OK String after business logic. myService仅应在业务逻辑之后返回OK String的情况下。

Since you implement request/reply case (HTTP) there is no reason to persist message, since HTTP client waits for reply immediately and your persistence for messages might break something in logic in the future. 由于您实现了请求/答复情况(HTTP),因此没有理由保留消息,因为HTTP客户端会立即等待答复,并且您对消息的持久性将来可能会破坏逻辑。 However it will work, of course, in this case, too - with message-store on <queue> of <channel> . 但是,在这种情况下,它当然也可以工作-通过<channel> <queue>上的message-store

To make the same with annotations, it might look like this: 为了使注释相同,可能看起来像这样:

@Configuration
@EnableIntegration
@EnableRetry
@ComponentScan
public class HttpFlowSample {

    @Bean
    public MessageChannel input() {
        return new DirectChannel();
    }

    @Bean
    public MessagingGatewaySupport httpInboundGateway() {
        HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway();
        RequestMapping mapping = new RequestMapping();
        mapping.setPathPatterns("/foo");
        gateway.setRequestMapping(mapping);
        gateway.setRequestChannel(this.input());
        return gateway;
    }


    @MessageEndpoint
    public static class MyService {

        @ServiceActivator(inputChannel = "input")
        @Retryable
        public String serviceMethod(Object payload) {
            //Do business logic
            return "OK";
        }

    }

}

The annotation sample will work only with Spring Integration 4.0. 注释样本仅适用于Spring Integration 4.0。

Let us know, if this is appropriate for you and I understood you fully. 让我们知道这是否适合您,而我也完全理解您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM