I'm following this article (http://www.baeldung.com/spring-cloud-netflix-eureka) to set up eureka, my application.yml looks like this
server:
port: 8761
eureka:
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}
but I debug the main application I always get:
com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect
at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187) ~[jersey-apache-client4-1.19.1.jar:1.19.1]
at com.sun.jersey.api.client.filter.GZIPContentEncodingFilter.handle(GZIPContentEncodingFilter.java:123) ~[jersey-client-1.19.1.jar:1.19.1]
at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27) ~[eureka-client-1.4.10.jar:1.4.10]
and when I got to my browser eureka is not in 8761 port but in 8080 port instead, what I'm doing wrong?
You can't referece a property you just set above. This is not a procedural script, there's no guarantee the eureka line will be executed before the server one so ${server.port} will be the defaut: 8080
If you run you app using an environment prop it will work. Try:
java -Dserver.port=8761 -jar your-app.jar
Related
I am doing a POC on Config Server wherein I will connect to BitBucket repo and if any checkin happen in that repo, my Config Service will pick those changes. In the below code if I am providing bitbucket credentials (hardcoding username and password), its able to connect to BitBucket and everything is working fine. But if I try to provide SSH key, its throwing below error:
application.yml
server.port: 8888
spring:
application.name: config-server
cloud.config.server.git.uri: ${url}
cloud:
config:
server:
git:
cloneOnStart: true
username: username
password: password
default-label: master
management:
endpoints:
web:
exposure:
include: refresh
eureka:
client:
serviceUrl:
defaultZone: http://localhost:7001/eureka/
registryFetchIntervalSeconds: 1
instance:
leaseRenewalIntervalInSeconds: 1
Like I said the above configuration is working fine. When I replaced with the below configuration.
server.port: 8888
spring:
application.name: config-server
cloud.config.server.git.uri: ${URL}
cloud:
config:
server:
git:
#cloneOnStart: true
ignore-local-ssh-settings: true
hostKey: ${hostKEY}
hostKeyAlgorithm: ssh-rsa
private-key: ${SSH PRIVATE KEY}
management:
endpoints:
web:
exposure:
include: refresh
eureka:
client:
serviceUrl:
defaultZone: http://localhost:7001/eureka/
registryFetchIntervalSeconds: 1
instance:
leaseRenewalIntervalInSeconds: 1
I am getting below error::
2023-02-10T12:26:39.276+05:30 INFO 24628 --- [ main] c.e.c.ConfigServerApplication : Started ConfigServerApplication in 2.949 seconds (process running for 3.646)
2023-02-10T12:26:41.041+05:30 WARN 24628 --- [2)-10.73.53.175] .c.s.e.MultipleJGitEnvironmentRepository : Error occured cloning to base directory.
org.eclipse.jgit.api.errors.TransportException: https://bitbucketdc-cluster07.jpmchase.net/scm/ccbrft/ccbrap-config.git: Authentication is required but no CredentialsProvider has been registered
I created SSH Key using command :: ssh-keygen -m PEM -t rsa -b 4096 -C "cigfid_dev#example.com
Any help is appreciated.
I have an environment with different services. They all are deployed and managed by Docker images and Kubernetes. I also use spring-boot-admin in order to monitor them all and spring-cloud-kubernetes to discover all the services automatically.
This my properties file.
application.yml (In the SBA project)
server:
port: ${admin-server.port:8086}
tomcat:
remote-ip-header: x-forwarded-for
protocol-header: x-forwarded-proto
spring:
application:
name: admin-server
security:
user:
name: ${spring-security.admin.username:****}
password: ${spring-security.admin.password:****}
boot:
admin:
discovery:
ignored-services: admin-server
notify:
mail:
enabled: ${admin-mail.enabled:true}
to: ${admin-mail.recipients:******}
from: ${admin-mail.from:******}
template: classpath:/template/status-changed.html
ignore-changes: OFFLINE:UP, DOWN:UP
slack:
webhook-url: ${admin-slack.webhook:*******}
ignore-changes: OFFLINE:UP, DOWN:UP
enabled: true
mail:
test-connection: false
host: smtpjc.*****
port: 25
properties:
mail:
smtp:
connectiontimeout: 5000
timeout: 3000
writetimeout: 5000
debug: ${admin-mail.debug:true}
It works perfectly whenever I restart the SBA project, it discovers every service.
My problem comes when I restart a single project, it is shown as OFFLINE in the SBA and it does not change its status.
What am I missing?
I have found the issue and fixed it like this:
spring.cloud.kubernetes.reload.enabled: true
I should have added this line to the config file.
I've found out, that I had to use the fabric8 kubernetes-client.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-kubernetes-fabric8-all</artifactId>
</dependency>
I'm using these current versions:
<spring-cloud.version>2020.0.2</spring-cloud.version>
<spring-cloud-kubernetes.version>2.0.2</spring-cloud-kubernetes.version>
<spring-boot-admin.version>2.4.1</spring-boot-admin.version>
Otherwise I follow the instructions of https://piotrminkowski.com/2020/02/18/spring-boot-admin-on-kubernetes/
Currently I'm working in Spring boot micro services project. Consider I have 3 micro services named as A, B, C. Now My project have application.yml file separately for each micro service. Now I want to add one more microservice D, for manage all service property files.
view my config-service structure
eureka.yml(inside config-service) file is:
server:
port: 8761
eureka:
client:
registerWithEureka: false
fetchRegistry: false
server:
waitTimeInMsWhenSyncEmpty: 0
endpoints:
sensitive: false
In eureka-service bootstrap.properties is:
spring:
application:
name: eureka
cloud:
config:
uri: http://localhost:8888
Config service application properties :
spring:
application:
name: config
cloud:
config:
server:
native:
search-locations: classpath:/config/DEVELOP
profiles:
active: native
server:
port: 8888
my config application file is:
#SpringBootApplication
#EnableConfigServer
public class ConfigApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigApplication.class, args);
}
}
I did the following steps:
start the config-service
start the eureka-service
unfortunately, eureka server getting error.
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
the problem is while running eureka server, its not looking the config file which is inside the config service...
help me to resolve this. or instead of micro service, how can I go with folder?
Thanks # g00glen00b
I am changed config service bootstrap yml as follows :
spring:
application:
name: config
cloud:
config:
server:
native:
searchLocations: classpath:/config/DEVELOP/
profiles:
active: native
server:
port: 8888
Its working fine.
I try to starting my application(Spring Boot + Spring Cloud + Eureka + MongoDB) with using docker image, but i can't get connection to MongoDB.
Exception:
exception "com.mongodb.MongoSocketOpenException: Exception opening socket."
I starting my application with execute command: docker-compose up --build
Docker log:
com.mongodb. MongoSocket0penException: Exception opening socket at com.mongodb. connection. SocketStream.open(SocketStream.java: 63) ~|mongo-java-driver-3.2.2.jar!/:naj
at com. monsoob: connection. berettaberverwontortser/ersonito-kunnablearancerainitservertonitolnava:1203-dionso-java-driver*3?2.2.jarl/:nal
at : java. lang. Thread.run (Thread. java: 745) Lna:1.8.0_111]
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect (Native Method) ~ [na: 1.8.0_1111 at java.net.AbstractPlainSocketImp1.doConnect (AbstractplainSocketImpl.java:350) ~ [na: 1.8.0_111]
at java.net.AbstractPlainSocketImp1.connectToAddress(AbstractPlainSocketImp1.java:206)~[na:1.8.0_1111
at java.net .AbstractPlainSocketImp1.connect (AbstractPlain5ocket Imp],java:188) ~[na:1.8.0_111]
at java.net.SocksSocketImpl.connect (SocksSocketImpl.java:392) ~|na:1.8.0_111] java.net Socket. connect (Socket, java: 589) ~[na:1.8:0-111]
at com.mongodb.connection. SocketStreamHelper.initialize(SocketStreamHelper. java: 50) ~ [mongo-java-driver-3.2.2.ar!/:na] at com. mongodb. connection. SocketStream.open(SocketStream. java:58) ~ [mongo-java-driver-3.2.2.jar!/:na]
3 common frames omitted
application.yml:
# Spring properties
spring:
application:
name: car-service
data:
mongodb.host: localhost
mongodb.port: 32769
mongodb.uri: mongodb://localhost/test
mongo.repositories.enabled: true
# Discovery Server Access
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
# HTTP Server (Tomcat) Port
server:
port: 2220
error:
whitelabel:
enabled: false
docker-compose.yml:
eureka:
build: ./eureka-discovery-service
ports:
- "8761:8761"
mongodb:
image: mongo:3.0.4
ports:
- "32769:32769"
postgresql:
image: postgres:9.6.1
ports:
- "32770:32770"
gateway-service:
build: ./gateway-service
ports:
- "9090:9090"
links:
- eureka
environment:
SPRING_APPLICATION_NAME: gateway-service
SPRING_PROFILES_ACTIVE: enableEureka
EUREKA_INSTANCE_PREFER_IP_ADDRESS: "true"
EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: http://eureka:8761/eureka/
airplane-service:
build: ./airplane-service
ports:
- "2222:2222"
links:
- eureka
- postgresql
environment:
SPRING_APPLICATION_NAME: airplane-service
SPRING_PROFILES_ACTIVE: enableEureka
EUREKA_INSTANCE_PREFER_IP_ADDRESS: "true"
EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: http://eureka:8761/eureka/
SPRING_SLEUTH_ENABLED: "true"
SPRING_DATASOURCE_POSTGRESQL_URL: jdbc:postgresql://localhost:32770/postgres
car-service:
build: ./car-service
ports:
- "2220:2220"
links:
- eureka
- mongodb
environment:
SPRING_APPLICATION_NAME: car-service
SPRING_PROFILES_ACTIVE: enableEureka
EUREKA_INSTANCE_PREFER_IP_ADDRESS: "true"
EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: http://eureka:8761/eureka/
SPRING_SLEUTH_ENABLED: "true"
SPRING_DATA_MONGODB_URI: mongodb://localhost:32769/test
machine-service:
build: ./machine-service
ports:
- "2224:2224"
links:
- eureka
environment:
SPRING_APPLICATION_NAME: machine-service
SPRING_PROFILES_ACTIVE: enableEureka
EUREKA_INSTANCE_PREFER_IP_ADDRESS: "true"
EUREKA_CLIENT_SERVICEURL_DEFAULTZONE: http://eureka:8761/eureka/
SPRING_SLEUTH_ENABLED: "true"
Why I have exception opening a socket? How to fix this problem?
You are setting mongodb host in property file as localhost. In a container localhost address itself, but your mongodb is not in that container(car-service) which car-service run in. While you are using docker compose, you can address a container with its name. In your case it is mongodb.
to clarify #barbakini's answer, to define it in applications.yaml use:
spring.data.mongodb.host: mongodb
Your mongoDB service is not UP ,
Check the status by following command
sudo service mongodb status
sudo service mongodb start
Hope it should work, there could be several reasons as well ,
like the configuration you defined in your application for mongodb service is incorrect such as port .
Try to add
network_mode: host
and remove
links: ....
for all services, that want to connect with mongo or eureka or postgresql, inside your docker-compose.yml.
By doing so you will connect to docker localhost.
Show my code
conf.set( "mongo.input.uri" , "mongodb://127.0.0.1/stackoverflow.mrtest" );
conf.set( "mongo.output.uri" , "mongodb://127.0.0.1/stackoverflow.mrtest_out2" );
the code runs without error when the host is localhost or 127.0.0.1. But when the host changed to my ip wlan0 192.168.1.102, it returned the following error
Cluster created with settings {hosts=[192.168.1.102:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
Exception in monitor thread while connecting to server 192.168.1.102:27017
com.mongodb.MongoSocketOpenException: Exception opening socket
at com.mongodb.connection.SocketStream.open(SocketStream.java:63)
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:114)
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:127)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.ConnectException: connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:50)
at com.mongodb.connection.SocketStream.open(SocketStream.java:58)
... 3 more
I have open the port 27017.
sudo iptables -A INPUT -ptcp --dport 27017 -j ACCEPT
My OS is Ubuntu 14.04.
How should I fix it? Thank you!
By default MongoDB only binds to the loopback interface which makes it only accessible from localhost. To change that you need to edit this line in mongod.conf file;
# /etc/mongod.conf
# Listen to local interface only. Comment out to listen on all interfaces.
bind_ip = 127.0.0.1
you can change it to bind_ip = 127.0.0.1,192.168.1.102 to allow LAN and local connections or you can remove or comment out that line to allow all connections.
For more info : MongoDB – Allow remote access
There could be several reasons of it , which in short can be concluded as Your Application is unable to Communicate mongoDB service
1.Check your MongoDB using the same IP configured in your application.yml file,
If not then configure the same used by MongoDB:
spring:
profiles:
active: dev
---
spring:
profiles: dev
data:
mongodb:
host: localhost
port: 27017
Here i assumed my mongo running on localhost, and port 27017, so i configured accordingly.
Check whether your MongoDB service up and running , How to check ?
Execute following command in your terminal
sudo service mongodb status
<pre><code>
● mongodb.service - An object/document-oriented database
Loaded: loaded (/lib/systemd/system/mongodb.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2020-07-03 20:10:15 IST; 1min 54s ago
Docs: man:mongod(1)
Main PID: 14305 (mongod)
Tasks: 23 (limit: 4915)
CGroup: /system.slice/mongodb.service
└─14305 /usr/bin/mongod --unixSocketPrefix=/run/mongodb --config /etc/mongodb.conf</pre></code>
If Status not visible as active and running, you need to start/restart the service
sudo service mongodb restart
I was able to determine that it was an issue with the bind parameter in the /etc/mongod.conf. Instead of commenting it out I set it to 0.0.0.0 to all for remote access.
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0
Exception: com.mongodb.MongoSocketOpenException: Exception opening socket
Solution:
Verify whether you have started "mongo daemon" or not.
Windows Terminal: mongod.exe
Linux Termina: mongod
If you're using Spring Boot and are following the Quick Start, make sure you put this configuration in your application.properties
spring.data.mongodb.uri=[YOUR_URI]