Spring Coud Gateway and Eureka - problem with Docker - java

I have three microservices, all running in Windows 10 localhost.
service-registry properties.yml:
eureka:
client:
fetch-registry: false
register-with-eureka: false
#serviceUrl:
#defaultZone: http://localhost:55003/eureka
server:
maxThreadsForPeerReplication: 0
server:
port: 55003
user-service properties.yml:
eureka:
client:
serviceUrl:
defaultZone: http://localhost:55003/eureka
server:
port: ${random.int(55020,55040)}
spring:
application:
name: user-service
api-gateway properties.yml:
eureka:
client:
serviceUrl:
defaultZone: http://localhost:55003/eureka
server:
port: 55002
spring:
application:
name: api-gateway
cloud:
gateway:
routes:
- uri: lb://user-service
predicates:
- Path=/users/**
This is my config. When I run all three services, I'm getting logs like this, with weird Docker address and also these addresses are in Eureka instances list:
DiscoveryClient_USER-SERVICE/host.docker.internal:user-service:55033 - registration status: 204
When I try to reach the api-gateway at localhost:55002/users/register, I keep getting 500 response with:
io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: no further information: host.docker.internal/192.168.1.145:55032
I tried to do anything to Windows hosts file, like removing the Docker part, like the other topics advised:
# Added by Docker Desktop
192.168.1.145 host.docker.internal
192.168.1.145 gateway.docker.internal
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section
In this case, the services are registered with some other weird addresses:
DiscoveryClient_USER-SERVICE/DESKTOP-C48Q87T:user-service:55036 - registration status: 204
And when i try to reach api-gateway, I'm getting another error:
Connection refused: no further information: localhost/127.0.0.1:55032
What seems completely not understandable for me, is that the ports are completely mixed. In first case user-services was registered in 55033 and erro says 55032. In second case. it's 55036 and 55032.
I'm completely confused. What's going on?

Related

Not able to run two instance of Authentication service with Zuul

I am working with Eureka/Zuul and Springboot microservices.
While mapping multiple instances of same application to Zuul gateway, i am using serviceId attribute.
Here i had shared my application.yml of zuul project.
server:
port: 8093
servlet:
context-path: /apigateway
spring:
application:
name: zuul-proxy
zuul:
sensitiveHeaders: Cookie,Set-Cookie
host:
socketTimeoutMillis: 60000
routes:
authenticator-oauth:
path: /oauth/
url: http://localhost:8092/authenticator/oauth
sample-resource-server:
path: /sample/
serviceId: sample
stripPrefix: false
sample:
ribbon:
NIWSServerListClassName: com.netflix.loadbalancer.ConfigurationBasedServerList
listOfServers: http://localhost:8096,http://localhost:8097
ConnectTimeout: 60000
ReadTimeout: 60000
MaxTotalHttpConnections: 500
MaxConnectionsPerHost: 100
authenticator:
ribbon:
NIWSServerListClassName: com.netflix.loadbalancer.ConfigurationBasedServerList
listOfServers: http://localhost:8092, http://localhost:8091
ConnectTimeout: 1000
ReadTimeout: 5000
MaxTotalHttpConnections: 500
MaxConnectionsPerHost: 100
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://localhost:8094/eureka/
instance:
preferIpAddress: true
I am able to run my authenticator application.
Also i am able to run my sample application on both port(8096/8097) with load balancing .
Here as you can see i had mapped authenticator service using URL and it's working fine.
url: http://localhost:8092/authenticator/oauth
But when i had mapped it with service id as below code, it's not able to redirect with actual authentication service url.
authenticator-oauth:
path: /authenticator/**
serviceId: authenticator
stripPrefix: false
In both these cases, i am hitting same URL as below
http://localhost:8093/apigateway/oauth/token.
Why authentication service or oauth/token end point behave differently compare to normal application?
Any help will appreciated.
In order to register multiple instance of same micro-service you have to do nothing
in ZUUL API GATEWAY.
Add a property in the micro-service itself for which you are creating multiple instance.
server:
port: ${PORT:0}
eureka:
instance:
instance-id: ${spring.application.name}:${spring.application.instance_id:${random.value}}
Every time you will start same service it will start on unique port
It will register itself with eureka discovery service
Load Balancing will be done automatically since ribbon comes built in with Zuul

Spring boot application of kafka pipeline with error of "Connection to node -1 could not be established. Broker may not be available."

2020-02-26 18:08:54.925 WARN 4472 --- [| adminclient-1] org.apache.kafka.clients.NetworkClient : [AdminClient clientId=adminclient-1] Connection to node -1 could not be established. Broker may not be available.
The following is the application.yaml file
spring:
cloud:
stream:
default:
producer:
useNativeEncoding: true
consumer:
useNativeEncoding: true
bindings:
input:
destination: employee-details
content-type: application/*+avro
group: group-1
concurrency: 3
output:
destination: employee-details
content-type: application/*+avro
kafka:
binder:
producer-properties:
key.serializer: io.confluent.kafka.serializers.KafkaAvroSerializer
value.serializer: io.confluent.kafka.serializers.KafkaAvroSerializer
schema.registry.url: http://localhost:8081
consumer-properties:
key.deserializer: io.confluent.kafka.serializers.KafkaAvroDeserializer
value.deserializer: io.confluent.kafka.serializers.KafkaAvroDeserializer
schema.registry.url: http://localhost:8081
specific.avro.reader: true
I tried to run curl -X POST https://localhost:9092/employees/1001/Harry/Potter on cmd, but gave error of curl: (7) Failed to connect to localhost port 9092: Connection refused
You seem to have some fundamental misunderstanding. connect to localhost port 9092: Connection refused Port 9092 is normally the Kafka port, not an HTTP port; given that you are getting Broker may not be available. and Connection Refused when trying to connect with curl implies you don't have Kafka running on localhost and you certainly can't connect to it with HTTP, even if it was running there.

Block Microservice Instance from registering with Eureka Service Discovery

Is there a way via configuration to blacklist specific ip addresses from registering as microservices with Spring Eureka cloud discovery? It seems that each time I restart my discovery service an unrecognized ip instance is registering as a microservice. From the attached image I would expect that only a single instance be present rather than the two shown.
Currently the application.yml file is configured as follows:
---
# This default profile is used when running a single instance completely standalone:
#spring:
# profiles: default
server:
port: 8010
eureka:
instance:
hostname: eurekahost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
security:
basic:
enabled: false
user:
name: user # login username
password: password
Although this is not my ideal solution since I prefer to do this via configuration, I found that I can de-register the service via Eureka's REST API.

Spring boot admin doesn't fetch registry from eureka

I use spring boot 2.0.X and want to use an admin-server that automatically detects other services registered at Eureka. I have followed this guide to the letter, but none of the applications are shown in the admin console. All applications are registered with Eureka successfully.
Admin-server configuration:
server:
port: 8762
spring:
application:
name: admin-server
boot:
admin:
discovery:
ignored-services: admin-server
#The admin server will automatically pick up all services at eureka and register them to itself.
eureka:
instance:
leaseRenewalIntervalInSeconds: 10
health-check-url-path: /actuator/health
metadata-map:
startup: ${random.int} #needed to trigger info and endpoint update after restart
client:
registryFetchIntervalSeconds: 5
registerWithEureka: true #default true
fetchRegistry: true #default true
serviceUrl:
defaultZone: http://localhost:8761/eureka/
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: ALWAYS
Eureka server configuration:
server:
port: 8761
spring:
application:
name: discovery-server
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://localhost:8761/eureka/
Some thoughts:
We migrated from spring boot 1.5.x to 2.0.x, is there a problem with
security? We don't use spring-security anywhere but I read that some
http endpoints are not "reachable" or "active" by default anymore. But I see no errors or warning in the logf of the admin server or eureka server about this.
None of my other applications have the spring boot admin starter client dependency in their pom, because I don't want THAT to be the part that is responsible for registering ith the admin console, I want it be done dynamically through Eureka
All applications, except the admin server and the eureka server, use
the config-server to fetch their configuration. Does this cause
problems?
The application.yml that all other applications get from the config server contains the following:
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
spring:
boot:
admin:
url: http://localhost:8762
management: #exposing all endpoints is not safe for production, especially not if spring security gets involved
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: ALWAYS
I had the same issue when upgrading to SBA2.
Versions of spring-boot, spring-cloud and SBA should match. I used:
spring-boot: 2.0.7.RELEASE
spring-cloud: Finchley.SR2
SBA: 2.0.4
In my case the trick was to use spring-boot-admin-starter-server as dependency instead of plain dependencies (spring-boot-admin-server, spring-boot-admin-server-ui, spring-boot-admin-server-cloud) as it is descriped here:
https://github.com/codecentric/spring-boot-admin/issues/776

Problems with Eureka server

I have a local eureka server and one client
Eureka:
server:
port: 1111
eureka:
instance:
prefer-ip-address: true
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://127.0.0.1:1111/eureka/
server:
waitTimeInMsWhenSyncEmpty: 0
Client:
eureka:
instance:
prefer-ip-address: true
client:
serviceUrl:
defaultZone: http://127.0.0.1:1111/eureka/
I have 2 problems:
1) Eureka server throws in log:
NullPointerException:
at com.netflix.eureka.resources.StatusResource.isReplicaAvailable
2) The client connecting with Eureka, but after some time I see in his log next:
RedirectingEurekaHttpClient : Request execution error
javax.ws.rs.WebApplicationException: null at com.netflix.discovery.provider.DiscoveryJerseyProvider.readFrom(DiscoveryJerseyProvider.java:110)
RetryableEurekaHttpClient : Request execution failure
DiscoveryClient : DiscoveryClient_MW/192.168.0.100:client:8080 - was unable to send heartbeat!
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
In log Eureka I see:
InstanceRegistry : DS: Registry: lease doesn't exist, registering resource: CLIENT - 192.168.0.100:client:8080
InstanceResource : Not Found (Renew): CLIENT - 192.168.0.100:client:8080
In Eureka web console the client has a UP status, but also there is a big inscription:
RENEWALS ARE LESSER THAN THE THRESHOLD. THE SELF PRESERVATION MODE IS
TURNED OFF.THIS MAY NOT PROTECT INSTANCE EXPIRY IN CASE OF
NETWORK/OTHER PROBLEM
Although connection is working and I can get link to my client throught Eureka.
Could you explain what it means and how I can get rid from that?
serviceUrl:
defaultZone: http://127.0.0.1:1111/eureka/
in client setting YML, you should add space before "defaultZone" like this:
serviceUrl:
defaultZone: http://127.0.0.1:1111/eureka/
else defaultZone is same level with serviceUrl.
thanks

Categories

Resources