从官方网站下载Apollo并安装在Mac OS X 10.10.2中,如主题Apollo 1.7 MQTT Protocol Manual所述,我在 apache-apollo-1.7 / bin / androidMQ中为mqtt设置了连接器/etc/apollo.xml:
<connector id="tcp" bind="tcp://0.0.0.0:61613" protocol="mqtt"/>
然后创建一个代理(androidMQ)并运行:
androidMQ/bin/apollo-broker run像这样的日志:
$ androidMQ/bin/apollo-broker run _____ .__ .__ / _ \ ______ ____ | | | | ____ / /_\ \\____ \ / _ \| | | | / _ \ / | \ |_> > ) |_| |_( ) \____|__ / __/ \____/|____/____/\____/ \/|__| Apache Apollo (1.7) Loading configuration file '/Users/jijin/services/apache-apollo-1.7/bin/androidMQ/etc/apollo.xml'. INFO | OS : Mac OS X 10.10.2 INFO | JVM : Java HotSpot(TM) 64-Bit Server VM 1.6.0_65 (Apple Inc.) INFO | Apollo : 1.7 (at: /Users/jijin/services/apache-apollo-1.7) INFO | OS is restricting the open file limit to: 6250 INFO | Starting store: leveldb store at /Users/jijin/services/apache-apollo-1.7/bin/androidMQ/data INFO | Accepting connections at: tcp://0.0.0.0:61613 INFO | Administration interface available at: https://127.0.0.1:61681/ INFO | Administration interface available at: http://127.0.0.1:61680/`
然后,我将它用于ruby gem:ruby-mqtt 我的剧本是:
subsctibe.rb
require 'rubygems'
require 'mqtt'
MQTT::Client.connect("localhost", 1883) do |client|
client.get("test") do |topic, message|
puts "#{topic}---content: #{message}\n"
end
end
publish.rb
require 'rubygems'
require 'mqtt'
MQTT::Client.connect("localhost", 1883) do |c|
c.publish("test", "gogogo!")
end
当我运行它时,错误:
$ ruby lib/mqtt/apollo_subscribe.rb /Users/jijin/.rvm/gems/ruby-1.9.3-p547/gems/mqtt-0.3.1/lib/mqtt/client.rb:496:in `block in receive_connack': Connection refused: bad user name or password (MQTT::ProtocolException) from /Users/jijin/.rvm/rubies/ruby-1.9.3-p547/lib/ruby/1.9.1/timeout.rb:69:in `timeout' from /Users/jijin/.rvm/gems/ruby-1.9.3-p547/gems/mqtt-0.3.1/lib/mqtt/client.rb:486:in `receive_connack' from /Users/jijin/.rvm/gems/ruby-1.9.3-p547/gems/mqtt-0.3.1/lib/mqtt/client.rb:277:in `connect' from /Users/jijin/.rvm/gems/ruby-1.9.3-p547/gems/mqtt-0.3.1/lib/mqtt/client.rb:93:in `connect' from lib/mqtt/apollo_subscribe.rb:4:in `'
当我将主机和端口更改为:
MQTT::Client.connect("test.mosquitto.org", 1883)
测试没问题,但是当我将主机更改为localhost时,无论我将端口更改为1883或61613,都会发生错误。 我现在不知道该怎么做。
答案 0 :(得分:3)
<!-- Uncomment to disable security for the virtual host -->
<authentication enabled="false"/>
也许我应该更仔细地阅读配置。