2017年3月27日15:56:23 复习与基础的重要

   之前一直对于integration的xml配置感到很无力,首先不知道可以用什么 节点名,然后又不知道节点内部的参数的作用。这两个问题一问出来会很模糊,看官方文档当然是你可以的,但是如果你忘记了或者不知道xml中命名空间 别名的声明和scheme的运用,那么就算把文档看穿也未必能解决这两个问题。

   关于xml中的配置首先要根据命名空间的别名去寻找目标节点在scheme中的说明无论是类还是属性,就算scheme中没有详细说明但是你手里已经有了句柄只需要相应的查找资料就可以解决问题。比如说:

<!-- 异步 -->
    <int:channel id="output_new_user_apply_credit_amount_channel"/>
    <int-amqp:outbound-channel-adapter id="third_party_credit_amount_out_adapter"
        channel="output_new_user_apply_credit_amount_channel" amqp-template="amqpTemplate" exchange-name="financialManagement.exchange"
        routing-key="thirdPartyCreditAmountQuery.queue"/>
        
    <int:channel id="input_new_user_apply_credit_amount_handler"/>
    <int-amqp:inbound-channel-adapter channel="input_new_user_apply_credit_amount_handler" error-channel="amqpAsynFailedMessageChannel"
        queue-names="thirdPartyCreditAmountQuery.queue" connection-factory="rabbitConnectionFactory"/>
    <int:service-activator input-channel="input_new_user_apply_credit_amount_handler"
        ref="userInfoActivator" method="getNewUserCreditAmount" />

这是rabbitmq实现异步的配置sample,ok,channel这些东西都是很容易理解的,routing-key也都是官方中说的很清楚的,但是amqp-template是什么鬼,做什么的,为什么要引用他。于是,按照上面的办法先看scheme:“<tool:annotation kind="ref"><tool:expected-type type="org.springframework.amqp.core.AmqpTemplate"/></tool:annotation>”然后在ide中new一个AmqpTemplate,查看源码说明会发现其实他是用来发布消息的。那么之前的那段配置就很容易理解了,你把输入的channel用来做发布消息用,这也是他区别于其他点对点mq消息的区别。

原文地址:https://www.cnblogs.com/Luke-wang/p/6627242.html