RabbitMQ Connection refused - java

After application started
Attempting to connect to: [localhost:5672]
2022-09-22 17:51:12.872 WARN 80292 --- [ 127.0.0.1:5672] c.r.c.impl.ForgivingExceptionHandler : An unexpected connection driver error occured (Exception message: Socket closed)
2022-09-22 17:51:12.880 WARN 80292 --- [)-192.168.87.19] o.s.b.a.amqp.RabbitHealthIndicator : Rabbit health check failed
org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:61) ~[spring-rabbit-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:510) ~[spring-rabbit-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:751) ~[spring-rabbit-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.createConnection(ConnectionFactoryUtils.java:214) ~[spring-rabbit-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:2095) ~[spring-rabbit-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:2068) ~[spring-rabbit-2.2.5.RELEASE.jar:2.2.5.RELEASE]
Things not related to rabbitMQ are working
application.properties:
#RABBITMQ
spring.rabbitmq.addresses=amqp://rabbitmq:rabbitmq#localhost:5672

try using a simple tool like telnet to check the port is open on the machine, e.g. telnet localhost 5672
are you running this in a Docker container? and is RabbitMQ running on the host machine? In which case localhost identifies the container not the host, you'd need to reference the hosts IP address or some virtual name.
(Not likely to be the cause of the problem is the property settings (unless you are not posting the actual values you are using). I don't think you have the correct property names, but the host/port you say you set are the defaults anyway. I do see the reference to 127.0.0.1:5672 in the logs.)
spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
See https://docs.spring.io/spring-boot/docs/1.5.6.RELEASE/reference/html/common-application-properties.html

Related

Play framework java connection is not available to sql server database

I'm stucked in a problem during connection from my java project (play framework ) to a sql server database in Azure.
In local enviroment the connection works fine.
Below parameter in my application.conf :
db.default {
url="jdbc:sqlserver://server-name.database.windows.net:1433;database=database-name"
encrypt=true
trustServerCertificate=false
hostNameInCertificate="*.database.windows.net"
loginTimeout=30
driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
username="root"
password="RootPwd"
}
This is the error received:
ERROR o.h.e.jdbc.spi.SqlExceptionHelper HikariPool-1 - Connection is
not available, request timed out after 30006ms. ERROR
o.h.e.jdbc.spi.SqlExceptionHelper The TCP/IP connection to the host
par-sql-server.database.windows.net, port 1433 has failed. Error:
"par-sql-server.database.windows.net. Verify the connection
properties. Make sure that an instance of SQL Server is running on the
host and accepting TCP/IP connections at the port. Make sure that TCP
connections to the port are not blocked by a firewall.". ERROR
p.api.http.DefaultHttpErrorHandler
play.api.PlayException: Execution exception[[CompletionException:
org.hibernate.exception.JDBCConnectionException: Unable to acquire
JDBC Connection]]
at play.api.http.HttpErrorHandlerExceptions$.$anonfun$convertToPlayException$3(HttpErrorHandler.scala:388)
at scala.Option.getOrElse(Option.scala:201)
at play.api.http.HttpErrorHandlerExceptions$.convertToPlayException(HttpErrorHandler.scala:388)
at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:373)
at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:264)
at play.core.server.AkkaHttp
I have already checked that tcp/ip port 1433 is correctly available for database, and my ip is correctly setted to avoid firewall.
Any suggestions?
thanks
Usually this error occurs when the database is not getting the connection within the default connectionTimeout property.
You can try to increase the value of connectionTimeout in Java config as below:
config.setConnectionTimeout(300000);
below is one of the sample config:
HikariConfig config = new HikariConfig();
config.setMaximumPoolSize(20);
config.setConnectionTimeout(300000);
config.setConnectionTimeout(120000);
config.setLeakDetectionThreshold(300000);
If possible let me know the steps to reproduce this issue so that I can fix it accordingly, also based on the information you've provided these blogs (Blog1, Blog2) will help you in establishing the connection

How can I start H2 in Server Mode using Quarkus?

