mqtt和activemq(MQTT和ActiveMQ有什么区别)

:暂无数据 2026-08-13 21:30:07 0

mqtt和activemq(MQTT和ActiveMQ有什么区别)

大家好,mqtt和activemq相信很多的网友都不是很明白,包括MQTT和ActiveMQ有什么区别也是一样,不过没有关系,接下来就来为大家分享关于mqtt和activemq和MQTT和ActiveMQ有什么区别的一些知识点,大家可以关注收藏,免得下次来找不到哦,下面我们开始吧!

本文目录

MQTT和ActiveMQ有什么区别

  MQTT只是IBM推出的一个消息协议,基于TCP/IP的。两个App端发送和接收消息需要中间人,这个中间人就是消息服务器(比如ActiveMQ/RabbitMQ),三者通信协议就是MQTT。
  wmqtt.jar是IBM实现的App端收发消息的具体实现,W意思为Webspare,说明消息服务器采用Webspare(WebSphere MQ Integrator Broker)。

Flutter通过Mqtt消费ActivieMQ

Flutter通过mqtt消费activemq,在android端主要使用插件的方式进行

处理流程

Android端连接MQTT

插件端业务处理

step1:配置插件依赖包

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    implementation ’com.google.code.gson:gson:2.8.5’

    implementation ’org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0’

    implementation ’org.eclipse.paho:org.eclipse.paho.android.service:1.1.1’

    implementation ’androidx.legacy:legacy-support-v4:1.0.0’

    implementation ’androidx.appcompat:appcompat:1.1.0-rc01’

    implementation ’androidx.constraintlayout:constraintlayout:1.1.3’

    implementation ’androidx.recyclerview:recyclerview:1.0.0’

    implementation ’androidx.multidex:multidex:2.0.1’

    implementation ’androidx.multidex:multidex-instrumentation:2.0.0’

    implementation ’com.google.android.material:material:1.1.0-alpha08’

step2 实现连接方法

class MqttClientPlugin : MethodCallHandler {

    override fun onMethodCall(call: MethodCall,    result: Result) {

        when (call.method) {

            "connectMq" -》 {

                    try {

                        connectToService()

                        result.success(true)

                    } catch (e: Exception) {

                        e.printStackTrace()

                        result.success(false)

                    }

                }

        }

    }

    private fun connectToService() {

        val intent = Intent(context, MqttClientService::class.java)

        this.context?.startService(intent)

    }

}

step3 实现mqttclient服务

class MqTTClientService : Service {

    private val TAG = "ActiveMQ"

    val clientId = "any_client_name"

    val serverURI = "tcp://192.168.0.201:1883" //replace with your ip

    val publishTopic = "outbox"

    val subscribeTopic = "TJ Test"

    var client: MqttAndroidClient? = null

    constructor() : super()

    val MY_ACTION = "MY_ACTION"

    var _currentV: Int = 0

    override fun onBind(intent: Intent?): IBinder? {

        return null

    }

    override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {

        val myThread = MyThrad()

        myThread.start()

        return super.onStartCommand(intent, flags, startId)

    }

    private fun subscribe() {

        try {

            client?.subscribe(subscribeTopic, 0, IMqttMessageListener { topic, message -》

                Log.i("接收到监听的消息:", "${message.payload}")

            })

        } catch (e: MqttException) {

            e.printStackTrace()

        }

    }

    inner class MyThrad : Thread() {

        override fun run() {

            val connectOptions = MqttConnectOptions()

            connectOptions.isAutomaticReconnect = true

            client = MqttAndroidClient(this@MqTTClientService.applicationContext, serverURI, clientId)

            try {

                client?.connect(connectOptions, object : IMqttActionListener {

                    override fun onSuccess(asyncActionToken: IMqttToken) {

                        subscribe()

                    }

                    override fun onFailure(asyncActionToken: IMqttToken, e: Throwable) {

                        Log.i("连接错误:", "${e.message}")

                    }

                })

            } catch (e: MqttException) {

                e.printStackTrace()

            }

        }

        private fun subscribe() {

            try {

                client?.subscribe(subscribeTopic, 0) { topic, message -》

                    //通过广播发送监听到的消息

                    val intent = Intent()

                    intent.action = MY_ACTION

                    intent.putExtra("DATAPASSED", message.toString())

                    sendBroadcast(intent)

                }

            } catch (e: MqttException) {

                e.printStackTrace()

            }

        }

    }

}

