Springboot mongo docker-compose fail to connect - spring

My docker-compose.yml is as shown
version: '3'
services:
backend-service:
image: 'storio-360-service:v1.0'
build: .
container_name: storio-360-service
ports:
- 8090:8080
depends_on:
- db_mongo
links:
- db_mongo
db_mongo:
image: 'mongo'
container_name: db_mongo
ports:
- 27018:27017
volumes:
- /home/bob/Bob/data:/data/db
restart: always
My Dockerfile is
FROM openjdk:8u111-jdk-alpine
VOLUME /tmp
ADD /target/backend-service-1.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
CMD curl "db_mongo:27018"
Because of this set up, my repository in my spring has this code
#Repository
public class WatcherRepository {
private MongoOperations mongoOps;
#Autowired
public WatcherRepository() {
String myHost = "db_mongo";
this.mongoOps = new MongoTemplate(new SimpleMongoDbFactory(new MongoClient(myHost), MongoConstant.DATABASE_NAME));
}
// Other code to access the mongo db
}
However, when i run docker-compose up --build,
I get the following when Spring boot is starting up,
02:24:55.871 [main] INFO org.mongodb.driver.cluster - Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
storio-360-service | 02:24:55.923 [cluster-ClusterId{value='5d3faa779470450001317225', description='null'}-localhost:27017] INFO org.mongodb.driver.cluster - Exception in monitor thread while connecting to server localhost:27017
storio-360-service | com.mongodb.MongoSocketOpenException: Exception opening socket
storio-360-service | at com.mongodb.connection.SocketStream.open(SocketStream.java:62)
storio-360-service | at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:126)
storio-360-service | at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:114)
storio-360-service | at java.lang.Thread.run(Thread.java:745)
storio-360-service | Caused by: java.net.ConnectException: Connection refused (Connection refused)
storio-360-service | at java.net.PlainSocketImpl.socketConnect(Native Method)
storio-360-service | at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
storio-360-service | at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
storio-360-service | at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
storio-360-service | at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
storio-360-service | at java.net.Socket.connect(Socket.java:589)
storio-360-service | at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:59)
storio-360-service | at com.mongodb.connection.SocketStream.open(SocketStream.java:57)
storio-360-service | ... 3 common frames omitted
storio-360-service | 02:24:56.060 [main] INFO org.mongodb.driver.cluster - Cluster created with settings {hosts=[127.0.0.1:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500
Then Spring boot will shown that it is waiting for calls as it sets up successfully.
02:34:39.274 [main] INFO o.d.i.i.storio.service.Service - Started Service in 5.353 seconds (JVM running for 6.085)
However, when i make the api call which will call the mongodb, it shows me the error
Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=127.0.0.1:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]; nested exception is com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=127.0.0.1:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]
I am new to Docker and it is clear that my springboot cannot access mongo. What am i doing wrong in my Dockerfile or docker-compose? thanks

Looks like you are forwarding your mongodb port to 27018
- 27018:27017
and you haven't specified 27018 in Spring config.
Hence Spring boot by default tries to connect to 27017
Solution:
Either remove the port forwarding, or update Spring Boot config to use mongo at 27018
Update:
Here are some Spring Boot's mongo auto configuration tips for the OP.
Have dependency on a mongodb starter for spring boot
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-mongodb -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<version>2.1.6.RELEASE</version>
</dependency>
Provide Mongo DB details in application properties.
spring.data.mongodb.database= # Database name.
spring.data.mongodb.host= # Mongo server host. Cannot be set with URI.
spring.data.mongodb.password= # Login password of the mongo server. Cannot be set with URI.
spring.data.mongodb.port= # Mongo server port. Cannot be set with URI.
spring.data.mongodb.username= # Login user of the mongo server. Cannot be set with URI
(Here the OP needs to specify his mongodb host and port)
Now, the only thing left is to autowire MongoTemplate, where ever you want to use.
#Autowired
private MongoTemplate mongoTemplate;

Related

Spring Boot & Spring boot Admin Can't sent alert email from Docker container

