activemq mqtt(mqtt和mq的区别)

admin 457 0

大家好,今天给各位分享activemq mqtt的一些知识,其中也会对mqtt和mq的区别进行解释,文章篇幅可能偏长,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在就马上开始吧!

一、mqtt 服务器 哪个好 activemq rabbitmq mosquitto

2、找到相应系统的安装文件安装,如果不想做任何设置直接在服务里启动就行。

如果需要配置一些用户名、密码、用户权限的参数,则需要修改安装目录下的mosquitto.conf文件

下面来说说我用到的一些参数吧:

①用户密码:#password_file pwfile.example后面跟着是用户密码配置文件,需写上绝对路径并且路径不带空格

②创建用户密码:打开doc窗口,进入mosquitto安装目录,运行mosquitto_passwd-c pwfile.example userName回车,然后输入密码(密码输入两遍后,在该文件里会自动加密密码)

userName:$6$Ls7JYQTdn9xagJJ2$zngeT758n1Wn1hnVLjFdK2cHb6lcmI5CMrMTNZe2SqkUj0fBgKts62gvlyWYwdY3/WArx/SAtFRKlvKKnHRCUg==

userName2:$6$bymgVcrtj+7wj8mR$nq1atPD3nreRgA6gDbDjfbUGZIlrmenOcWrXMoneBp+zmAxnOybqJvrBZboxX1XXPnz/TKZwz9aKQJ72zJym5A=

③如果想再增加用户,则执行mosquitto_passwd-u pwfile.example userName2即可

④用户权限:#acl_file aclfile.example后面跟着是用户权限配置文件,需写上绝对路径并且路径

/usr/local/lib/python2.6/site-packages( mosquitto.py)

/usr/local/src/mosquitto-1.1.3/lib/python

yum-y install patch make gcc gcc-c++ gcc-g77 flex bison

centos5.6下 yum-y install gcc automake autoconf libtool make

yum-y install openssl openssl-devel vim-minimal

topic#(或+)表示可以读写任何主题

到这里用户密码及权限已配置完成,订阅和发布的时候加上用户名及密码即可验证:

client= new MqttClient("tcp://127.0.0.1:1883","java_client0000000000");

Myback callback= new Myback();

MqttConnectOptions conOptions= new MqttConnectOptions();

conOptions.setCleanSession(false);

conOptions.setUserName("userName");

conOptions.setPassword("pwd".toCharArray());

MqttClient client= new MqttClient("tcp://127.0.0.1:1883","mqttserver-pub");

MqttTopic topic= client.getTopic("主题");

MqttMessage message= new MqttMessage(topic.getName().getBytes());

MqttConnectOptions options= new MqttConnectOptions();

options.setUserName("userName");

options.setPassword("pwd".toCharArray());

二、activemq 持久化消息删除调用是什么方法

ActiveMQ的另一个问题就是只要是软件就有可能挂掉,挂掉不可怕,怕的是挂掉之后把信息给丢了,所以本节分析一下几种持久化方式:

ActiveMQ默认就支持这种方式,只要在发消息时设置消息为持久化就可以了。

D:\ActiveMQ\apache-activemq\conf\activemq.xml在越80行会发现默认的配置项:

<kahaDB directory="${activemq.data}/kahadb"/>

注意这里使用的是kahaDB,是一个基于文件支持事务的消息存储器,是一个可靠,高性能,可扩展的消息存储器。

他的设计初衷就是使用简单并尽可能的快。KahaDB的索引使用一个transaction log,并且所有的destination只使用一个index,有人测试表明:如果用于生产环境,支持1万个active connection,每个connection有一个独立的queue。该表现已经足矣应付大部分的需求。

然后再发送消息的时候改变第二个参数为:

PERSISTENT:保存到磁盘,consumer消费之后,message被删除。

NON_PERSISTENT:保存到内存,消费之后message被清除。

注意:堆积的消息太多可能导致内存溢出。

然后打开生产者端发送一个消息:

不启动消费者端,同时在管理界面查看:

发现有一个消息正在等待,这时如果没有持久化,ActiveMQ宕机后重启这个消息就是丢失,而我们现在修改为文件持久化,重启ActiveMQ后消费者仍然能够收到这个消息。

我们从支持Mysql为例,先从http://dev.mysql.com/downloads/connector/j/下载mysql-connector-java-5.1.34-bin.jar包放到:

D:\ActiveMQ\apache-activemq\lib目录下。

xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">

<!-- Allows us to use system properties as variables in this configuration file-->

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

<property name="locations">

<value>file:${activemq.conf}/credentials.properties</value>

<!-- Allows accessing the server log-->

<bean id="logQuery" class="org.fusesource.insight.log.log4j.Log4jLogQuery"

lazy-init="false" scope="singleton"

init-method="start" destroy-method="stop">

The<broker> element is used to configure the ActiveMQ broker.

<broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.data}">

<policyEntry topic=">">

<!-- The constantPendingMessageLimitStrategy is used to prevent

slow topic consumers to block producers and affect other consumers

by limiting the number of messages that are retained

http://activemq.apache.org/slow-consumer-handling.html

<pendingMessageLimitStrategy>

<constantPendingMessageLimitStrategy limit="1000"/>

</pendingMessageLimitStrategy>

The managementContext is used to configure how ActiveMQ is exposed in

JMX. By default, ActiveMQ uses the MBean server that is started by

the JVM. For more information, see:

http://activemq.apache.org/jmx.html

<managementContext createConnector="false"/>

Configure message persistence for the broker. The default persistence

mechanism is the KahaDB store(identified by the kahaDB tag).

http://activemq.apache.org/persistence.html

<kahaDB directory="${activemq.data}/kahadb"/>

<jdbcPersistenceAdapter dataDirectory="${activemq.base}/data" dataSource="#derby-ds"/>

The systemUsage controls the maximum amount of space the broker will

use before disabling caching and/or slowing down producers. For more information, see:

http://activemq.apache.org/producer-flow-control.html

<memoryUsage percentOfJvmHeap="70"/>

<storeUsage limit="100 gb"/>

<tempUsage limit="50 gb"/>

The transport connectors expose ActiveMQ over a given protocol to

clients and other brokers. For more information, see:

http://activemq.apache.org/configuring-transports.html

<!-- 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"/>

<!-- destroy the spring context on shutdown to stop jetty-->

<bean xmlns="http://www.springframework.org/schema/beans" class="org.apache.activemq.hooks.SpringContextHook"/>

<bean id="derby-ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">

<property name="driverClassName" value="com.mysql.jdbc.Driver"/>

<property name="url" value="jdbc:mysql://localhost/activemq?relaxAutoCommit=true"/>

<property name="username" value="root"/>

<property name="password" value=""/>

<property name="maxActive" value="200"/>

<property name="poolPreparedStatements" value="true"/>

Enable web consoles, REST and Ajax APIs and demos

The web consoles requires by default login, you can disable this in the jetty.xml file

Take a look at${ACTIVEMQ_HOME}/conf/jetty.xml for more details

<import resource="jetty.xml"/>

<!-- END SNIPPET: example-->

三、kafka和mqtt的区别是什么

1、kafka是分布式消息队列或者叫分布式消息中间件,有时候会叫做一种MQ产品(Message Queue),同类型的有RabbitMQ,ActiveMQ等等。

2、MQTT是一种即时消息传输协议,Message Queuing Telemetry Transport,也就是一种即时信息传输的一种格式约定,与其类似的有XMPP等,是用来做IM的。

3、kafka是不支持MQTT协议的,如果非要把它们集成在一起,你要不自己分析,要不去Github上找找,说不定有人做过这样的项目。

4、两个M的意思,是完全不一样的,kafka的M是指各个服务器或各个进程间传输的消息,而MQTT的M,是指类似MSN,QQ那种IM中那种大家交流的那种消息。

好了,文章到此结束,希望可以帮助到大家。