JmsOutboundGateway - Java配置缺少选项?

时间:2017-01-17 10:24:50

标签: java spring spring-mvc spring-integration

我目前正在将Springs XML转换为Java-Configuration。 (Spring Version 4.3.4)我目前正在努力解决Spring Integration问题。 JmsOutboundGateway似乎不支持其XML对应的所有选项:

XML:

<int-jms:outbound-gateway 
  correlation-key="JMSCorrelationID" auto-startup="true" 
  connection-factory="connectionFactory" explicit-qos-enabled="true" 
  time-to-live="60000" request-channel="myRequestChannel" request-destination="outQueue"
  requires-reply="true" reply-channel="myResponseChannel" reply-destination="inQueue"
  receive-timeout="20000" >
</int-jms:outbound-gateway>

翻译的Java:

@Bean
public JmsOutboundGateway myGateway(){
    JmsOutboundGateway gateway = new JmsOutboundGateway();
    gateway.setConnectionFactory(connectionFactory());
    gateway.setCorrelationKey("JMSCorrelationID");
    gateway.setReplyChannel(myResponseChannel());
    gateway.setReplyDestination(inQueue());
    gateway.setReceiveTimeout(20000);
    gateway.setExplicitQosEnabled(true);
    gateway.setRequiresReply(true);
    gateway.setRequestDestination(outQueue())
    return gateway;
}

自动启动请求频道似乎“缺失”。我只是在错误的地方寻找它们还是需要额外的步骤?我甚至误解了什么吗?

提前致谢!

2 个答案:

答案 0 :(得分:1)

XML解析器创建的所有消费端点都获得2个bean;一个消息处理程序和一个调用处理程序的消费者;消费者取决于输入渠道的类型;那些属性依赖于消费者。

使用Java配置配置使用端点时,将@ServiceActivator添加到@Bean以生成使用者bean(对请求通道使用inputChannel)。

有关详细信息,请参阅Programming Tips and Tricks

答案 1 :(得分:0)

试试这个

   @Bean 
   @ServiceActivator(inputChannel="requestChannel",outputChannel="replyChannel",autoStartup="true")
     public JmsOutboundGateway jmsGateway(){
       JmsOutboundGateway gateway=new JmsOutboundGateway();
       gateway.setConnectionFactory(connectionFactory);
       gateway.setRequestDestinationName("test.out");
       gateway.setReplyDestinationName("test.in");
       gateway.setCorrelationKey("JMSCorrelationID");
       return gateway;
     }