Here in my company we are trying to stablish a micro service based environment, where all the micro services to come will be monitored by an actuator application. We've created two applications, the first micro service and the spring boot admin project, locally all went well and all, then we used docker on this two applications, a container for each one and here start the problems.
Both applications run on port 8080 inside the container, then we assign an external port for its access, this seems to affect the way actuator communicates because now I'm having issues when the client application goes down, the admin is not sending any emails alerting as it did when locally. Here're my configs (changing some parameters):
Client:
.properties:
server.port=8080
spring.boot.admin.client.instance.name=Monitoramento Catracas
spring.boot.admin.client.url=http://my-ip:6060
spring.boot.admin.client.instance.service-base-url=http://my-ip:7070
docker-compose.yml:
services:
my-service:
build:
context: ./
dockerfile: my-file.dockerfile
image: test/my-image
container_name: my-container
ports:
- 7070:8080
Spring Boot Admin Application:
.properties
spring.mail.host=smtp.office365.com
spring.mail.port=587
spring.mail.username=email#email
spring.mail.password=12345
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
server.port=6060
spring.boot.admin.notify.mail.enabled=true
spring.boot.admin.notify.mail.from=email#email
spring.boot.admin.notify.mail.to=email_2#email
spring.boot.admin.notify.mail.template=classpath:templates/email-template.html
docker-compose.yml:
services:
ms-admin:
build:
context: ./ms-admin
dockerfile: ms-admin.dockerfile
image: cap/ms-admin
container_name: ms-admin
ports:
- 6060:8080
And this is what I get when I turn off the client application:
2022-12-09 17:06:10.534 WARN 1 --- [or-http-epoll-3] d.c.b.a.s.notify.NotificationTrigger : Couldn't notify for event InstanceStatusChangedEvent(super=InstanceEvent(instance=2cc8546ac366, version=4, timestamp=2022-12-09T17:06:10.275Z, type=STATUS_CHANGED), statusInfo=StatusInfo(status=OFFLINE, details={exception=org.springframework.web.reactive.function.client.WebClientRequestException, message=finishConnect(..) failed: Connection refused: /my-ip:7070; nested exception is io.netty.channel.AbstractChannel$AnnotatedConnectException: finishConnect(..) failed: Connection refused: /my-ip:7070}))
ms-monitoramento-hml |
ms-monitoramento-hml | org.springframework.mail.MailSendException: Mail server connection failed; nested exception is com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.office365.com, 587; timeout -1;
ms-monitoramento-hml | nested exception is:
ms-monitoramento-hml | java.net.UnknownHostException: smtp.office365.com. Failed messages: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.office365.com, 587; timeout -1;
ms-monitoramento-hml | nested exception is:
ms-monitoramento-hml | java.net.UnknownHostException: smtp.office365.com
ms-monitoramento-hml | Caused by: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.office365.com, 587; timeout -1
ms-monitoramento-hml | at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2210) ~[jakarta.mail-1.6.7.jar!/:1.6.7]
ms-monitoramento-hml | at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:722) ~[jakarta.mail-1.6.7.jar!/:1.6.7]
ms-monitoramento-hml | at javax.mail.Service.connect(Service.java:342) ~[jakarta.mail-1.6.7.jar!/:1.6.7]
ms-monitoramento-hml | at org.springframework.mail.javamail.JavaMailSenderImpl.connectTransport(JavaMailSenderImpl.java:518) ~[spring-context-support-5.3.23.jar!/:5.3.23]
ms-monitoramento-hml | at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:437) ~[spring-context-support-5.3.23.jar!/:5.3.23]
ms-monitoramento-hml | ... 124 common frames omitted
Hope someone can help me with this one, thanks
The error message is very clear, it says
Mail server connection failed.
Couldn't connect to host, port: smtp.office365.com, 587
So this is an network issue. Maybe there is some kind of firewall blocking the request or the docker containers are not able to reach the internet at all.
Maybe talk to the people who provide the docker host and check the connection rules with them.

ambari on HDP cluster + ambari-metrics-collector service not start