I use the H2 database in my development mode with Quarkus. When I need to access the Database with a client as DBeaver, I start the H2 in Mixed mode, like this:
quarkus.datasource.jdbc.url=jdbc:h2:~/h2/oracle_test;MODE=Oracle;AUTO_SERVER=TRUE
These days, I discovered that if I start Quarkus without passing the quarkus.datasource.jdbc.url property in the application.properties, like:
quarkus.datasource.db-kind=h2
quarkus.datasource.username=test
quarkus.datasource.password=test
Quarkus is automatically starting the H2 database in Server mode for me:
[INFO] H2 database started in TCP server mode; server status: TCP server running at tcp://127.0.1.1:40003 (only local connections)
In this scenario, I was able to connect to H2 Server at localhost:40003 with DBeaver.
I've used the #ConfigProperty to discover what Quarkus is passing to this parameter:
#ConfigProperty(name = "quarkus.datasource.jdbc.url")
In my test, it was jdbc:h2:tcp://localhost:40003/mem:default;DB_CLOSE_DELAY=-1
I've tried to pass this in my properties:
quarkus.datasource.db-kind=h2
quarkus.datasource.jdbc.driver=org.h2.Driver
quarkus.datasource.jdbc.url=jdbc:h2:tcp://localhost:40003/mem:default;DB_CLOSE_DELAY=-1
But, when I start Quarkus I receive this error:
2021-04-09 17:14:57,549 WARN [io.agr.pool] (agroal-11) Datasource '<default>': Connection is broken: "java.net.ConnectException: Connection refused (Connection refused): localhost:40003" [90067-197]
2021-04-09 17:14:57,551 WARN [org.hib.eng.jdb.env.int.JdbcEnvironmentInitiator] (Quarkus Main Thread) HHH000342: Could not obtain connection to query metadata: org.h2.jdbc.JdbcSQLException: Connection is broken: "java.net.ConnectException: Connection refused (Connection refused): localhost:40003" [90067-197]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:357)
at org.h2.message.DbException.get(DbException.java:168)
at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:451)
at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:332)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:124)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:103)
at org.h2.Driver.connect(Driver.java:69)
at io.agroal.pool.ConnectionFactory.createConnection(ConnectionFactory.java:200)
at io.agroal.pool.ConnectionPool$CreateConnectionTask.call(ConnectionPool.java:452)
at io.agroal.pool.ConnectionPool$CreateConnectionTask.call(ConnectionPool.java:434)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at io.agroal.pool.util.PriorityScheduledExecutor.beforeExecute(PriorityScheduledExecutor.java:65)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1126)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399)
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.base/java.net.Socket.connect(Socket.java:609)
at org.h2.util.NetUtils.createSocket(NetUtils.java:103)
at org.h2.util.NetUtils.createSocket(NetUtils.java:83)
at org.h2.engine.SessionRemote.initTransfer(SessionRemote.java:114)
at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:447)
... 12 more
I believe that I have to pass another parameter to make Quarkus to start H2 in Server Mode or Quarkus is doing something more when I don't pass the quarkus.datasource.jdbc.url anywhere, perhaps it is doing something like this issue - Quarkus JPA with H2 database
I could run my development mode without passing the quarkus.datasource.jdbc.url parameter, the only inconvenient is that each time Quarkus choose a different port to the database.
Summarizing, I'm able to run Quarkus in development mode with H2 in Mixed mode and accessing the database from a client. The downside is that H2 at mixed mode creates some files and running it directly with Server Mode would be useful!

"java.io.EOFException: SSL peer shut down incorrectly" thrown when not using SSL

