2015-09-26 47 views
1

當使用基於XML的配置service-activator可以排除method如下:服務激活就沒有辦法在Spring集成的Java配置/ DSL

<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 
    } 
} 

我不能簡單地從中刪除 as methodName是強制性的。是否有可能在Java config/DSL中實現這一點?

+1

我不知道如何轉換,但您可以通過使用'PayloadTypeRouter'實現相同的行爲,這是在[Spring Integration DSL]中預定義的(https://github.com/spring-projects/彈簧集成的Java-DSL /維基/ Spring的集成的Java-DSL-參考#消息路由器)。 – Nicolas

回答

3

您可以使用相同的.handle()使用null的方法名稱:

.handle("customerService", "addCustomer") 

或者與version 1.1開始,你可以使用該方法的一個新版本:

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

兩種變體的作用完全相同你只需ref就可以得到<service-activator>

相關問題