Announcement Announcement Module
Collapse
No announcement yet.
Connection refused exception in my consumer application Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Connection refused exception in my consumer application

    Hi

    I am using spring-rabbit 1.1.2.RELEASE version in my producer and consumer application.

    The producer application is working fine and can send messages to the rabbitmq queues without any issue. Bu tye consumer application having issues and print the below warning when the listener getting initialized.

    WARN [SimpleMessageListenerContainer] Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused

    When the consumer application starts, both rabbitmq servers are up and running and property values (server name, ports) and passed correctly.

    The spring config as below.
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:rabbit="http://www.springframework.org/schema/rabbit"
           xmlns:context="http://www.springframework.org/schema/context"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.1.xsd
           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    
        <context:property-placeholder location="file:/app/rabbitmq.properties" ignore-unresolvable="true" />
    
        <!-- Rabbit MQ connectivity -->
        <rabbit:connection-factory
                id="connectionFactory"
                addresses="${system.distributed.rabbitmq.host}"
                username="${system.distributed.rabbitmq.username}"
                password="${system.distributed.rabbitmq.password}"
                channel-cache-size="2" />
        <rabbit:admin connection-factory="connectionFactory"/>
    
        <bean id="jsonConverter" class="org.springframework.amqp.support.converter.JsonMessageConverter"/>
        <bean name="errorHandler" class="biz.hub.queue.RabbitErrorHandler"/>
        <bean id="jsonFactory" class="org.codehaus.jackson.JsonFactory"/>
    
        <rabbit:listener-container
                connection-factory="connectionFactory"
                message-converter="jsonConverter"
                concurrency="2"
                error-handler="errorHandler">
            <rabbit:listener ref="receiveListner" method="handleMessage" queue-names="${system.distributed.exchange.queue}"/>
        </rabbit:listener-container>
    
        <bean id="receiveListner" class="biz.hub.queue.ConsumerHandler">
            <constructor-arg ref="jsonFactory" />
        </bean>
    
    </beans>
    Could someone please help me to resolve this issue. Thanks.

  • #2
    java.net.ConnectException: Connection refused
    This is a low-level TCP exception that means that you are resolving to a host the does not have anything listening on the requested port. The SYN (socket open) is being rejected by the TCP stack on that host.

    So, it seems there is a problem with either the host or port configuration. In either case, you are hitting a real host because the error definitely means you reached a TCP stack where there's no such port listening.

    If you can't figure out your configuration problem, you can use a wire monitor such as WireShark, or tcpdump to take a look at the packets to see what port it's trying to connect to, and on which host.

    Comment


    • #3
      Thanks Gary for the quick reply. So that means my config file is correct, right ?

      Thanks again.

      Comment


      • #4
        Also this connection issue comes after I putting the listener configs to the bean xml. Problem is Producer connecting to the same rabbitmq cluster and it works fine.

        Also the telnet from consumer to the rabbitmq servers to port 5672 is fine.

        Any thoughts.

        Many thanks.

        Comment


        • #5
          Well, it looks ok, but I can't see your properties (and wouldn't know if they are correct if I could).

          I am not a fan of
          ignore-unresolvable="true"
          in a property-placeholder.

          It's usually better to fail fast.

          Comment


          • #6
            Hi Gary

            I tried without the ignore-unresolveable option in place holder configuration, but the result is same.

            Forgot to mention the properties in the first post and here they are:
            system.distributed.rabbitmq.host=app16,app17
            system.distributed.rabbitmq.username=<user name>
            system.distributed.rabbitmq.password=<password>
            system.distributed.exchange.name=messageexchange
            system.distributed.exchange.queue=hub_queue_ha

            Please have a look and comment if they are good.

            Also regarding the connection refuse issue, I used the rabbitmq java client and open a connection and it was success. Why this is not success with spring amqp listeners? Is spring amqp using special technique to build up the connection factory?

            Thanks

            /Roshan.

            Comment


            • #7
              I don't know if it's good because I don't know your environment.

              Like I said, you are getting a low-level TCP rejection (RST) to the SYN.

              This implies you are connecting to a host that is not listening on the default port.

              I don't think it's a problem parsing the addresses. There is nothing special done to
              build up the connection factory
              ; the addresses attribute is parsed by the underlying Rabbit Client
              Code:
              Address.parseAddresses()
              method.

              At this point, if you don't see anything interesting in DEBUG, or TRACE level logging, I suggest you use wireshark or tcpdump to trace the TCP activity to see what's going on.


              I just ran a test with similar configuration to yours and everything works fine

              Comment


              • #8
                Thanks Gary.

                I narrow down the problem and not a issue with TCP connections in my network. When building the connection factory I am using

                addresses="${system.distributed.rabbitmq.host}"
                The property value for the above are app16:5672,app17:5672 in my property file.

                String host = "app16:5672,app17:5672";
                Address[] add = Address.parseAddresses(host);
                The above address line is parsing fine with Address.parseAddresses() method.

                Seems there is problem when pass 2 or more hosts to addresses in connection factory, and it's fine with a single host and a port.


                Any thoughts??

                Thanks

                /Roshan
                Last edited by codevally; Sep 18th, 2012, 06:08 PM.

                Comment


                • #9
                  It's my mistake. I used spring-rabbit 1.0.0 version by mistake and all good with 1.1.2 version. Sorry about the post.

                  Thanks.

                  Comment

                  Working...
                  X