跟踪mqttv3源码(二)
对于spring-mqtt.xml中的标签:
<int-mqtt:message-driven-channel-adapter>
<int-mqtt:outbound-channel-adapter>
<int:channel>
<int:transformer>
<int:service-activator>
<int:outbound-channel-adapter>
了解Spring自定义标签的应该都知道标签的构建过程:
1、首先我们进入spring-integration-mqtt-4.3.5 --->META-INF路径查看spring.handlers
http\://www.springframework.org/schema/integration/mqtt=org.springframework.integration.mqtt.config.xml.MqttNamespaceHandler
得知命名处理类MqttNamespaceHandler,进入config/xml :
public class MqttNamespaceHandler extends AbstractIntegrationNamespaceHandler {
@Override
public void init() {
this.registerBeanDefinitionParser("message-driven-channel-adapter", new MqttMessageDrivenChannelAdapterParser());
this.registerBeanDefinitionParser("outbound-channel-adapter", new MqttOutboundChannelAdapterParser());
}
}
public class MqttMessageDrivenChannelAdapterParser extends AbstractChannelAdapterParser {
@Override
protected AbstractBeanDefinition doParse(Element element, ParserContext parserContext, String channelName) {
//包装类MqttPahoMessageDrivenChannelAdapter
BeanDefinitionBuilder builder = BeanDefinitionBuilder
.genericBeanDefinition(MqttPahoMessageDrivenChannelAdapter.class);
//用类MqttParserUtils设置builder属性:url、client-id、client-factory、converter、send-timeout
MqttParserUtils.parseCommon(element, builder, parserContext);
//解析spring-mqtt.xml中配置的属性topics、qos、recovery-interval
builder.addConstructorArgValue(element.getAttribute("topics"));
builder.addPropertyReference("outputChannel", channelName);
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "error-channel");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "qos");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "recovery-interval");
return builder.getBeanDefinition();
}
}
查看MqttPahoMessageDrivenChannelAdapter:builder.addPropertyReference("outputChannel", channelName);
跟踪channelName,进入AbstractChannelAdapterParser.parseInternal()可以看到channelName来源于element;
同理进入IntegrationNamespaceHandler,找到registerBeanDefinitionParser("service-activator", new ServiceActivatorParser());跟踪AbstractDelegatingConsumerEndpointParser-->AbstractConsumerEndpointParser:
protected String getInputChannelAttributeName() {
return "input-channel";
}
String inputChannelAttributeName = this.getInputChannelAttributeName();
String inputChannelName = element.getAttribute(inputChannelAttributeName);
builder.addPropertyValue("inputChannelName", inputChannelName);
然后查看spring.tooling就可以得知标签int-mqtt的来源:
# Tooling related information for the integration mqtt namespace
http\://www.springframework.org/schema/integration/mqttadapter@name=integration mqtt Namespace
http\://www.springframework.org/schema/integration/mqttadapter@prefix=int-mqtt
http\://www.springframework.org/schema/integration/mqttadapter@icon=org/springframework/integration/config/xml/spring-integration-mqtt.gif
跟踪进spring-integration-4.3.xsd,可以看到标签<xsd:element service-activator>包含inputOutputChannelGroup:
<xsd:element name="service-activator">
<xsd:annotation>
<xsd:documentation>
Defines an endpoint for the 'org.springframework.integration.handler.ServiceActivatingHandler'
for exposing any bean reference as a service that
receives request Messages
from an 'input-channel' and may send reply
Messages to an 'output-channel'. The 'ref' may point to an instance
that
has either a single public method or a method with the
@ServiceActivator annotation. Otherwise, the 'method'
attribute
should be provided along with 'ref'.
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="serviceActivatorType">
<xsd:attributeGroup ref="inputOutputChannelGroup" />
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
查看标签<xsd:attributeGroup name="inputOutputChannelGroup">可以看到包含output-channel、input-channel、send-timeout、order:
<xsd:attributeGroup name="inputOutputChannelGroup">
<xsd:attribute name="output-channel" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.messaging.MessageChannel" />
</tool:annotation>
</xsd:appinfo>
<xsd:documentation>
Identifies the Message channel where Message will be sent after it's being processed by this endpoint
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="send-timeout" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
Specify the maximum amount of time in milliseconds to wait when sending a reply
Message to the output channel. Defaults to '-1' - blocking indefinitely.
It is applied only if the output channel has some 'sending' limitations, e.g. QueueChannel with
fixed a 'capacity'. In this case a MessageDeliveryException is thrown. The 'send-timeout'
is ignored in case of AbstractSubscribableChannel implementations.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="input-channel" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.messaging.MessageChannel" />
</tool:annotation>
</xsd:appinfo>
<xsd:documentation>
The receiving Message channel of this endpoint
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="order" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[
Specifies the order for invocation when this endpoint is connected as a
subscriber to a channel. This is particularly relevant when that channel
is using a "failover" dispatching strategy. It has no effect when this
endpoint itself is a Polling Consumer for a channel with a queue.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attributeGroup ref="smartLifeCycleAttributeGroup"/>
</xsd:attributeGroup>
可以看到配置文件中:org.springframework.integration.mqtt.core.DefaultMqttPahoClientFactory用来配置通信基础信息
将DefaultMqttPahoClientFactory注入到类org.springframework.integration.mqtt.outbound.MqttPahoMessageHandler,类中messageArrived()方法用来获取消息
跟踪mqttv3源码(二)的更多相关文章
- 跟踪mqttv3源码(一)
Spring整合MQTT pom.xml <!-- MQTT消息队列 --> <dependency> <groupId>org.eclipse.paho</ ...
- Unity UGUI图文混排源码(二)
Unity UGUI图文混排源码(一):http://blog.csdn.net/qq992817263/article/details/51112304 Unity UGUI图文混排源码(二):ht ...
- JMeter 源码二次开发函数示例
JMeter 源码二次开发函数示例 一.JMeter 5.0 版本 实际测试中,依靠jmeter自带的函数已经无法满足我们需求,这个时候就需要二次开发.本次导入的是jmeter 5.0的源码进行实际的 ...
- AQS源码二探-JUC系列
本文已在公众号上发布,感谢关注,期待和你交流. AQS源码二探-JUC系列 共享模式 doAcquireShared 这个方法是共享模式下获取资源失败,执行入队和等待操作,等待的线程在被唤醒后也在这个 ...
- [转载 java 技术栈] eclipse 阅读跟踪 Java 源码的几个小技巧!
本文基于Eclipse IDE,我们每天都使用的IDE其实提供了很多强大的功能,掌握它们,往往能够事半功倍. 1.Quick Type Hierarchy 快速查看类继承体系. 快捷键:Ctrl + ...
- JDK1.8源码(二)——java.lang.Integer类
一.初识 1.介绍 int 是Java八大基本数据类型之一,占据 4 个字节,范围是 -2^31~2^31 - 1,即 -2147483648~2147483647.而 Integer 是 int 包 ...
- Qemu+gdb跟踪内核源码
1.编译安装Qemu Qemu源码下载地址:http://wiki.qemu.org/Download linux下可以直接用wget下载: wget http://wiki.qemu.org/dow ...
- JDK1.8源码(二)——java.lang.Integer 类
上一篇博客我们介绍了 java.lang 包下的 Object 类,那么本篇博客接着介绍该包下的另一个类 Integer.在前面 浅谈 Integer 类 博客中我们主要介绍了 Integer 类 和 ...
- Jetty源码学习-编译Jetty源码二三事
工作小几个月了,JDK基础和web应用框架学的的差不多了,开始学习Jetty源码,费了小半天才编译成功,把自己拆过的坑记录下来. 编译前的环境: MAVEN 3.3.Eclips eLuna Serv ...
随机推荐
- 单点登录(SSO)详解
背景 在企业发展初期,企业使用的系统很少,通常一个或者两个,每个系统都有自己的登录模块,运营人员每天用自己的账号登录,很方便.但随着企业的发展,用到的系统随之增多,运营人员在操作不同的系统时,需要多次 ...
- Mysql千万级大数据量查询优化
来源于:https://blog.csdn.net/A350204530/article/details/79040277 1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 ord ...
- visualization of filters keras 基于Keras的卷积神经网络(CNN)可视化
https://adeshpande3.github.io/adeshpande3.github.io/ https://blog.csdn.net/weiwei9363/article/detail ...
- iOS 小米推送总结和遇到的坑
极光推送就不赘述了,这里说下小米推送在ios上的坑吧,查了好久也没有查到相关的文章. 极光的强大就不说了,当客户贪图实惠的时候,当人家给你让你用小米推送的时候,我的内心是崩溃的,小米推送???没听过! ...
- 2018-2019-2 网络对抗技术 20165305 Exp4 恶意代码分析
Exp4 恶意代码分析 1.实践目标 1.1是监控你自己系统的运行状态,看有没有可疑的程序在运行. 1.2是分析一个恶意软件,就分析Exp2或Exp3中生成后门软件:分析工具尽量使用原生指令或sysi ...
- Linux基础命令---mpstat显示cpu使用
mpstat mpstat指令用来显示cpu的使用状况,将内容显示到标准输出.处理器0是第一个.还报告了所有处理器之间的全球平均活动.mpstat命令既可以在SMP机器上使用,也可以在UP机器上使用, ...
- CCF CSP 201809-2 买菜
题目链接:http://118.190.20.162/view.page?gpid=T78 问题描述 小H和小W来到了一条街上,两人分开买菜,他们买菜的过程可以描述为,去店里买一些菜然后去旁边的一个广 ...
- Python爬虫与一汽项目【二】爬取中国东方电气集中采购平台
网站地址:https://srm.dongfang.com/bid_detail.screen 东方电气采购的页面看似很友好,实际上并不好爬取 在观察网页的审查元素之后发现,1处的网页响应只是单纯的一 ...
- Linux网络属性管理
Linux网络属性管理 局域网:以太网,令牌环网 Ethernet: CSMA/CD 冲突域 广播域 MAC:Media Access Control 48bits: 24bits: 24bits: ...
- MySql-2019-4-21-复习
数据库对象:存储,管理和使用数据的不同结构形式,如:表.视图.存储过程.函数.触发器.事件.索引等. 数据库:存储数据库对象的容器. 数据库分两种: 系统数据库(系统自带的数据库):不能修改 info ...