package com.sto.wenzhou.orderreceive.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.annotation.IntegrationComponentScan;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.core.MessageProducer;
import org.springframework.integration.mqtt.core.DefaultMqttPahoClientFactory;
import org.springframework.integration.mqtt.core.MqttPahoClientFactory;
import org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter;
import org.springframework.integration.mqtt.support.DefaultPahoMessageConverter;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.MessagingException;
import com.sto.wenzhou.orderreceive.util.AESCoder;
@Configuration
@IntegrationComponentScan
public class MqttReceiveConfig {
@Value("${spring.mqtt.username}")
private String username;
@Value("${spring.mqtt.password}")
private String password;
@Value("${spring.mqtt.url}")
private String hostUrl;
@Value("${spring.mqtt.client.id}")
private String clientId;
@Value("${spring.mqtt.default.topic}")
private String defaultTopic;
@Value("${spring.mqtt.connectionTimeout}")
private int connectionTimeout;
@Value("${spring.mqtt.keepAliveInterval}")
private int keepAliveInterval;
@Value("${spring.mqtt.theme}")
private String mqttTheme;
@Value("${spring.aes.key}")
private String aesKey;
@Bean
public MqttPahoClientFactory mqttClientFactory() {
DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory();
factory.setUserName(username);
factory.setPassword(password);
factory.setServerURIs(new String[] { hostUrl });
// 设置超时时间
factory.setConnectionTimeout(connectionTimeout);
// 设置会话心跳时间
factory.setKeepAliveInterval(keepAliveInterval);
return factory;
}
// 接收通道
@Bean
public MessageChannel mqttInputChannel() {
return new DirectChannel();
}
// 配置client,监听的topic
@Bean
public MessageProducer inbound() {
MqttPahoMessageDrivenChannelAdapter adapter = new MqttPahoMessageDrivenChannelAdapter(clientId + "_inbound",
mqttClientFactory(), mqttTheme);
adapter.setCompletionTimeout(connectionTimeout);
adapter.setConverter(new DefaultPahoMessageConverter());
adapter.setQos(1);
adapter.setOutputChannel(mqttInputChannel());
return adapter;
}
// 通过通道获取数据
@Bean
@ServiceActivator(inputChannel = "mqttInputChannel")
public MessageHandler handler() {
return new MessageHandler() {
@Override
public void handleMessage(Message<?> message) throws MessagingException {
MessageHeaders headers = message.getHeaders();
String topic = headers.get("mqtt_topic").toString();
if (mqttTheme.equalsIgnoreCase(topic)) {
try {
String msg = message.getPayload().toString();
// 解密
String resultMsg = AESCoder.decrypt(aesKey, msg);
System.out.println("解密后的内容=========" + resultMsg);
} catch (Exception e) {
e.printStackTrace();
}
}
}
};
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
SpringBoot集成MQTT之消息订阅处理程序
共32个文件
properties:10个
class:4个
lst:3个
4星 · 超过85%的资源 需积分: 44 148 下载量 25 浏览量
2018-11-08
16:13:15
上传
评论 1
收藏 20.08MB RAR 举报
温馨提示
SpringBoot集成MQTT之消息订阅处理程序,含有AES加密算法工具类、BASE64的编码解码。
资源推荐
资源详情
资源评论
收起资源包目录
sto-wenzhou-orderreceive.rar (32个子文件)
sto-wenzhou-orderreceive
.project 1KB
.springBeans 502B
src
main
resources
application-dev.properties 655B
application.properties 26B
log4j.properties 925B
application-pro.properties 655B
java
com
sto
wenzhou
orderreceive
WenZhouOrderReceiveApplication.java 669B
util
AESCoder.java 3KB
config
MqttReceiveConfig.java 3KB
target
maven-status
maven-compiler-plugin
testCompile
default-testCompile
inputFiles.lst 0B
compile
default-compile
createdFiles.lst 840B
inputFiles.lst 1KB
generated-sources
annotations
classes
application-dev.properties 655B
application.properties 26B
com
sto
wenzhou
orderreceive
util
AESCoder.class 3KB
config
MqttReceiveConfig.class 4KB
MqttReceiveConfig$1.class 2KB
WenZhouOrderReceiveApplication.class 1KB
log4j.properties 925B
META-INF
MANIFEST.MF 394B
maven
com.sto.wenzhou.orderreceive
sto-wenzhou-orderreceive
pom.properties 285B
pom.xml 4KB
application-pro.properties 655B
sto-realsystam-pushback.jar.original 24KB
sto-realsystam-pushback.jar 22.75MB
maven-archiver
pom.properties 164B
test-classes
.settings
org.eclipse.wst.common.project.facet.core.xml 145B
org.eclipse.m2e.core.prefs 90B
org.eclipse.jdt.core.prefs 243B
org.eclipse.core.resources.prefs 250B
pom.xml 4KB
.classpath 1KB
共 32 条
- 1
资源评论
- (>_<)2020-03-25就这点东西,你要4c币,都是一搜一大把的东西
- tlancs2020-06-17可以用,非常感谢分享!
- ekinchuoji2019-06-14需要使用这个,看看效果咋样。学习下,谢谢了。
天明少侠
- 粉丝: 68
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 2%EF%BC%9A%E9%99%95%E8%A5%BF%E
- yyspdz62_944.apk
- SAP公司间采购EDI配置-如何触发自动MIRO.docx
- python197基于图像识别的仪表实时监控系统.rar
- I2C驱动SHT30温湿度传感器和LCD12864使用例程(RSCG12864B)
- python193中学地理-中国的江河湖泊教学网(django).rar
- python191基于时间序列分析的大气污染预测软件(django).rar
- python190基于人脸识别智能化小区门禁管理系统.rar
- python189某医院体检挂号系统.rar
- python179的企业物流管理系统(django).rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功