0

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.

Locally my environment variable is: amqp://guest:guest@localhost:5672

On Heroku, my environment variable is generated by Heroku and is something along the lines of: amqp://oilpmoxc:rGoLFAKEPASSWORDhhqwwk6g@lion.rmq.cloudamqp.com/oilpmoxc

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.

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.

The following is a dump of the logs.

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)

Anyone have any idea what is happening?

Thanks!

codefinger
  • 10,088
  • 7
  • 39
  • 51
btbam91
  • 578
  • 2
  • 8
  • 20
  • Is it possible you've exceeded your connection limit? The limit for the free service is 20, and if you're local app or multiple instance of your app are connecting with a large pool size, this is likely. – codefinger Mar 14 '19 at 13:51
  • @codefinger I don’t think this is it. It connects one time every minute. Just my single app instance. – btbam91 Mar 14 '19 at 16:10
  • Are you sure it’s closing connections properly? Does it connect after you restart your dyno? – codefinger Mar 15 '19 at 02:41
  • @codefinger it does not connect whatsoever, even after restarting the dyno . I do have a finally block to close the connection. – btbam91 Mar 15 '19 at 02:44

1 Answers1

0

Finally got it...

Essentially I need to set the URI to the factory object before using the factory to create a connection. It's weird because this order wasn't required when running locally. Weird, but oh well. It works.

btbam91
  • 578
  • 2
  • 8
  • 20