一:服务器端

为什么使用mosca:mosca是基于node.js开发,上手难度相对较小,其次协议支持完整,除了不支持Qos 2,其它的基本都支持。持久化支持redis以及mongo。二次开发接口简单。部署非常简单,并且支持docker镜像。

mosca参数简介:

var mosca = require('mosca')

ascoltatore :  是Mosca作者开发的一个订阅与发布类库,Mosca核心的订阅与发布模型

var ascoltatore = {
type: 'redis', //指定类型,mongo的写法请参考官方wiki
redis: require('redis'),
db: ,
port: ,
return_buffers: true, // to handle binary payloads
//指定数据保留多长时间,单位毫秒
     ttl: {
// TTL for subscriptions is 23 hour
subscriptions: * * * ,
       // TTL for packets is 23 hour
packets: * * * ,
},
host: "localhost"
};

//基本参数设置

var moscaSettings = {
port: , //设置监听端口
backend: ascoltatore,
maxInflightMessages: , //设置单条消息的最大长度,超出后服务端会返回
    //设置WebSocket参数
    http: {
      port: ,
      bundle: true,
      static: './' },
      //数据持久化参数设置
      persistence: {
         factory: mosca.persistence.Redis,
         db: ,
         port: ,
         return_buffers: true, // to handle binary payloads
         ttl: {
// TTL for subscriptions is 23 hour
subscriptions: * * * ,
// TTL for packets is 23 hour
packets: * * * , },
              host: "localhost"
}
     }

//如果需要用户登录验证权限,需要改写此方法

//这里以简单判断了用户名和密码为例,真实环境可以连接实际业务系统的鉴权服务 

var authenticate = function(client, username, password, callback) {
    var authorized = (username === 'test' &;&; password.toString() === 'passwd');
    if (authorized) client.user = username;
    callback(null, authorized);
 } function authPub(client, topic, payload, callback) {
   callback(null, payload);
} function authSub(client, topic, callback) {
   callback(null, topic);
} var server = new mosca.Server(moscaSettings);
server.on('ready', setup);
server.on('clientConnected', function(client) {
    console.log('client connected', client.id);
});
server.on('published', function(packet, client) {
    console.log('Published', packet.topic + packet.payload);
}); // fired when the mqtt server is ready
function setup() {
   server.authenticate = authenticate;
   server.authorizePublish = authPub;
   server.authorizeSubscribe = authSub;
   console.log('Mosca server is up and running')
}

二次开发可以监听的事件列表

clientConnected: when a client is connected; the client is passed as a parameter.

clientDisconnecting: when a client is being disconnected; the client is passed as a parameter.

clientDisconnected: when a client is disconnected; the client is passed as a parameter.

published: when a new message is published; the packet and the client are passed as parameters.

delivered: when a client has sent back a puback for a published message; the packet and the client are passed as parameters.

subscribed: when a client is subscribed to a topic; the topic and the client are passed as parameters.

unsubscribed: when a client is unsubscribed to a topic; the topic and the client are passed as parameters.

有了上面可以监听到事件你就可以根据自己的业务进行相应的开发,拦截特定的事件并添加业务代码

ascoltatore托管地址 https://github.com/mcollina/ascoltatori

高级参数设置可以参考 https://github.com/mcollina/mosca/wiki/Mosca-advanced-usage

权限验证可以参考 https://github.com/mcollina/mosca/wiki/Authentication-&;-Authorization

配置ssl可以参考 https://github.com/mcollina/mosca/wiki/TLS-SSL-Configuration

配置WebSocket可以参考 https://github.com/mcollina/mosca/wiki/MQTT-over-Websockets

