EMQ使用

一.准备
Emqtt服务端下载: https://www.emqx.io/cn/downloads
测试工具: https://links.jianshu.com/go?to=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fworkswithweb%2Fmqttbox%2Flatest%2Fwindows%2FMQTTBox-win.exe
二.使用文档
https://docs.emqx.io/enterprise/latest/cn/getting-started/install-ee.html
三.Maven依赖
EMQ使用

org.springframework.boot
spring-boot-starter-integration


org.springframework.integration
spring-integration-stream


org.springframework.integration
spring-integration-mqtt

四.步骤
(1)Pom.xml
(2)Properties/yml
(3)配置mqtt消息推送配置类 @IntegrationComponentScan : 注解搜索指定的集成注解.,它将会扫描到使用@MessagingGateway注解的词条网关.
PS:Spring Integration是Spring项目中秉承其相同目标和原则的新成员。它扩展了Spring的编程模型到消息领域,在Spring已经存在的企业集成支持的基础上,提供了更高级别的抽象。它将控制反转添加到关注点,支持消息驱动架构,例如当特定业务逻辑应该执行时,响应也应该被发送。它支持路由和消息转换,所以不同的传输协议和不同的数据格式能在不影响易测试性的前提下被集成。换句话说,消息和集成关注点都被框架处理,所以业务组件能更好地与基础设施隔离,从而降低开发者所要面对的复杂的集成职责。
(4)配置消息接口 @MessagingGateway : 是一个用于提供消息网关代理整合的注解,参数defaultRequestChannel指定发送消息绑定的channel。 PS:一定要指定生产者通道名称

五.Android 与 Mqtt
(1)根目录下的build.gradle -->repositories { maven { url “https://repo.eclipse.org/content/repositories/paho-releases/” } }
(2)app目录下的build.gradle —> dependencies { compile ‘org.eclipse.paho:org.eclipse.paho.android.service:1.1.1’ compile ‘org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.1’ }
(3)权限 :



具体实现

Linux部署:
1.安装: shell脚本安装 —> curl https://repos.emqx.io/install_emqx.sh | bash
2.配置文件路径: /etc/emqx
PS: 遇到问题 ① Usage: emqx_ctl -->
修改emqx_management.conf文件中management.listener.http = ** 监听端口 为28080,重启EMQ,问题解决。
3.命令文件: /bin