title: CloudAMQP Connection Refused Only On Heroku
body: <p>I am using the CloudAMQP Heroku Add On for my Spring Boot application. I am connecting to the service using a "CLOUDAMQP_URL" environment variable both locally and on Heroku. </p>
  
  <p>Locally my environment variable is: amqp://guest:guest@localhost:5672</p>
  
  <p>On Heroku, my environment variable is generated by Heroku and is something along the lines of: amqp://oilpmoxc:rGoLFAKEPASSWORDhhqwwk6g@lion.rmq.cloudamqp.com/oilpmoxc</p>
  
  <p>I know that the environment variable generated by Heroku is correct because I grabbed it and used it locally. I was able to connect to the Heroku provided CloudAWQP instance just fine.</p>
  
  <p>At one point, my application on Heroku was connecting to CloudAMQP just fine. No issues whatsoever. Now, I can't connect at all. I keep getting a Connection Refused error.</p>
  
  <p>The following is a dump of the logs.</p>
  
  <pre><code>2019-03-14T00:55:24.586687+00:00 app[web.1]: java.net.ConnectException: Connection refused (Connection refused)
  2019-03-14T00:55:24.587055+00:00 app[web.1]:    at java.net.PlainSocketImpl.socketConnect(Native Method)
  2019-03-14T00:55:24.587122+00:00 app[web.1]:    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
  2019-03-14T00:55:24.587220+00:00 app[web.1]:    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
  2019-03-14T00:55:24.587282+00:00 app[web.1]:    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
  2019-03-14T00:55:24.587356+00:00 app[web.1]:    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
  2019-03-14T00:55:24.587431+00:00 app[web.1]:    at java.net.Socket.connect(Socket.java:589)
  2019-03-14T00:55:24.587491+00:00 app[web.1]:    at com.rabbitmq.client.impl.SocketFrameHandlerFactory.create(SocketFrameHandlerFactory.java:60)
  2019-03-14T00:55:24.587610+00:00 app[web.1]:    at com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory.newConnection(RecoveryAwareAMQConnectionFactory.java:62)
  2019-03-14T00:55:24.587755+00:00 app[web.1]:    at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.init(AutorecoveringConnection.java:156)
  2019-03-14T00:55:24.587820+00:00 app[web.1]:    at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1106)
  2019-03-14T00:55:24.587896+00:00 app[web.1]:    at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1063)
  2019-03-14T00:55:24.588121+00:00 app[web.1]:    at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1021)
  2019-03-14T00:55:24.588185+00:00 app[web.1]:    at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1182)
  2019-03-14T00:55:24.588267+00:00 app[web.1]:    at com.noebrito.temptube.messaging.MessageReceiver.pollQueue(MessageReceiver.java:41)
  2019-03-14T00:55:24.588345+00:00 app[web.1]:    at com.noebrito.temptube.util.ScheduledTask.deleteExpiredVideos(ScheduledTask.java:39)
  2019-03-14T00:55:24.588401+00:00 app[web.1]:    at sun.reflect.GeneratedMethodAccessor73.invoke(Unknown Source)
  2019-03-14T00:55:24.588489+00:00 app[web.1]:    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  2019-03-14T00:55:24.588700+00:00 app[web.1]:    at java.lang.reflect.Method.invoke(Method.java:498)
  2019-03-14T00:55:24.588761+00:00 app[web.1]:    at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84)
  2019-03-14T00:55:24.588856+00:00 app[web.1]:    at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
  2019-03-14T00:55:24.588921+00:00 app[web.1]:    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
  2019-03-14T00:55:24.588997+00:00 app[web.1]:    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
  2019-03-14T00:55:24.589220+00:00 app[web.1]:    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
  2019-03-14T00:55:24.589284+00:00 app[web.1]:    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
  2019-03-14T00:55:24.589362+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
  2019-03-14T00:55:24.589438+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  2019-03-14T00:55:24.589499+00:00 app[web.1]:    at java.lang.Thread.run(Thread.java:748)
  2019-03-14T00:55:24.589945+00:00 app[web.1]: 2019-03-14 00:55:24.589 ERROR 4 --- [   scheduling-1] c.n.temptube.messaging.MessageReceiver   : Connection refused (Connection refused)
  </code></pre>
  
  <p>Anyone have any idea what is happening?</p>
  
  <p>Thanks!</p>