未调用Service Activator

时间:2017-08-27 00:42:07

标签: spring-boot spring-integration

我正在尝试这个用例: 轮询队列中的消息 - >转换消息 - >使用转换后的消息调用方法。

这是我的代码

    <jms:message-driven-channel-adapter id="jmsIn"
            destination-name="test"
            channel="jmsInChannel"/>
    <channel id="jmsInChannel"/>
    <channel id="consoleOut"/>
    <int:transformer input-channel="jmsInChannel" ref="xmlMsgToVORPojoTransformer" output-channel="consoleOut">
    </int:transformer>

    <beans:bean id="xmlMsgToVORPojoTransformer" class="com.order.jmspublisher.ValidateOrderMessageTransformer">
        <beans:property name="unmarshaller" ref="marshaller" />
   </beans:bean>

   <beans:bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
        <beans:property name="classesToBeBound">
            <beans:list>
                <beans:value>com.order.jmspublisher.ValidateOrderResponseType</beans:value>
            </beans:list>
        </beans:property>
    </beans:bean>

    <logging-channel-adapter id="consoleOutloggerChannel" channel="consoleOut" log-full-message="true" level="DEBUG"/>
     <int:service-activator id="sa" input-channel="consoleOut"   output-channel="someChannel" method="handleVOR">
        <beans:bean id="vorActivator" class="com.order.jmspublisher.VORServiceActivator"/>
    </int:service-activator> 

我的Transformer代码如下:

@SuppressWarnings("rawtypes")
       public Message transform(String message)
       {
           try {
              XMLInputFactory xif = XMLInputFactory.newFactory();
              XMLStreamReader xsr = xif.createXMLStreamReader(new StreamSource(new StringReader(message)));
              xsr.nextTag(); // Advance to Envelope tag

              while(xsr.hasNext() ) {
                   int next = xsr.next();
                   if(next == XMLStreamReader.START_ELEMENT)

                      if(xsr.getLocalName().equals("ValidateOrderResponse"))
                      {
                          break;
                      }

                }
             ValidateOrderResponseType vor = (ValidateOrderResponseType)marshaller.unmarshal(new StAXSource(xsr));
             return MessageBuilder.withPayload(vor).build();
          } catch (XmlMappingException e) {
              return MessageBuilder.withPayload(e).build();
          } catch(Exception e){
             return MessageBuilder.withPayload(e).build();
            }
       }

=============================================== ========================= 我的服务激活方法代码如下:

public class VORServiceActivator {

    private static final Logger logger = LoggerFactory.getLogger(VORServiceActivator.class); 
    @ServiceActivator
       public String handleVOR(ValidateOrderResponseType vor)
       {
          logger.info("vor information received and invoke some services here....\r\n"+vor);
          return vor.toString();
       }

}

=============================================== ==========================

我的服务激活方法没有被调用。但是我的变换被调用了,我可以在日志中看到相同的变化。 请帮我知道我哪里错了。 提前谢谢。

1 个答案:

答案 0 :(得分:0)

<channel id="consoleOut"/>DirectChannel;你有2个消费者订阅了频道(日志适配器和服务激活器)。

默认调度程序将以循环方式向这些竞争消费者分发消息;所以每个人都会得到替代信息。

如果您希望两位消费者都能收到所有消息,则需要将consoleOut更改为<publish-subscribe-channel />

You can read about channel types here