Cloudfoundry RabbitMQ -Connection refused
Hi
I am getting following Stack error when i try to connect RabbitMQ,
My configuration :
<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"
xsi:schemaLocation="http://www.springframework.org/schema/rabbit http://www.springframework.org/schem...rabbit-1.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<rabbit:connection-factory id="rabbitConnectionFactory" />
<rabbit:template id="amqpTemplate" connection-factory="rabbitConnectionFactory" />
<rabbit:admin connection-factory="rabbitConnectionFactory" />
<rabbit:queue name="myqueue" />
</beans>
================================================== ================================================== ==
Error stack :
java.net.ConnectException: Connection refused
org.springframework.amqp.rabbit.connection.RabbitU tils.convertRabbitAccessException(RabbitUtils.java :106)
org.springframework.amqp.rabbit.connection.Abstrac tConnectionFactory.createBareConnection(AbstractCo nnectionFactory.java:118)
org.springframework.amqp.rabbit.connection.Caching ConnectionFactory.createConnection(CachingConnecti onFactory.java:179)
org.springframework.amqp.rabbit.connection.Connect ionFactoryUtils$1.createConnection(ConnectionFacto ryUtils.java:77)
org.springframework.amqp.rabbit.connection.Connect ionFactoryUtils.doGetTransactionalResourceHolder(C onnectionFactoryUtils.java:121)
org.springframework.amqp.rabbit.connection.Connect ionFactoryUtils.getTransactionalResourceHolder(Con nectionFactoryUtils.java:67)
org.springframework.amqp.rabbit.connection.RabbitA ccessor.getTransactionalResourceHolder(RabbitAcces sor.java:100)
org.springframework.amqp.rabbit.core.RabbitTemplat e.execute(RabbitTemplate.java:402)
org.springframework.amqp.rabbit.core.RabbitTemplat e.receive(RabbitTemplate.java:267)
org.springframework.amqp.rabbit.core.RabbitTemplat e.receiveAndConvert(RabbitTemplate.java:296)
smse.com.au.service.MessageServiceImpl.resiveMessa ge(MessageServiceImpl.java:33)
smse.com.au.MessageController.list(MessageControll er.java:39)
sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.springframework.web.bind.annotation.support.Ha ndlerMethodInvoker.invokeHandlerMethod(HandlerMeth odInvoker.java:176)
org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter.invokeHandlerMethod(An notationMethodHandlerAdapter.java:436)
org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter.handle(AnnotationMetho dHandlerAdapter.java:424)
org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:790)
org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:719)
org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:669)
org.springframework.web.servlet.FrameworkServlet.d oGet(FrameworkServlet.java:574)
javax.servlet.http.HttpServlet.service(HttpServlet .java:617)
javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:290)
org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
org.springframework.orm.jpa.support.OpenEntityMana gerInViewFilter.doFilterInternal(OpenEntityManager InViewFilter.java:113)
org.springframework.web.filter.OncePerRequestFilte r.doFilter(OncePerRequestFilter.java:76)
org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:235)
org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
org.springframework.web.filter.HiddenHttpMethodFil ter.doFilterInternal(HiddenHttpMethodFilter.java:7 7)
org.springframework.web.filter.OncePerRequestFilte r.doFilter(OncePerRequestFilter.java:76)
org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:235)
org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
org.springframework.web.filter.CharacterEncodingFi lter.doFilterInternal(CharacterEncodingFilter.java :88)
org.springframework.web.filter.OncePerRequestFilte r.doFilter(OncePerRequestFilter.java:76)
org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:235)
org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:233)
org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:191)
org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:127)
org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:298)
org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:859)
org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:588)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:489)
java.lang.Thread.run(Thread.java:662)
You need to tell Spring that your Rabbit Connection parameters come from CloudFoundry
cf http://support.cloudfoundry.com/entr...ng-application
This means adding the cloud: namespace declaration, and define the cloud:rabbit-connection-factory
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xmlns:cloud="http://schema.cloudfoundry.org/spring"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schem...ng-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schem...ontext-3.0.xsd
http://www.springframework.org/schema/rabbit http://www.springframework.org/schem...rabbit-1.0.xsd
http://schema.cloudfoundry.org/spring http://schema.cloudfoundry.org/spring/cloudfoundry-spring-0.7.xsd">
<context:component-scan base-package="com.rabbitmq.cftutorial.simple"/>
<mvc:annotation-driven/>
<!-- Obtain a connection to the RabbitMQ via cloudfoundry-runtime: -->
<cloud:rabbit-connection-factory id="connectionFactory"/>
<!-- Set up the AmqpTemplate/RabbitTemplate: -->
<rabbit:template connection-factory="connectionFactory"/>
<!-- Request that queues, exchanges and bindings be automatically
declared on the broker: -->
<rabbit:admin connection-factory="connectionFactory"/>
<!-- Declare the "messages" queue: -->
<rabbit:queue name="messages" durable="true"/>
</beans>