开源broker软件mosquitto(mqtt v3.1支持协议)
Really Small Message Broker(RSMB),是IBM提供的一个简单的代理。 rsmb_1.2.0.zip没有提供客户端连入broker的验证机制。
使用MQTT push消息这个方案,在这里被提出疑问。
为了安全考虑,在网上找解决方法,发现mqtt v3.1是支持验证等其他功能的。 后来发现一个开源的broker,而且是mqtt v3.1扩展的,问题解决。
下载地址:http:///download/
解压后:有mosquitto.exe和mosquitto-cygwin.exe 其中前者是vs 2008编译的,电脑如果缺少dll,无法运行。 后者mosquitto-cygwin.exe,本人运行OK。
其中有三个配置文件: mosquitto.conf aclfile.example pwfile.example
如果只运行mosquitto-cygwin.exe,不加参数,那配置文件是无法载入的, 即,运行的内容是默认设置。
如果需要使用配置文件中的参数, 需要在dos下加参数运行,例如: mosquitto-cygwin -c mosquitto.conf
为了验证是否已经使用配置, 可以先修改监听的端口号:port 1884 如果再界面中显示服务器监听的时1884端口,说明配置载入正确。
相关配置如下:
===================================
# Config file for mosquitto # # See mosquitto.conf(5) for more information. # # Default values are shown, uncomment to change. # # Use the # character to indicate a comment, but only if it is the # very first character on the line.
# ================================================================= # General configuration # =================================================================
# Time in seconds to wait before resending an outgoing QoS=1 or # QoS=2 message. #retry_interval 20
# Time in seconds between updates of the $SYS tree. #sys_interval 10
# Time in seconds between cleaning the internal message store of # unreferenced messages. Lower values will result in lower memory # usage but more processor time, higher values will have the # opposite effect. # Setting a value of 0 means the unreferenced messages will be # disposed of as quickly as possible. #store_clean_interval 10
# Write process id to a file. Default is a blank string which means # a pid file shouldn't be written. # This should be set to /var/run/mosquitto.pid if mosquitto is # being run automatically on boot with an init script and # start-stop-daemon or similar. #pid_file
# When run as root, drop privileges to this user and its primary # group. # Leave blank to stay as root, but this is not recommended. # If run as a non-root user, this setting has no effect. # Note that on Windows this has no effect and so mosquitto should # be started by the user you wish it to run as. #user mosquitto
# The maximum number of QoS 1 and 2 messages currently inflight per # client. # This includes messages that are partway through handshakes and # those that are being retried. Defaults to 10. Set to 0 for no # maximum. Setting to 1 will guarantee in-order delivery of QoS 1 # and 2 messages. #max_inflight_messages 10
# The maximum number of QoS 1 and 2 messages to hold in a queue # above those that are currently in-flight. Defaults to 100. Set # to 0 for no maximum (not recommended). #max_queued_messages 100
# ================================================================= # Default listener # =================================================================
# IP address/hostname to bind the default listener to. If not # given, the default listener will not be bound to a specific # address and so will be accessible to all network interfaces. # bind_address ip-address/host name #bind_address
# Port to use for the default listener. #port 1883
port 1884
# The maximum number of client connections to allow. This is # a per listener setting. # Default is -1, which means unlimited connections. # Note that other process limits mean that unlimited connections # are not really possible. Typically the default maximum number of # connections possible is around 1024. #max_connections -1
# ================================================================= # Extra listeners # =================================================================
# Listen on a port/ip address combination. By using this variable # multiple times, mosquitto can listen on more than one port. If # this variable is used and neither bind_address nor port given, # then the default listener will not be started. # The port number to listen on must be given. Optionally, an ip # address or host name may be supplied as a second argument. In # this case, mosquitto will attempt to bind the listener to that # address and so restrict access to the associated network and # interface. By default, mosquitto will listen on all interfaces. # listener port-number [ip address/host name] #listener
# The maximum number of client connections to allow. This is # a per listener setting. # Default is -1, which means unlimited connections. # Note that other process limits mean that unlimited connections # are not really possible. Typically the default maximum number of # connections possible is around 1024. #max_connections -1
# The listener can be restricted to operating within a topic hierarchy using # the mount_point option. This is achieved be prefixing the mount_point string # to all topics for any clients connected to this listener. This prefixing only # happens internally to the broker; the client will not see the prefix. #mount_point
# ================================================================= # Persistence # =================================================================
# If persistence is enabled, save the in-memory database to disk # every autosave_interval seconds. If set to 0, the persistence # database will only be written when mosquitto exits. # Note that writing of the persistence database can be forced by # sending mosquitto a SIGUSR1 signal. #autosave_interval 1800
# Save persistent message data to disk (true/false). # This saves information about all messages, including # subscriptions, currently in-flight messages and retained # messages. # retained_persistence is a synonym for this option. #persistence false
# The filename to use for the persistent database, not including # the path. #persistence_file mosquitto.db
# Location for persistent database. Must include trailing / # Default is an empty string (current directory). # Set to /var/lib/mosquitto/ if running as a proper service. #persistence_location
# ================================================================= # Logging # =================================================================
# Places to log to. Use multiple log_dest lines for multiple # logging destinations. # Possible destinations are: stdout stderr syslog topic # stdout and stderr log to the console on the named output. # syslog uses the userspace syslog facility which usually ends up # in /var/log/messages or similar. # topic logs to the broker topic '$SYS/broker/log/<severity>', # where severity is one of D, E, W, N, I which are debug, error, # warning, notice and information. # Use "log_dest none" if you wish to disable logging. #log_dest stderr
# Types of messages to log. Use multiple log_type lines for logging # multiple types of messages. # Possible types are: debug, error, warning, notice, information, # none. # Note that debug type messages are for decoding the incoming # network packets. # They are not logged in syslog. #log_type error #log_type warning #log_type notice #log_type information
# ================================================================= # Security # =================================================================
# If set, only clients that have a matching prefix on their # clientid will be allowed to connect to the broker. By default, # all clients may connect. # For example, setting "secure-" here would mean a client "secure- # client" could connect but another with clientid "mqtt" couldn't. #clientid_prefixes clientid_prefixes pig-
# Boolean value that determines whether clients that connect # without providing a username are allowed to connect. If set to # false then a password file should be created (see the # password_file option) to control authenticated client access. # Defaults to true. #allow_anonymous true
# Control access to the broker using a password file. The file is a # text file # of lines in the format: # username:password # The password (and colon) may be omitted if desired, although this # offers very little in the way of security. #password_file
# Control access to topics on the broker using an access control list # file. If this parameter is defined then only the topics listed will # have access. # Topic access is added with lines of the format: # # topic [read|write] <topic> # # The access type is controlled using "read" or "write". This parameter # is optional - if not given then the access is read/write. # <topic> can contain the + or # wildcards as in subscriptions. # # The first set of topics are applied to anonymous clients, assuming # allow_anonymous is true. User specific topic ACLs are added after a # user line as follows: # # user <username> # # The username referred to here is the same as in password_file. It is # not the clientid. # #acl_file
# ================================================================= # Bridges # =================================================================
# Experimental support for connecting multiple MQTT brokers # together. # Specify multiple sets of connection, address and topic # configurations. # Each connection must have a unique name. # Only a single address per configuration is currently supported, # unlike in rsmb. # The direction that the topic will be shared can be chosen by # specifying out, in or both, where the default value is out. # Multiple topics can be specified per connection, but be careful # not to create any loops. #connection <name> #address <host>[:<port>] #topic <topic> [out | in | both]
# Set the client id for this bridge connection. If not defined, # this defaults to 'name.hostname' where name is the connection # name and hostname is the hostname of this computer. #clientid
# Set the clean session variable for this bridge. # When set to true, when the bridge disconnects for any reason, all # messages and subscriptions will be cleaned up on the remote # broker. Note that with cleansession set to true, there may be a # significant amount of retained messages sent when the bridge # reconnects after losing its connection. # When set to false, the subscriptions and messages are kept on the # remote broker, and delivered when the bridge reconnects. #cleansession false
# Set the keepalive interval for this bridge connection, in # seconds. #keepalive_interval 60
# Set the username to use when connecting to an MQTT v3.1 broker # that requires authentication. #username
# Set the password to use when connecting to an MQTT v3.1 broker # that requires authentication. This option is only used if # username is also set. #password
# ================================================================= # External security checks # =================================================================
# This section defines options for potential use with external # databases. # They are intended to make it easier to add external security # checks along with WITH_EXT_SECURITY_CHECKS. If you haven't written # code to support another database and compiled support in, you are # unlikely to need to change anything here.
# Database hostname. #db_host
# Database port. #db_port
# Database name. #db_name
# Database username. #db_username
# Database password. #db_password
# ================================================================= # Unsupported rsmb options - for the future # =================================================================
#autosave_on_changes #connection_messages #addresses #idle_timeout #notifications #notification_topic #round_robin #start_type #threshold
# ================================================================= # rsmb options - unlikely to ever be supported # =================================================================
#ffdc_output #max_log_entries #trace_level #trace_output #try_private
|