we have some issue with ambari-metrics-collector service , ( we have HDP cluster version - 2.6.4 with 8 nodes )
ambari metrics collector service can’t start or start of few second then failed
the details about metrics collector version
rpm -qa | grep metrics
ambari-metrics-grafana-2.6.1.0-143.x86_64
ambari-metrics-monitor-2.6.1.0-143.x86_64
ambari-metrics-collector-2.5.0.3-7.x86_64
ambari-metrics-hadoop-sink-2.6.1.0-143.x86_64
all machines are rhel 7.2
we performed the following steps in order to resolve the problem
1.restart metrics-collector service
su - ams -c '/usr/sbin/ambari-metrics-collector --config /etc/ambari-metrics-collector/conf/ stop'
su - ams -c '/usr/sbin/ambari-metrics-collector --config /etc/ambari-metrics-collector/conf/ start'
or
ambari-metrics-collector stop
ambari-metrics-collector start
2.restart ambari-metrics-monitor on all nodes
ambari-metrics-monitor stop
ambari-metrics-monitor start
3.clean the folder /var/lib/ambari-metrics-collector/hbase-tmp/zookeeper/
mv /var/lib/ambari-metrics-collector/hbase-tmp/zookeeper/zookeeper_0 /tmp/bck/zookeeper/
Then restart metrics-collector service
4.Tuning the metrics-collector parameters according - https://docs.cloudera.com/HDPDocuments/Ambari-2.2.1.0/bk_ambari_reference_guide/content/_ams_general_guidelines.html
we update the follwing parameters in ambari
metrics_collector_heap_size=1024
hbase_regionserver_heapsize=1024
hbase_master_heapsize=512
hbase_master_xmn_size=128
status for now: - steps 1-4 doesn’t help
From the logs we can see the following:
log file - ambari-metrics-collector.log
2020-06-25 09:06:14,474 WARN org.apache.zookeeper.ClientCnxn: Session 0x172eab71f310002 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1141)
2020-06-25 09:06:14,575 WARN org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper: Possibly transient ZooKeeper, quorum=master02.sys671.com:61181, exception=org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /ams-hbase-unsecure/meta-region-server
log file - hbase-ams-master-master02.sys671.com.log
2020-06-25 09:38:18,799 WARN [RS:0;master02:51842-SendThread(master02.sys671.com:61181)] zookeeper.ClientCnxn: Session 0x172ead5d73a0004 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1125)
2020-06-25 09:38:20,437 INFO [main-SendThread(master02.sys671.com:61181)] zookeeper.ClientCnxn: Opening socket connection to server master02.sys671.com/23.2.35.171:61181. Will not attempt to authenticate using SASL (unknown error)
2020-06-25 09:38:20,438 WARN [main-SendThread(master02.sys671.com:61181)] zookeeper.ClientCnxn: Session 0x172ead5d73a0002 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused
we also not see that port is listening ( timeline.metrics.service.webapp.address )
netstat -tulpn | grep 6188
any advice how to continue from this point ?
we'll appreciate to get any help about this problem

Docker compose error on mysql db connect for spring boot app Caused by: java.net.UnknownHostException: [duplicate]

