2015-07-28 54 views
0

我想將以下內容轉換爲spring-integration java dsl。使用Java DSL設置pub-sub-domain

<int:channel id="partsSubscriberChannel" /> 

    <int-jms:message-driven-channel-adapter 
     id="jmsPartsInbound" 
     acknowledge="transacted" 
     destination-name="parts.topic" 
     channel="partsSubscriberChannel" 
     pub-sub-domain="true" 
     connection-factory="jmsConnectionFactory"/> 

這是我最高:

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

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

@Bean 
public IntegrationFlow partsSubscription(ConnectionFactory connectionFactory) { 
    return IntegrationFlows 
      .from(Jms.messageDriverChannelAdapter(connectionFactory) 
        .id("partsJmsSubscriber") 
        .destination(Topic.PARTS.getName()) 
        .outputChannel(partsSubscriberChannel()) 
        .errorChannel(partsErrorChannel())) 
      .get(); 
} 

如何設置pub-sub-domainacknowledge XML屬性?

回答

0

這是當前不可直接使用DSL,但你可以在屬性設置一個監聽器容器連線...

@Bean 
public IntegrationFlow jmsMessageDriverFlowWithContainer() { 
    return IntegrationFlows 
      .from(Jms.messageDriverChannelAdapter(container()) 
        .id("foo")) 
        .errorChannel(errorChannel())) 
      .channel(outputChannel() 
      .get(); 
} 

@Bean 
public AbstractMessageListenerContainer container() { 
    DefaultMessageListenerContainer container = new DefaultMessageListenerContainer(); 
    container.setSessionTransacted(true); 
    container.setDestinationName(Topic.PARTS.getName()); 
    container.setPubSubDomain(true); 
    return container; 
} 
+0

感謝,並AbstractMessageListenerContainer類需要一個@Bean?原因是我將創建許多不同的主題,所以Topic.PARTS.getName()會傳遞一個參數。 – jax

+0

不,它不會,只要您不需要稍後將其作爲參考(例如在運行時更改併發消費者等)。順便說一下,我之前創建了一個[拉請求](https://github.com/spring-projects/spring-integration-java-dsl/pull/41),以將工廠方法添加到'Jms'來構建容器。但是,在將它集成到發行版之前還有一段時間。 –

+0

我現在實際上在類[javax.jms.Session]'中找不到'org.springframework.core.ConstantException:Field'AUTO'。 – jax