I am unable to connect VisualVM to a remote JVM. I have started the remote JVM with the following parameters:
java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.port=9000 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=[server ip] -Dlog4j.configurationFile=file:///home/ubuntu/servicesLog4j2.xml -jar /home/ubuntu/Program.jar &
Note the -Dcom.sun.management.jmxremote.ssl=false
I then start VisualVM and add a new JMX connection to the server. I specifically check the option:
Do not require SLL connection
When the connection fails, I can see the following error in the VisualVM log. I am unsure why SSL is involved if I have disabled SSL with a flag on the remote VM and specified not to require SSL in VisualVM. But it would appear this error is preventing the connection. What am I missing?
java.io.EOFException: SSL peer shut down incorrectly
at sun.security.ssl.InputRecord.read(InputRecord.java:505)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:954)
Caused: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1343)
at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:728)
at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:123)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
at java.io.DataOutputStream.flush(DataOutputStream.java:123)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:229)
Caused: java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is:
javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:304)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:342)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:118)
Caused: javax.naming.CommunicationException [Root exception is java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is:
javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake]
at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:122)
at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:205)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1929)
at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1896)
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:287)
Caused: java.io.IOException: Failed to retrieve RMIServer stub
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:369)
at com.sun.tools.visualvm.jmx.impl.JmxModelImpl$ProxyClient.tryConnect(JmxModelImpl.java:569)
[catch] at com.sun.tools.visualvm.jmx.impl.JmxModelImpl$ProxyClient.connect(JmxModelImpl.java:506)
at com.sun.tools.visualvm.jmx.impl.JmxModelImpl.connect(JmxModelImpl.java:234)
at com.sun.tools.visualvm.jmx.impl.JmxModelImpl.<init>(JmxModelImpl.java:223)
at com.sun.tools.visualvm.jmx.impl.JmxModelProvider.createModelFor(JmxModelProvider.java:60)
at com.sun.tools.visualvm.jmx.impl.JmxModelProvider.createModelFor(JmxModelProvider.java:41)
at com.sun.tools.visualvm.core.model.ModelFactory.getModel(ModelFactory.java:111)
at com.sun.tools.visualvm.tools.jmx.JmxModelFactory.getJmxModelFor(JmxModelFactory.java:69)
at com.sun.tools.visualvm.jmx.impl.JmxApplicationProvider.addJmxApplication(JmxApplicationProvider.java:295)
at com.sun.tools.visualvm.jmx.impl.JmxApplicationProvider.createJmxApplication(JmxApplicationProvider.java:200)
at com.sun.tools.visualvm.jmx.JmxApplicationsSupport.createJmxApplicationImpl(JmxApplicationsSupport.java:319)
at com.sun.tools.visualvm.jmx.JmxApplicationsSupport.createJmxApplicationInteractive(JmxApplicationsSupport.java:296)
at com.sun.tools.visualvm.jmx.impl.AddJMXConnectionAction$1.run(AddJMXConnectionAction.java:80)
at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1423)
at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2033)
How I managed to solve this after some headaches:
If you have a firewall at the remote machine, you might have issues with the second random port (where remote objects are exported). Try to disable the firewall and if it works then you might have to do something like this. Tomcat have a listener to solve it: link
Make sure that the value under -Djava.rmi.server.hostname resolves to the host from your client location (that was my case)
And finally jconsole (at the JDK bin folder, the same than VisualVM) provides very useful information. Execute it from a console with the -debug option. With the debug option, Jconsole will pop up stacktraces explaining the real reason why your client can't connect. When you try to connect to nonSSL servers JConsole will initially fail and then it will ask you to connect "insecure", next you'll see the real reason, in my case it was looking for the object export port at the loopback IP 127.0.0.1 (because I wasn't using the -Djava.rmi.server.hostname option).
Hope it helps!

Unable to connect to remote hbase from java program

Hi I am trying to connect to hbase in a remote machine from my java program. But I am getting connection refused error. On looking at the error I think it is trying to connect to my localhost instead of the remote machine.
My configuration is like-
HBaseConfiguration conf = new HBaseConfiguration();
conf.set("hbase.master", "10.219.47.22:60010");
conf.set("hbase.zookeeper.quorum.", "10.219.47.22:60010");
conf.set("hbase.zookeeper.property.clientPort", "2181");
I am getting the following error
13/11/15 17:35:08 WARN zookeeper.ClientCnxn: Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused: no further information
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(Unknown Source)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:350)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1068)
13/11/15 17:35:08 INFO zookeeper.ClientCnxn: Opening socket connection to server 127.0.0.1/127.0.0.1:2180. Will not attempt to authenticate using SASL (unknown error)
13/11/15 17:35:08 WARN zookeeper.RecoverableZooKeeper: Possibly transient ZooKeeper exception: org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /hbase/master
13/11/15 17:35:08 INFO util.RetryCounter: The 1 times to retry after sleeping 2000 ms
Also on running lsof on the remote machine to check if my port 2181 is open. I got the following result-
java 18854 root 266u IPv6 6199707 0t0 TCP 127.0.0.1:47000->127.0.0.1:2181 (CLOSE_WAIT)
Your zookeeper quorum ip adderess 10.219.47.22:60010 also specifies a port (60010) remove that
Also you have an unnecessary . after quorum
conf.set("hbase.zookeeper.quorum", "10.219.47.22");
conf.set("hbase.zookeeper.property.clientPort", "2181");
The 60010 port is just for web ui not for connection.
Check if this code snippet can help you:
Configuration hbaseConfiguration = HBaseConfiguration.create();
hbaseConfiguration.addResource(new Path("hbase-site.xml");
and in hbase-site.xml file add properties like ones in your conf folder of hbase installation folder on your master node.

ActiveMQ, Broker Url: how to run on port number other than default 61616

I am trying to run on the port number 5000, tcp://localhost:5000
it shows the following error
WARNING: Could not refresh JMS Connection for destination 'queue://jmsExample' - retrying in 5000 ms. Cause: Could not connect to broker URL: tcp://localhost:5000. Reason: java.net.ConnectException: Connection refused: connect
Any Help please
The port 5000 is already in use by another process or service

Categories