tomcat服务器依赖于rabbitmq服务器

时间:2017-12-21 12:43:50

标签: spring-mvc spring-amqp spring-rabbitmq

我将RabbitMQ服务器集成到我定制的spring-Amqp项目中,作为基于spring mvc Design的。我在xml中配置了所有配置。当RabbitMq服务器关闭时,我正在尝试启动我的应用程序,但是Tomcat服务器没有启动。     我想通过tomcat启动我的项目而不依赖于RabbitMq         我的配置是

     1. List item

    <rabbit:annotation-driven container-factory="rabbitListenerContainerFactory" />
        <!-- CREATE Queues -->
        <rabbit:queue name="queue.email" durable="true" auto-delete="false"/>
        <rabbit:queue name="queue.sms" durable="true" auto-delete="false"/>
        <rabbit:queue name="queue.newstatus" durable="true" auto-delete="false"/>
        <rabbit:queue name="queue.smsnew" durable="true" auto-delete="false" />
        <rabbit:topic-exchange name="exchange">
        <!--  <rabbit:bindings>
          <rabbit:binding pattern="topic" queue="queue.newstatus"/>
         </rabbit:bindings> -->
        </rabbit:topic-exchange>
        <rabbit:connection-factory 
                               id="connectionFactory" 
                               host="192.168.2.31"  
                               username="guest" 
                               password="guest" 
                               port="5672" 
                               channel-cache-size="100"
                               requested-heartbeat="30"/>
        <rabbit:admin connection-factory="connectionFactory"/>
        <!-- Template Creation -->
        <rabbit:template id="amqpTemplate" connection-factory="connectionFactory" exchange="exchange"/>
        <!-- Listener Creation -->
        <bean id="rabbitListenerContainerFactory" class="org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory">
            <property name="connectionFactory" ref="connectionFactory" />
            <property name="concurrentConsumers" value="30"/>
            <property name="maxConcurrentConsumers" value="50"/>
            <property name="prefetchCount" value="30"/>
            <property name="defaultRequeueRejected" value="false"/>
            <property name="autoStartup" value="true"/>
        </bean> 

        <rabbit:listener-container connection-factory="connectionFactory" recovery-interval="50000"   acknowledge="none" requeue-rejected="false">
         <rabbit:listener ref="rabbitListenerContainerFactory" queue-names="queue.email" />
         <rabbit:listener ref="rabbitListenerContainerFactory" queue-names="queue.sms" />
        </rabbit:listener-container>

我遇到了异常

    org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused: connect
        at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:62)
        at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:376)
        at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:573)
        at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1430)
        at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1411)
        at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1387)
        at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueProperties(RabbitAdmin.java:336)
        at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.redeclareElementsIfNecessary(SimpleMessageListenerContainer.java:1209)
        at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1470)
        at java.lang.Thread.run(Thread.java:745)
    Caused by: java.net.ConnectException: Connection refused: connect
        at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
        at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:579)
        at com.rabbitmq.client.impl.SocketFrameHandlerFactory.create(SocketFrameHandlerFactory.java:50)
        at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:907)
        at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:859)
        at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1000)
        at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:364)

任何人都可以帮我解决这个问题,谢谢你提前。

1 个答案:

答案 0 :(得分:0)

  

引起:java.net.ConnectException:连接被拒绝:连接

简单地表示代理不在侦听提供的主机/端口。

没有关系,但您似乎也完全误解了配置。

rabbit:annotation-driven适用于@RabbitListener POJO方法;您无法将工厂设置为<rabbit:listener/>元素中的监听器。