Почему STOMP, ActiveMQ и Vagrant не работают в моей системе? - PullRequest
3 голосов
/ 31 декабря 2011

У меня есть две бродячие машины. Первый называется web, который содержит небольшое приложение на Ruby, а второй - mq с установленным ActiveMQ. Я не могу подключить свое приложение к ActiveMQ.

Файл конфигурации Vagrant:

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>'

1 Ответ

2 голосов
/ 27 декабря 2012

Кажется, вы забыли передать свой хэш методу Stomp :: Client.new (), поэтому по умолчанию используется localhost.

Он должен выглядеть следующим образом:

client = Stomp::Client.new(hash)
...