This question already has answers here:
Communications link failure , Spring Boot + MySql +Docker + Hibernate
(6 answers)
Closed 3 years ago.
I have spring boot app
My Dockerfile is
FROM openjdk:8-jdk-alpine
EXPOSE 8080
ARG JAR_FILE=target/demo-0.0.1-SNAPSHOT.jar
ADD ${JAR_FILE} demo.jar
ENTRYPOINT ["java","-jar","/demo.jar"]
My docker compose file
# Docker Compose file Reference (https://docs.docker.com/compose/compose-file/)
version: '3.7'
# Define services
services:
# App backend service
app-server:
# Configuration for building the docker image for the backend service
build:
context: . # Use an image built from the specified dockerfile in the `polling-app-server` directory.
dockerfile: ./Dockerfile
container_name: empserver
ports:
- "3000:3000" # Forward the exposed port 8080 on the container to port 8080 on the host machine
restart: always
depends_on:
- db # This service depends on mysql. Start that first.
environment: # Pass environment variables to the service
SPRING_DATASOURCE_URL: jdbc:mysql://db:3306/employee_entries?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false
SPRING_DATASOURCE_USERNAME: root
SPRING_DATASOURCE_PASSWORD: root
# Database Service (Mysql)
db:
image: mysql:5.7
ports:
- "3306:3306"
restart: always
environment:
MYSQL_DATABASE: employee_entries
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_ROOT_PASSWORD: root
My docker net works
NETWORK ID NAME DRIVER SCOPE
b95e3d99b266 Default Switch ics local
7fff4f9713f8 demo_default nat local
fe8883b77d1d emp-mysql ics local
f464aab9064a nat nat local
a5bd5e8efe61 none null local
App is successfully running using java -jar target\demo-0.0.1-SNAPSHOT.jar
but when I am doing docker-compose up
I got below error
app-server_1 | Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
app-server_1 |
app-server_1 | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
app-server_1 | at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_212]
app-server_1 | at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_212]
app-server_1 | at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_212]
app-server_1 | at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_212]
app-server_1 | at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) ~[mysql-connector-java-8.0.19.jar!/:8.0.19]
app-server_1 | at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105) ~[mysql-connector-java-8.0.19.jar!/:8.0.19]
app-server_1 | at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151) ~[mysql-connector-java-8.0.19.jar!/:8.0.19]
app-server_1 | at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167) ~[mysql-connector-java-8.0.19.jar!/:8.0.19]
app-server_1 | at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:91) ~[mysql-connector-java-8.0.19.jar!/:8.0.19]
app-server_1 | at com.mysql.cj.NativeSession.connect(NativeSession.java:144) ~[mysql-connector-java-8.0.19.jar!/:8.0.19]
app-server_1 | at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:956) ~[mysql-connector-java-8.0.19.jar!/:8.0.19]
app-server_1 | at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:826) ~[mysql-connector-java-8.0.19.jar!/:8.0.19]
app-server_1 | ... 56 common frames omitted
app-server_1 | Caused by: java.net.UnknownHostException: db
app-server_1 | at java.net.InetAddress.getAllByName0(InetAddress.java:1281) ~[na:1.8.0_212]
app-server_1 | at java.net.InetAddress.getAllByName(InetAddress.java:1193) ~[na:1.8.0_212]
app-server_1 | at java.net.InetAddress.getAllByName(InetAddress.java:1127) ~[na:1.8.0_212]
app-server_1 | at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:132) ~[mysql-connector-java-8.0.19.jar!/:8.0.19]
app-server_1 | at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:65) ~[mysql-connector-java-8.0.19.jar!/:8.0.19]
app-server_1 | ... 59 common frames omitted
I am able to access mysql database and tables but from docker compose it was not
any suggestion would really be helpful
You need to provide the container names to the services and use them when referring them from each other. In your environment section for app-server, the url for database points to 127.0.0.1 but the database is not running on same container as app-server so this will fail.
To make this work, provide container names to services for eg : my_mysql and my_app-server and use it in environment url as jdbc:mysql://my_mysql:3306.
Please see the modified file below:
# Docker Compose file Reference (https://docs.docker.com/compose/compose-file/)
version: '3.7'
# Define services
services:
# App backend service
app-server:
# Configuration for building the docker image for the backend service
build:
context: . # Use an image built from the specified dockerfile in the `polling-app-server` directory.
dockerfile: ./Dockerfile
container_name: my_app-server
ports:
- "3000:3000" # Forward the exposed port 8080 on the container to port 8080 on the host machine
restart: always
depends_on:
- db # This service depends on mysql. Start that first.
environment: # Pass environment variables to the service
SPRING_DATASOURCE_URL: jdbc:mysql://my_mysql:3306/employee_entries?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false
SPRING_DATASOURCE_USERNAME: root
SPRING_DATASOURCE_PASSWORD: root
# Database Service (Mysql)
db:
image: mysql:5.7
container_name: my_mysql
ports:
- "3306:3306"
restart: always
environment:
MYSQL_DATABASE: employees
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_ROOT_PASSWORD: root
network:
my-network:

Unable to connect JConsole to my Springboot application running in a Docker container

I have a Springboot application being successfully deployed in a Docker container and I am trying to connect JConsole to it. Inside the container the application is being executed with the following flags:
-Dcom.sun.management.jmxremote
-Djava.rmi.server.hostname="$JMX_RMI_SERVER_HOST"
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.port=10122
-Dcom.sun.management.jmxremote.rmi.port=10122
where JMX_RMI_SERVER_HOST=$(hostname -i).
In my Dockerfile I have EXPOSE 10122 and in the ports section of my compose 10122:10122.
JConsole fails to connect to localhost:10122 most likely because of this warning that I see in my logs:
15:40:35.896 [RMI TCP Accept-0] [] [] [] WARN sun.rmi.transport.tcp - RMI TCP Accept-0: accept loop for ServerSocket[addr=0.0.0.0/0.0.0.0,localport=44567] throws
java.net.SocketTimeoutException: Accept timed out
at java.base/java.net.PlainSocketImpl.socketAccept(Native Method)
at java.base/java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:458)
at java.base/java.net.ServerSocket.implAccept(ServerSocket.java:551)
at java.base/java.net.ServerSocket.accept(ServerSocket.java:519)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$AcceptLoop.executeAcceptLoop(TCPTransport.java:394)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$AcceptLoop.run(TCPTransport.java:366)
at java.base/java.lang.Thread.run(Thread.java:834)
15:40:35.896 [RMI TCP Accept-10122] [] [] [] WARN sun.rmi.transport.tcp - RMI TCP Accept-10122: accept loop for ServerSocket[addr=0.0.0.0/0.0.0.0,localport=10122] throws
java.net.SocketTimeoutException: Accept timed out
at java.base/java.net.PlainSocketImpl.socketAccept(Native Method)
at java.base/java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:458)
at java.base/java.net.ServerSocket.implAccept(ServerSocket.java:551)
at java.base/java.net.ServerSocket.accept(ServerSocket.java:519)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$AcceptLoop.executeAcceptLoop(TCPTransport.java:394)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$AcceptLoop.run(TCPTransport.java:366)
at java.base/java.lang.Thread.run(Thread.java:834)
Does anyone know what I am missing? Thank you for your help

