简体   繁体   English

Spring Integration Java Config / DSL中没有方法的服务激活器

[英]Service Activator without method in Spring Integration Java Config / DSL

When using XML-based configuration for service-activator you can exclude the method as follows: 将基于XML的配置用于service-activator ,可以按以下method排除该method

<service-activator input-channel="incomingCustomerChannel" output-channel="outgoingCustomerChannel" ref="customerService" />

This will cause the SI framework to choose the target method in customerService based on the payload. 这将导致SI框架根据有效负载在customerService选择目标方法。 How can I achieve the same functionality using DSL and Java config? 如何使用DSL和Java配置实现相同的功能?

At present I have the following: 目前,我有以下内容:

@Bean
public IntegrationFlow customerRequestFlow(ConnectionFactory connectionFactory) {

    return IntegrationFlows.from((MessagingGateways g) -> g.jms(connectionFactory)
                                                           .correlationKey("JmsCorrelationID")
                                                           .destination("customer_incoming.queue"))
                                                           .handle("customerService", "addCustomer")
                                                           .get();
}

The service activator is defined as: 服务激活器定义为:

@Component
public class customerService {

    @ServiceActivator
    public AddCustomerResponse addCustomer(AddCustomerRequest addCustomerRequest) {

        // add customer
    }
}

I have extended the activator to add a deleteCustomer method as follows: 我已经扩展了激活器,以添加deleteCustomer方法,如下所示:

@Component
public class customerService {

    @ServiceActivator
    public AddCustomerResponse addCustomer(AddCustomerRequest request) {

        // add customer
    }

    @ServiceActivator
    public DeleteCustomerResponse deleteCustomer(DeleteCustomerRequest request) {

        // delete customer
    }
}

I cannot simply remove the , "addCustomer" from .handle("customerService", "addCustomer") as methodName is mandatory. 我不能简单地从.handle("customerService", "addCustomer")删除, "addCustomer" .handle("customerService", "addCustomer")因为methodName是必需的。 Is it possible to achieve this in Java config / DSL? 是否有可能在Java config / DSL中实现呢?

You can use the same .handle() using null for method name: 您可以将相同的.handle()使用null作为方法名称:

.handle("customerService", "addCustomer")

Or starting with version 1.1 you can use a new version of that method: 或者从1.1版开始,您可以使用该方法的新版本:

@Autowired
private CustomerService customerService;
....
.handle(this.customerService)

Both variants do exactly the same what you have with just ref for <service-activator> . 这两个变体的功能与<service-activator> ref完全相同。

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

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