Spring 集成 Java 配置/DSL 中没有方法的服务激活器
Service Activator without method in Spring Integration Java Config / DSL
当为 service-activator
使用基于 XML 的配置时,您可以排除 method
,如下所示:
<service-activator input-channel="incomingCustomerChannel" output-channel="outgoingCustomerChannel" ref="customerService" />
这将导致 SI 框架根据负载选择 customerService
中的目标方法。如何使用 DSL 和 Java 配置实现相同的功能?
目前我有:
@Bean
public IntegrationFlow customerRequestFlow(ConnectionFactory connectionFactory) {
return IntegrationFlows.from((MessagingGateways g) -> g.jms(connectionFactory)
.correlationKey("JmsCorrelationID")
.destination("customer_incoming.queue"))
.handle("customerService", "addCustomer")
.get();
}
服务激活器定义为:
@Component
public class customerService {
@ServiceActivator
public AddCustomerResponse addCustomer(AddCustomerRequest addCustomerRequest) {
// add customer
}
}
我扩展了激活器以添加一个 deleteCustomer
方法,如下所示:
@Component
public class customerService {
@ServiceActivator
public AddCustomerResponse addCustomer(AddCustomerRequest request) {
// add customer
}
@ServiceActivator
public DeleteCustomerResponse deleteCustomer(DeleteCustomerRequest request) {
// delete customer
}
}
我不能简单地从 .handle("customerService", "addCustomer")
中删除 , "addCustomer"
,因为 methodName
是强制性的。是否可以在 Java 配置/DSL 中实现此目的?
您可以使用相同的 .handle()
使用 null
作为方法名称:
.handle("customerService", "addCustomer")
或者从 version 1.1 开始,您可以使用该方法的新版本:
@Autowired
private CustomerService customerService;
....
.handle(this.customerService)
这两种变体的功能与 <service-activator>
的 ref
完全相同。
当为 service-activator
使用基于 XML 的配置时,您可以排除 method
,如下所示:
<service-activator input-channel="incomingCustomerChannel" output-channel="outgoingCustomerChannel" ref="customerService" />
这将导致 SI 框架根据负载选择 customerService
中的目标方法。如何使用 DSL 和 Java 配置实现相同的功能?
目前我有:
@Bean
public IntegrationFlow customerRequestFlow(ConnectionFactory connectionFactory) {
return IntegrationFlows.from((MessagingGateways g) -> g.jms(connectionFactory)
.correlationKey("JmsCorrelationID")
.destination("customer_incoming.queue"))
.handle("customerService", "addCustomer")
.get();
}
服务激活器定义为:
@Component
public class customerService {
@ServiceActivator
public AddCustomerResponse addCustomer(AddCustomerRequest addCustomerRequest) {
// add customer
}
}
我扩展了激活器以添加一个 deleteCustomer
方法,如下所示:
@Component
public class customerService {
@ServiceActivator
public AddCustomerResponse addCustomer(AddCustomerRequest request) {
// add customer
}
@ServiceActivator
public DeleteCustomerResponse deleteCustomer(DeleteCustomerRequest request) {
// delete customer
}
}
我不能简单地从 .handle("customerService", "addCustomer")
中删除 , "addCustomer"
,因为 methodName
是强制性的。是否可以在 Java 配置/DSL 中实现此目的?
您可以使用相同的 .handle()
使用 null
作为方法名称:
.handle("customerService", "addCustomer")
或者从 version 1.1 开始,您可以使用该方法的新版本:
@Autowired
private CustomerService customerService;
....
.handle(this.customerService)
这两种变体的功能与 <service-activator>
的 ref
完全相同。