step4监听广播

class DevicemanagerPlugin : MethodCallHandler {

    constructor(context: Context?, channel: MethodChannel) {

            this.context = context

            this.channel = channel

            initMqtt()

            register()

        }

    private fun register() {

            myReceiver = MyReceiver()

            val intentFilter = IntentFilter()

            intentFilter.addAction("MY_ACTION")

            this.context?.registerReceiver(myReceiver, intentFilter)

        }

    inner class MyReceiver : BroadcastReceiver() {

        override fun onReceive(context: Context?, intent: Intent?) {

            try {

                val value = intent?.getStringExtra("DATAPASSED")

                //将监听到的消息,通过methchannel传给flutter

                channel?.invokeMethod("receiveMsg", value)

            } catch (e: Exception) {

                e.printStackTrace()

            }

        }

    }   

}

Flutter端业务处理

实现receiveMsg方法

const channel = const MethodChannel("mqttclient");

class _MyHomePageState extends State《MyHomePage》 {

    @override

  void initState() {

      registerMethod()

      connectActiveMq()

  }

  void connectActiveMq() async{

    if (Platform.isAndroid) {

      var result = await Devicemanager.connectMq(API.MQ_URI);

      if (result) {

        print("mq链接成功");

      } else {

        print("mq链接失败");

      }

    }

  }

  void registerMethod() {

    channel.setMethodCallHandler((handler) {

      var completer = new Completer《String》();

      try {

        switch (handler.method) {

          case "receiveMsg":

            //接收到的消息

            var v = handler.arguments;

            break;

          default:

            break;

        }

      } catch (e) {

        print(e);

      }

      return completer.future;

    });

  }

}

MQTT和ActiveMQ有什么区别wmqtt.jar和mqttv3.jar又有什么区别

ActiveMQ 这个也没有研究过,最近打算弄个聊天所以也看了下MQTT,不过也是一头雾水,看到有些人是使用 Mosquitto:An Open Source MQTT v3.1 Broker 做的(broker)代理,好像这个更简单一点儿,
还有的是用:MQTT的学习研究(二)moquette-mqtt 的使用之mqtt broker的启动
如果你只是需要推送功能的话,可以使用第三方的推送试试,比如极光,百度等,有好多的
我的理解是:MQTT他只是定义了一种通讯协议,给我们封装好了一些socket连接,让我们方便调用,像 Mosquitto 和ActiveMQ只是基于这个协议实现的代理,而wmqtt.jar 是在移动端实现接收和发送消息的接口供我们调用!

各位,activemq可以限制客户端连接数吗

可以 生产者和消费者可以使用不同的传输协议来传输消息,ActiveMQ提供了广泛的连接模式,包括HTTP/S、JGroups、JXTA、muticast、SSL、TCP、UDP、XMPP等。
《transportConnectors》 《!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB --》 《transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/》 《transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/》 《transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/》 《transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/》 《transportConnector name="ws" uri="ws://0.0.0.0:61614?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/》 《/transportConnectors》
可以看出最大连接数是1000,最大容量是100m

OK,关于mqtt和activemq和MQTT和ActiveMQ有什么区别的内容到此结束了,希望对大家有所帮助。

mqtt和activemq(MQTT和ActiveMQ有什么区别)

本文编辑:admin

更多文章:


数据库管理系统和数据库系统分别侧重(数据库,数据库管理系统,数据库系统,这三个分别是什么意思并举个实例)

数据库管理系统和数据库系统分别侧重(数据库,数据库管理系统,数据库系统,这三个分别是什么意思并举个实例)

今天给各位分享数据库,数据库管理系统,数据库系统,这三个分别是什么意思并举个实例的知识,其中也会对数据库,数据库管理系统,数据库系统,这三个分别是什么意思并举个实例进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