mqtt------ mosca服务器端参数简介的更多相关文章

  1. 【ABAP系列】SAP abap dialog screen屏幕参数简介

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP abap dialog ...

  2. Mqtt使用教程,简介

    1,简介 MQTT协议(Message Queuing Telemetry Transport),翻译过来就是遥信消息队列传输,是IBM公司于1999年提出的,现在最新版本是3.1.1.MQTT是一个 ...

  3. Tomcat性能调优参数简介

    近期,我们的一个项目进入了试运营的阶段,在系统部署至阿里云之后,我们发现整个系统跑起来还是比较慢的,而且,由于代码的各种不规范,以及一期进度十分赶的原因,缺少文档和完整的测试,整个的上线过程一波三折. ...

  4. Linux 内核引导参数简介

    概述 内核引导参数大体上可以分为两类:一类与设备无关.另一类与设备有关.与设备有关的引导参数多如牛毛,需要你自己阅读内核中的相应驱动程序源码以获取其能够接受的引导参数.比如,如果你想知道可以向 AHA ...

  5. HOG参数简介及Hog特征维数的计算(转)

    HOG构造函数 CV_WRAP HOGDescriptor() :winSize(64,128), blockSize(16,16), blockStride(8,8),      cellSize( ...

  6. VM参数简介

    http://www.cnblogs.com/yuzhaoxin/p/4083612.html block_dump Linux 内核里提供了一个 block_dump 参数用来把 block 读写( ...

  7. 【转载】va_list 可变参数 简介 va_copy vprintf

    [说明]本文转载自 smart 的文章 http://blog.sina.com.cn/s/blog_590be5290100qhxr.html  及百度百科 va_list是一个宏,由va_star ...

  8. vue路由对象($route)参数简介

    路由对象在使用了 vue-router 的应用中,路由对象会被注入每个组件中,赋值为 this.$route ,并且当路由切换时,路由对象会被更新. so , 路由对象暴露了以下属性: 1.$rout ...

  9. Flask 参数简介

    我们都知道学习了Flask的时候它里面的参数是有很多种的参数  都是需要相互进行调用传递的  今天就简要分析一些常见的参数 首先导入Flask之后看 源码 from flask import Flas ...

随机推荐

  1. Jmeter学习之-http接口功能测试-入门

    ps:默认已经安装好Jmeter工具,配置好相关环境 打开jmeter 工具,为测试计划重新命名 添加线程组:在测试计划上右键,依次选择“添加>Threads>线程组” 添加http请求: ...

  2. mysql报错Ignoring the redo log due to missing MLOG_CHECKPOINT between

    mysql报错Ignoring the redo log due to missing MLOG_CHECKPOINT between mysql版本:5.7.19 系统版本:centos7.3 由于 ...

  3. python基础之 基本数据类型,str方法和for循环

    1.概念 1.十进制转二进制,对2取余,余数倒序排列 2.字符串为空的时候,bool值为false,字符串非空就是True3.字符串转化成int时,必须是只包含数字才能转化.4.字符串转化成int时可 ...

  4. Python 总结

    python3.7下载地址 Python安装pip 1.首先检查linux有没有安装python-pip包,直接执行 yum install python-pip 2.没有python-pip包就执行 ...

  5. ORACLE——存储过程

    存储过程procedure 被内容来自<oracle从入门到精通——明日科技>一书 存储过程是一种命名的PL/SQL程序快,存储过程被保存在数据库中,它不可以被SQL语句直接执行或调用,只 ...

  6. Centos安装Oracle及问题处理

    安装Oracle前准备 创建运行oracle数据库的系统用户和用户组 [jonathan@localhost ~]$ su root #切换到root Password: [root@localhos ...

  7. 微信OpenID获取

    用户要求在微信端登录一次后,以后不需要再登录.  我的系统是单独的一个网站. 使用MVC的记住密码功能, 如果用户重启,就还是要输入密码,所以需要有一个唯一不变的用来标示用户的ID.  OpenID就 ...

  8. How Many Triangles (极角排序 + 尺取法)

    题意:二维平面与有很多个点,然后求构成锐角三角形的个数. 思路:对于每一个三角形我们知道存在至少2个锐角,只要有一个钝角就不行了,所以我们的想法就是枚举所有夹角的状态,然后得知情况,确定用总个数减去- ...

  9. 时间序列预测——Tensorflow.Keras.LSTM

    1.测试数据下载 https://datamarket.com/data/set/22w6/portland-oregon-average-monthly-bus-ridership-100-janu ...

  10. AARRR海盗模型简介

    整理下AARRR模型的概念.实际应用场景等问题,初步感觉这个模型主要应用在APP应用分析中. 1.什么是AARRR模型 AARRR是Acquisition.Activation.Retention.R ...