com.datastax.driver.core.TransportException: [/xx.xxx.x.xxx:9042] Cannot connect

I have 2 node in Cassandra cluster with IP:Port aa.aaa.a.aaa:9043(node) and xx.xxx.x.xxx:9043. When i trying to connect using following config **PoolingOptions poolingOptions = new PoolingOptions();
poolingOptions.setCoreConnectionsPerHost(HostDistance.LOCAL, 2)
.setMaxConnectionsPerHost(HostDistance.LOCAL, 4)
.setCoreConnectionsPerHost(HostDistance.REMOTE, 2)
.setMaxConnectionsPerHost(HostDistance.REMOTE, 4)
.setMaxRequestsPerConnection(HostDistance.LOCAL, 200)
.setMaxRequestsPerConnection(HostDistance.REMOTE, 200);
cluster = Cluster.builder()
.addContactPointsWithPorts(socketAddressList)
.withPoolingOptions(poolingOptions)
.withRetryPolicy(DefaultRetryPolicy.INSTANCE)
.withLoadBalancingPolicy(new TokenAwarePolicy(new DCAwareRoundRobinPolicy())).build();
Session session = cluster.connect(cassandraDB);**
I am getting following exception 16/01/14 09:52:45 INFO core.NettyUtil: Did not find Netty's native epoll transport in the classpath, defaulting to NIO.
16/01/14 09:52:46 WARN core.Cluster: ***You listed /xx.xxx.x.xxx:9043 in your contact points, but it could not be reached at startup*
16/01/14 09:52:47 INFO policies.DCAwareRoundRobinPolicy: Using data-center name 'name' for DCAwareRoundRobinPolicy (if this is incorrect, please provide the correct datacenter name with DCAwareRoundRobinPolicy constructor)ent.Futures$CombinedFuture setExceptionAndMaybeLog
SEVERE: input future failed.
com.datastax.driver.core.TransportException: [/xx.xxx.x.xxx:9042] Cannot connect
at com.datastax.driver.core.Connection$1.operationComplete(Connection.java:156)
at com.datastax.driver.core.Connection$1.operationComplete(Connection.java:139)
at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:680)
at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:603)
at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:563)
at io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:424)
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.fulfillConnectPromise(AbstractNioChannel.java:268)
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:284)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:528)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:111)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.ConnectException: Connection refused: /xx.xxx.x.xxx:9042
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:744)
at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:224)
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:281)
... 6 more
16/01/14 09:52:47 ERROR core.Session: Error creating pool to /xx.xxx.x.xxx:9042
com.datastax.driver.core.TransportException: [/xx.xxx.x.xxx:9042] Cannot connect
at com.datastax.driver.core.Connection$1.operationComplete(Connection.java:156)
at com.datastax.driver.core.Connection$1.operationComplete(Connection.java:139)
at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:680)
at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:603)
at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:563)
at io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:424)
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.fulfillConnectPromise(AbstractNioChannel.java:268)
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:284)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:528)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:111)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.ConnectException: Connection refused: /xx.xxx.x.xxx:9042
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:744)
at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:224)
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:281)**
My Question are:
why it is trying to connect on port 9042, while no where i am using this port in code as well as in config file ?
cassandra version: Cassandra 2.2.1
why it is trying to connect on port 9042, while no where i am using this port in code as well as in config file ?
9042 is the default port for the CQL binary protocol.
Can you show us the content of the variable socketAddressList that you passed to the cluster builder ?
Is there any reason you're using port 9043 instead of the default 9042 port ?

Resources