2026年9月7日 17:00

编程语言出现的先后顺序(最早的编程语言是哪一个)

编程语言出现的先后顺序(最早的编程语言是哪一个)

今天给各位分享最早的编程语言是哪一个的知识,其中也会对最早的编程语言是哪一个进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

2026年9月7日 16:10

小程序源码有什么用(大商创小程序源码好用吗)

小程序源码有什么用(大商创小程序源码好用吗)

“小程序源码有什么用”相关信息最新大全有哪些,这是大家都非常关心的,接下来就一起看看小程序源码有什么用(大商创小程序源码好用吗)!

2026年9月7日 15:40

springmvc的依赖(springMVC的注入方式有哪几种,这与springMVC依赖)

springmvc的依赖(springMVC的注入方式有哪几种,这与springMVC依赖)

大家好,关于springmvc的依赖很多朋友都还不太明白,不过没关系,因为今天小编就来为大家分享关于springMVC的注入方式有哪几种,这与springMVC依赖的知识点,相信应该可以解决大家的一些困惑和问题,如果碰巧可以解决您的问题,还

2026年9月7日 14:00

it培训评价网(it培训排名机构十大IT培训机构)

it培训评价网(it培训排名机构十大IT培训机构)

这篇文章给大家聊聊关于it培训评价网,以及it培训排名机构十大IT培训机构对应的知识点,希望对各位有所帮助,不要忘了收藏本站哦。

2026年9月7日 13:00

个人博客页面布局(新手站长怎样做好独立博客初期运营工作)

个人博客页面布局(新手站长怎样做好独立博客初期运营工作)

大家好,如果您还对个人博客页面布局不太了解,没有关系,今天就由本站为大家分享个人博客页面布局的知识,包括新手站长怎样做好独立博客初期运营工作的问题都会给大家分析到,还望可以解决大家的问题,下面我们就开始吧!

2026年9月7日 12:40

display flex 自动换行(overflow-y:hidden;overflow-x:auto;无效解决方法)

display flex 自动换行(overflow-y:hidden;overflow-x:auto;无效解决方法)

大家好,关于display flex 自动换行很多朋友都还不太明白,不过没关系,因为今天小编就来为大家分享关于overflow-y:hidden;overflow-x:auto;无效解决方法的知识点,相信应该可以解决大家的一些困惑和问题,如

2026年9月7日 11:00

小程序免认证源码(小程序源码都能干嘛)

小程序免认证源码(小程序源码都能干嘛)

本篇文章给大家谈谈小程序免认证源码,以及小程序源码都能干嘛对应的知识点,文章可能有点长,但是希望大家可以阅读完,增长自己的知识,最重要的是希望对各位有所帮助,可以解决了您的问题,不要忘了收藏本站喔。

2026年9月7日 10:50

timestamp without time zone(Postgresql中to_date()函数使用问题)

timestamp without time zone(Postgresql中to_date()函数使用问题)

各位老铁们好,相信很多人对timestamp without time zone都不是特别的了解,因此呢,今天就来为大家分享下关于timestamp without time zone以及Postgresql中to_date()函数使用问题

2026年9月7日 09:40

网页制作代码特效大全(谁知道网页打字机特效的代码)

网页制作代码特效大全(谁知道网页打字机特效的代码)

大家好,如果您还对网页制作代码特效大全不太了解,没有关系,今天就由本站为大家分享网页制作代码特效大全的知识,包括谁知道网页打字机特效的代码的问题都会给大家分析到,还望可以解决大家的问题,下面我们就开始吧!

2026年9月7日 04:20

最近更新

创业加盟网1688(怎样考察加盟店)
2026-09-07 17:50:14 浏览:0
热门文章

yoga pro 14s carbon(yoga14s接口类型)
2026-07-03 17:50:01 浏览:5
domino directory(帮我翻译一下Recipient’s Domino Directory entry does not specify a valid Notes mail file)
2026-08-03 19:20:01 浏览:4
标签列表