3

我有两台流浪机器。第一个名为“web”,包含一个小型 Rub​​y 应用程序,第二个名为“mq”,安装了 ActiveMQ。我无法将我的应用程序与 ActiveMQ 连接起来。

流浪者配置文件:

config.vm.define :web do |web_config|
    web_config.vm.network("33.33.33.10")
    web_config.vm.box = "lucid32"
    config.ssh.forwarded_port_key = "ssh"
    config.vm.forward_port("ssh", 22, 2223)
    web_config.vm.forward_port "http", 3000, 3000
end

config.vm.define :mq do |mq_config|
    mq_config.vm.network("33.33.33.50")
    mq_config.vm.box = "lucid32"
    config.ssh.forwarded_port_key = "ssh"
    config.vm.forward_port("ssh", 22, 2223)
    mq_config.vm.forward_port "activemq", 8161, 8161
    mq_config.vm.forward_port "stomp", 61613, 61613
end

我的 Ruby Stomp 应用程序位于我的“网络”机器上:

require "rubygems"
require 'stomp'

hash = {
    :hosts => [
      {:login => "", :passcode => "", :host => "33.33.33.50", :port => 61613, :ssl => false}]}
queue = "/queue/test"
client = Stomp::Client.new()
client.subscribe queue do | message |
    puts "#{message}"
end
client.join

ActiveMQ 配置文件 ( activemq.xml):

<!-- Allows us to use system properties as variables in this configuration file -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>

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

    <!-- Destination specific policies using destination names or wildcards -->
    <destinationPolicy>
        <policyMap>
            <policyEntries>
                <policyEntry queue=">" memoryLimit="5mb"/>
                <policyEntry topic=">" memoryLimit="5mb">
                    <dispatchPolicy>
                        <strictOrderDispatchPolicy/>
                    </dispatchPolicy>
                    <subscriptionRecoveryPolicy>
                        <lastImageSubscriptionRecoveryPolicy/>
                    </subscriptionRecoveryPolicy>
                </policyEntry>
            </policyEntries>
        </policyMap>
    </destinationPolicy>

    <!-- Use the following to configure how ActiveMQ is exposed in JMX -->
    <managementContext>
        <managementContext createConnector="true"/>
    </managementContext>

    <persistenceAdapter>
        <amqPersistenceAdapter syncOnWrite="false" directory="${activemq.base}/data" maxFileLength="20 mb"/>
    </persistenceAdapter>

<sslContext>
        <sslContext keyStore="file:${activemq.base}/conf/broker.ks" keyStorePassword="password" trustStore="file:${activemq.base}/conf/broker.ts"   trustStorePassword="password"/>
    </sslContext>

    <!--  The maximum about of space the broker will use before slowing down producers -->
    <systemUsage>
        <systemUsage>
            <memoryUsage>
                <memoryUsage limit="20 mb"/>
            </memoryUsage>
            <storeUsage>
                <storeUsage limit="1 gb" name="foo"/>
            </storeUsage>
            <tempUsage>
                <tempUsage limit="100 mb"/>
            </tempUsage>
        </systemUsage>
    </systemUsage>


    <!-- The transport connectors ActiveMQ will listen to -->
    <transportConnectors>
        <transportConnector name="openwire" uri="tcp://0.0.0.0:61616" />
        <transportConnector name="ssl" uri="ssl://0.0.0.0:61617" />
        <transportConnector name="stomp" uri="stomp://0.0.0.0:61613" />
        <transportConnector name="xmpp" uri="xmpp://0.0.0.0:61222" />
    </transportConnectors>

</broker>

<!-- An embedded servlet engine for serving up the Admin console -->
<jetty xmlns="http://mortbay.com/schemas/jetty/1.0">
    <connectors>
        <nioConnector port="8161"/>
    </connectors>

    <handlers>
        <webAppContext contextPath="/admin" resourceBase="${activemq.base}/webapps/admin" logUrlOnStart="true"/>
        <webAppContext contextPath="/demo" resourceBase="${activemq.base}/webapps/demo" logUrlOnStart="true"/>
        <webAppContext contextPath="/fileserver" resourceBase="${activemq.base}/webapps/fileserver" logUrlOnStart="true"/>
    </handlers>
</jetty>

机器可以相互通信。

从机器“网络”:

vagrant@lucid32:/vagrant$ ping 33.33.33.50
PING 33.33.33.50 (33.33.33.50) 56(84) bytes of data.
64 bytes from 33.33.33.50: icmp_seq=1 ttl=64 time=0.479 ms
64 bytes from 33.33.33.50: icmp_seq=2 ttl=64 time=0.726 ms
64 bytes from 33.33.33.50: icmp_seq=3 ttl=64 time=0.687 ms

从机器“mq”:

vagrant@lucid32:~$ ping 33.33.33.10
PING 33.33.33.10 (33.33.33.10) 56(84) bytes of data.
64 bytes from 33.33.33.10: icmp_seq=1 ttl=64 time=0.383 ms
64 bytes from 33.33.33.10: icmp_seq=2 ttl=64 time=0.856 ms
64 bytes from 33.33.33.10: icmp_seq=3 ttl=64 time=0.660 ms

最后,当我尝试执行应用程序时,出现此错误:

vagrant@lucid32:/vagrant$ ruby stomp_client.rb 
/home/vagrant/.rvm/gems/ruby-1.9.2-p290/gems/stomp-1.1.9/lib/stomp/connection.rb:481:in `initialize': Connection refused - connect(2) (Errno::ECONNREFUSED)
    from /home/vagrant/.rvm/gems/ruby-1.9.2-p290/gems/stomp-1.1.9/lib/stomp/connection.rb:481:in `open'
    from /home/vagrant/.rvm/gems/ruby-1.9.2-p290/gems/stomp-1.1.9/lib/stomp/connection.rb:481:in `open_tcp_socket'
    from /home/vagrant/.rvm/gems/ruby-1.9.2-p290/gems/stomp-1.1.9/lib/stomp/connection.rb:522:in `open_socket'
    from /home/vagrant/.rvm/gems/ruby-1.9.2-p290/gems/stomp-1.1.9/lib/stomp/connection.rb:120:in `block in socket'
    from <internal:prelude>:10:in `synchronize'
    from /home/vagrant/.rvm/gems/ruby-1.9.2-p290/gems/stomp-1.1.9/lib/stomp/connection.rb:113:in `socket'
    from /home/vagrant/.rvm/gems/ruby-1.9.2-p290/gems/stomp-1.1.9/lib/stomp/connection.rb:89:in `initialize'
    from /home/vagrant/.rvm/gems/ruby-1.9.2-p290/gems/stomp-1.1.9/lib/stomp/client.rb:94:in `new'
    from /home/vagrant/.rvm/gems/ruby-1.9.2-p290/gems/stomp-1.1.9/lib/stomp/client.rb:94:in `initialize'
    from stomp_client.rb:28:in `new'
    from stomp_client.rb:28:in `<main>'
4

1 回答 1

2

您似乎忘记将哈希传递给 Stomp::Client.new() 方法,因此它默认为 localhost。

它应该如下所示:

client = Stomp::Client.new(hash)
于 2012-12-27T19:22:12.347 回答