Eureka Server is Working but not the services Springboot Microservices Docker-compose - spring-boot

I have created Microservices using Spring Boot and Eureka . I have used API Gateway for the microservices .
All the microservices ( eureka clients ) are visible on eureka server but giving an error like the below
api-Gateway port : 8999
product-service : 9001
product-detail-service : 9002
eureka-server : 8761
api-gatway application.properties
server.port =8999
spring.application.name = api-gateway
eureka.client.instance.preferIpAddress = true
eureka.client.serviceUrl.defaultZone= http://localhost:8761/eureka
spring.cloud.gateway.routes[0].id=product-service
spring.cloud.gateway.routes[0].uri=lb://product-service
spring.cloud.gateway.routes[0].predicates[0]=Path=/product/**
spring.cloud.gateway.routes[1].id=product-detail-service
spring.cloud.gateway.routes[1].uri=lb://product-detail-service
spring.cloud.gateway.routes[1].predicates[0]=Path=/productDetail/**
eureka-server application.properties
server.port=8761
eureka.client.register-with-eureka = false
eureka.server.waitTimeInMsWhenSyncEmpty = 0
product-detail-service application.properties
server.port=9002
spring.application.name = product-detail-service
eureka.instance.preferIpAddress = true
product-service application.properties
server.port = 9001
spring.application.name = product-service
eureka.client.instance.preferIpAddress = true
docker-compose.yml
version: '3.8'
services:
api-server:
build: ../apigateway
ports:
- 8999:8999
environment:
- eureka.client.service-url.defaultZone=http://eureka-server:8761/eureka
depends_on:
- product-service
- product-detail-service
eureka-server:
build: ../eureka_server
ports:
- 8761:8761
depends_on:
- product-service
- product-detail-service
product-service:
build: ../product_service
ports:
- 9001:9001
environment:
- eureka.client.service-url.defaultZone=http://eureka-server:8761/eureka
depends_on:
- product-detail-service
product-detail-service:
build: ../product_details_service
ports:
- 9002:9002
environment:
- eureka.client.service-url.defaultZone=http://eureka-server:8761/eureka
my docker images are created successfully and are running fine without docker-compose .
I have used networks and much more but still not resolved
Please help I am trying to solve the issue from 3 days

Related

Docker: Eureka clients are not registered in Eureka Server

I have searched over stackoverflow & tried alot of solutions but with no result.
I have 2 containers one is for eureka server and another one for spring cloud gateway.
I'm running these 2 containers with docker-compose but spring-cloud-gateway didn't register to eureka server.
I'm using https. On localhost everything is working as expected but when I jumped to containers this is the problem of unregistered clients.
eureka.server.yml:
eureka:
client:
fetch-registry: false
register-with-eureka: false
instance:
secure-port-enabled: true
non-secure-port-enabled: false
server:
port: 8761
ssl:
enabled: true
key-alias: statement
key-store: classpath:statement-keystore.p12
key-store-password: secret
key-store-type: PKCS12
spring:
application:
name: netflix-eureka
spring.cloud.gateway.yml:
eureka:
instance:
nonSecurePortEnabled: false
securePortEnabled: true
securePort: 8765
prefer-ip-address: true
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: https://localhost:8761/eureka
level:
org:
springframework:
cloud:
gateway: DEBUG
reactor:
netty:
http:
client: DEBUG
server:
port: 8765
ssl:
enabled: true
key-alias: statement
key-store: classpath:statement-keystore.p12
key-store-password: secret
key-store-type: PKCS12
spring:
application:
name: api-gateway
cloud:
config:
enabled: false
gateway:
discovery:
locator:
enabled: true
httpclient:
wiretap: true
httpserver:
wiretap: true
globalcors:
corsConfigurations:
'[/**]':
allowedOrigins: "https://localhost:4200"
allowedHeaders: "*"
allowedMethods:
- GET
- POST
- PUT
- DELETE
spring.cloud.gateway.Dockerfile:
FROM openjdk:11-jre-slim
LABEL Description="SPring cloud gateway" Version="0.0.1"
ARG VERSION=0.0.1
VOLUME /tmp
ADD target/api-gateway-${VERSION}-SNAPSHOT.jar app.jar
RUN sh -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
eureka.server.Dockerfile:
FROM openjdk:11-jre-slim
LABEL Description="Eureka Server" Version="1.0"
ARG VERSION=1.0
VOLUME /tmp
ADD target/eureka-server-${VERSION}-SNAPSHOT.jar app.jar
RUN sh -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
docker-compose.yml:
version: '3.7'
services:
netflix-eureka:
image: abraham/netflix-eureka
container_name: "netflix-eureka"
ports:
- "8761:8761"
networks:
- statement-network
api-gateway:
image: abraham/api-gateway
container_name: "api-gateway"
ports:
- "8765:8765"
networks:
- statement-network
environment:
eureka.client.service-url.default-zone: https://netflix-eureka:8761/eureka
depends_on:
- netflix-eureka
links:
- netflix-eureka
networks:
abraham-network:

How to configure Traefik to be in front of Nginx and a PHP-FPM WebSocket server?

I'd like to use Traefik as a reverse proxy behind a Ratchet WebSocket server (3rd option suggested in deploy section).
The goal is to manage HTTPS and wss with the reverse proxy while keeping a simple HTTP and ws on the Ratchet server.
My WebSocket server exposes on port 8080, like in this example:
public function run()
{
$loop = React\EventLoop\Factory::create();
$pusher = new Pusher();
// Listen for the web server to make a ZeroMQ push after an AJAX request
$context = new React\ZMQ\Context($loop);
$pull = $context->getSocket(ZMQ::SOCKET_PULL);
$pull->bind('tcp://0.0.0.0:5555');
$pull->on('message', array($pusher, 'onEntry'));
// Set up our WebSocket server for clients wanting real-time updates
$webSock = new React\Socket\Server('0.0.0.0:8443', $loop);
$webServer = new IoServer(
new HttpServer(
new WsServer(
new WampServer(
$pusher
)
)
),
$webSock
);
$loop->run();
}
Following this post, I have been able to configure HTTPS via Traefik.
Here is my simplified docker-compose.yml:
nginx:
image: wodby/nginx:$NGINX_TAG
container_name: "${PROJECT_NAME}_nginx"
depends_on:
- php
environment:
NGINX_STATIC_OPEN_FILE_CACHE: "off"
NGINX_ERROR_LOG_LEVEL: debug
NGINX_BACKEND_HOST: php
NGINX_SERVER_ROOT: /var/www/html/webroot
NGINX_VHOST_PRESET: $NGINX_VHOST_PRESET
volumes:
- ./html:/var/www/html:cached
labels:
- "traefik.http.routers.${PROJECT_NAME}_nginx.rule=Host(`${PROJECT_BASE_URL}`)"
- "traefik.http.middlewares.${PROJECT_NAME}_nginx_https.redirectscheme.scheme=https"
- "traefik.http.routers.${PROJECT_NAME}_nginx.entrypoints=web"
- "traefik.http.routers.${PROJECT_NAME}_nginx.middlewares=${PROJECT_NAME}_nginx_https#docker"
- "traefik.http.routers.${PROJECT_NAME}_nginx_https.rule=Host(`${PROJECT_BASE_URL}`)"
- "traefik.http.routers.${PROJECT_NAME}_nginx_https.tls=true"
- "traefik.http.routers.${PROJECT_NAME}_nginx_https.entrypoints=websecure"
php:
build:
context: .
dockerfile: docker/php-fpm/Dockerfile
container_name: "${PROJECT_NAME}_php"
volumes:
- ./html:/var/www/html
labels:
- "traefik.http.routers.php.rule=Host(`${PROJECT_BASE_URL}`)"
traefik:
image: traefik:v2.0
container_name: "${PROJECT_NAME}_traefik"
command:
- "--api.insecure=true"
- "--entrypoints.web.address=:80"
- "--entrypoints.websecure.address=:443"
- "--providers.docker=true"
- "--providers.file.filename=/etc/traefik/dynamic_conf/config.yml"
- "--providers.file.watch=true"
ports:
- "80:80"
- "443:443"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
- "./docker/traefik/config.yml:/etc/traefik/dynamic_conf/config.yml" # used to define the certificate path
- "./docker/certs:/tools/certs"
However, how can I now forward HTTPS/wss to HTTP/ws to the php service?

Laravel Dusk is not working on Docker/ docker-compose.yaml

I am working on a Laravel project. I started writing browser tests using Dusk. I am using docker as my development environment. When I run the tests, I am getting the "Connection refused" error.
This is my docker-compose.yaml file.
version: '3'
services:
apache:
container_name: res_apache
image: webdevops/apache:ubuntu-16.04
environment:
WEB_DOCUMENT_ROOT: /var/www/public
WEB_ALIAS_DOMAIN: restaurant.localhost
WEB_PHP_SOCKET: php-fpm:9000
volumes: # Only shared dirs to apache (to be served)
- ./public:/var/www/public:cached
- ./storage:/var/www/storage:cached
networks:
- res-network
ports:
- "8081:80"
- "443:443"
php-fpm:
container_name: res_php
image: jguyomard/laravel-php:7.3
volumes:
- ./:/var/www/
- ./ci:/var/www/ci:cached
- ./vendor:/var/www/vendor:delegated
- ./storage:/var/www/storage:delegated
- ./node_modules:/var/www/node_modules:cached
- ~/.ssh:/root/.ssh:cached
- ./composer.json:/var/www/composer.json
- ./composer.lock:/var/www/composer.lock
- ~/.composer/cache:/root/.composer/cache:delegated
networks:
- res-network
db:
container_name: res_db
image: mariadb:10.2
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: restaurant
MYSQL_USER: restaurant
MYSQL_PASSWORD: secret
volumes:
- res-data:/var/lib/mysql
networks:
- res-network
ports:
- "33060:3306"
chrome:
image: robcherry/docker-chromedriver
networks:
- res-network
environment:
CHROMEDRIVER_WHITELISTED_IPS: ""
CHROMEDRIVER_PORT: "9515"
ports:
- 9515:9515
cap_add:
- "SYS_ADMIN"
networks:
res-network:
driver: "bridge"
volumes:
res-data:
driver: "local"
The following is the driver function in DuskTestCase.php class
/**
* Create the RemoteWebDriver instance.
*
* #return \Facebook\WebDriver\Remote\RemoteWebDriver
*/
protected function driver()
{
$options = (new ChromeOptions)->addArguments([
'--disable-gpu',
'--headless',
'--window-size=1920,1080',
]);
return RemoteWebDriver::create(
'http://localhost:9515', DesiredCapabilities::chrome()->setCapability(
ChromeOptions::CAPABILITY, $options
)
);
}
I run the tests running the following command.
docker-compose exec php-fpm php artisan dusk
Then I get the following error.
Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session with params: {"capabilities":{"firstMatch":[{"browserName":"chrome","goog:chromeOptions":{"args":["--disable-gpu","--headless","--windo
w-size=1920,1080"]}}]},"desiredCapabilities":{"browserName":"chrome","platform":"ANY","chromeOptions":{"args":["--disable-gpu","--headless","--window-size=1920,1080"]}}}
Failed to connect to localhost port 9515: Connection refused
/var/www/vendor/php-webdriver/webdriver/lib/Remote/HttpCommandExecutor.php:331
What is wrong with my configuration and how can I fix it?

How to update configurations using spring cloud config server and spring cloud bus with rabbit mq?

I could not find any up to date and / or working documentation and / or example on how to set this up so what I did is researching and try and error. Yet I have not been able to get it running.
Im having a config-server with the following dependencies:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
<version>2.2.1.RELEASE</version>
</dependency>
The config-server has the following bootstrap.yml:
spring:
application:
name: config-server
rabbitmq:
host: ${RABBIT_MQ_HOST:localhost}
port: ${RABBIT_MQ_PORT:5672}
username: ${RABBIT_MQ_URSER_NAME:guest}
password: ${RABBIT_MQ_URSER_PASSWORD:guest}
And the following application.yml
spring:
cloud:
config:
server:
git:
uri: https://github.com/MyGit/config-repository.git
cloneOnStart: true
management:
endpoints:
web:
exposure:
include: "*"
server:
port: 8888
All my clients are having the following dependencies:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
<version>2.2.1.RELEASE</version>
</dependency>
Their bootstrap.yml for example looks like this:
spring:
application:
name: user-service
cloud:
config:
uri: http://${CONFIG_HOST:localhost}:${CONFIG_PORT:8888}
rabbitmq:
host: ${RABBIT_MQ_HOST:localhost}
port: ${RABBIT_MQ_PORT:5672}
username: ${RABBIT_MQ_URSER_NAME:guest}
password: ${RABBIT_MQ_URSER_PASSWORD:guest}
And their application.yml like this:
management:
endpoints:
web:
exposure:
include: "*"
server:
port: 8000
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://${EUREKA_HOST:localhost}:${EUREKA_PORT:8761}/eureka
Im using springs #ConfigurationProperties, for example:
#Component
#ConfigurationProperties("user")
#Getter
#Setter
public class UserConfiguration {
private String role;
}
I'm starting all my services (including rabbitmq) using docker and docker-compose:
version: "3"
services:
rabbitmq:
image: bitnami/rabbitmq:latest
container_name: rabbitmq
environment:
RABBITMQ_USERNAME: admin
RABBITMQ_PASSWORD: admin
ports:
- "4369:4369"
- "5672:5672"
- "15672:15672"
- "25672:25672"
config-server:
build:
context: config-server
dockerfile: Dockerfile
container_name: config-server
depends_on:
- rabbitmq
environment:
RABBIT_MQ_HOST: "rabbitmq"
RABBIT_MQ_PORT: "5672"
RABBIT_MQ_URSER_NAME: "admin"
RABBIT_MQ_URSER_PASSWORD: "admin"
ports:
- "8888:8888"
eureka-server:
build:
context: eureka-server
dockerfile: Dockerfile
container_name: eureka-server
depends_on:
- rabbitmq
- config-server
environment:
RABBIT_MQ_HOST: "rabbitmq"
RABBIT_MQ_PORT: "5672"
RABBIT_MQ_URSER_NAME: "admin"
RABBIT_MQ_URSER_PASSWORD: "admin"
CONFIG_HOST: "config-server"
CONFIG_PORT: "8888"
ports:
- "8761:8761"
zuul-gateway:
build:
context: zuul-gateway
dockerfile: Dockerfile
container_name: zuul-gateway
depends_on:
- rabbitmq
- config-server
- eureka-server
environment:
RABBIT_MQ_HOST: "rabbitmq"
RABBIT_MQ_PORT: "5672"
RABBIT_MQ_URSER_NAME: "admin"
RABBIT_MQ_URSER_PASSWORD: "admin"
CONFIG_HOST: "config-server"
CONFIG_PORT: "8888"
EUREKA_HOST: "eureka-server"
EUREKA_PORT: "8761"
ports:
- "8765:8765"
user-service:
build:
context: user-service
dockerfile: Dockerfile
container_name: user-service
depends_on:
- rabbitmq
- config-server
- eureka-server
environment:
SPRING_PROFILES_ACTIVE: "development"
RABBIT_MQ_HOST: "rabbitmq"
RABBIT_MQ_PORT: "5672"
RABBIT_MQ_URSER_NAME: "admin"
RABBIT_MQ_URSER_PASSWORD: "admin"
CONFIG_HOST: "config-server"
CONFIG_PORT: "8888"
EUREKA_HOST: "eureka-server"
EUREKA_PORT: "8761"
ports:
- "8000:8000"
user-service-2:
build:
context: user-service
dockerfile: Dockerfile
container_name: user-service-2
depends_on:
- rabbitmq
- config-server
- eureka-server
environment:
SPRING_PROFILES_ACTIVE: "development"
RABBIT_MQ_HOST: "rabbitmq"
RABBIT_MQ_PORT: "5672"
RABBIT_MQ_URSER_NAME: "admin"
RABBIT_MQ_URSER_PASSWORD: "admin"
CONFIG_HOST: "config-server"
CONFIG_PORT: "8888"
EUREKA_HOST: "eureka-server"
EUREKA_PORT: "8761"
ports:
- "8001:8000"
user-service-3:
build:
context: user-service
dockerfile: Dockerfile
container_name: user-service-3
depends_on:
- rabbitmq
- config-server
- eureka-server
environment:
SPRING_PROFILES_ACTIVE: "development"
RABBIT_MQ_HOST: "rabbitmq"
RABBIT_MQ_PORT: "5672"
RABBIT_MQ_URSER_NAME: "admin"
RABBIT_MQ_URSER_PASSWORD: "admin"
CONFIG_HOST: "config-server"
CONFIG_PORT: "8888"
EUREKA_HOST: "eureka-server"
EUREKA_PORT: "8761"
ports:
- "8002:8000"
When all my services are started, at first everything seems to be fine. All services are registered with eureka, all services are callable on localhost and they can talk to each other.
But the config refresh is not working.
When I change something in my config repository and commit and push it it has no effect on my services. The configuration they have stays the same. When I manually call the bus refresh on my config-server:
http://localhost:8888/bus/refresh
with POST, like it is described in nearly every guide I could find so far, I get the response:
{
"timestamp": "2020-03-30T09:33:57.818+0000",
"status": 405,
"error": "Method Not Allowed",
"message": "Request method 'POST' not supported",
"path": "/bus/refresh"
}
When I use GET instead, I get:
{
"name": "bus",
"profiles": [
"refresh"
],
"label": null,
"version": "03759e798f3516da6a18fc8b61a265d37ddeff4e",
"state": null,
"propertySources": []
}
and it also has no effect on the confiuration of my services.
And when I call the bus refresh on any of my services I get:
{
"timestamp": "2020-03-30T09:35:39.643+0000",
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/bus/refresh"
}
What do I need to do to get the auto configuration refresh working?
Manually calling the /actuator/refresh endpoints on the services works. They are then pulling the new config. So it seems like the rabbit mq simply is not working.
I found the solution.
Acutally my setup and configuration files are totally fine, I just called the wrong endpoint. Instead of calling:
http://localhost:8888/bus/refresh
I have to call:
http://localhost:8888/actuator/bus-refresh
This works on any service I started. It will automatically send a message to rabbitmq which will then publish the refresh to all consumers. All configurations are then updating.
Though I still dont know why bus/refresh is not working. It is used in many examples / tutorials.

Spring on docker, environment variables not evaluated with configuration placeholders

I have a Spring project and use an application.yml file to run configure it. When using placeholders in the configuration file and run it as a built docker image it will not evaluate the placeholder, whereas this works fine when running the jar without docker. What could be wrong here?
org.postgresql.util.PSQLException: FATAL: password authentication failed for user "${POSTGRES_DB_USER}"
application.yml
server:
compression:
enabled: true
mime-types: application/json,application/xml,text/html,text/xml,text/plain
context-path: /
port: 8085
logging:
config: config/log4j2-spring.xml
spring:
datasource:
url: jdbc:h2:./data/cdr
username: sa
password:
jpa:
hibernate:
ddl-auto: create-drop
security:
user:
password: secretpassword
---
spring:
profiles: docker
datasource:
url: jdbc:postgresql://postgres/databasename
username: ${POSTGRES_DB_USER}
password: ${POSTGRES_DB_PASS}
docker-compose.yml
version: '2'
services:
application:
image: domain.com:3000/application:0-SNAPSHOT
volumes:
- application:/application/logs
ports:
- 8085:8085
links:
- postgres
environment:
PASSWORD: secretpassword
postgres:
image: sameersbn/postgresql:9.5-2
volumes:
- postgres-data:/var/lib/postgresql
environment:
DB_NAME: databasename
DB_USER: user
DB_PASS: secretpassword
volumes:
postgres-data:
driver: local
application-logs:
driver: local
I think you want this:
version: '2'
services:
application:
image: domain.com:3000/application:0-SNAPSHOT
volumes:
- application-logs:/application/logs
ports:
- 8085:8085
environment:
POSTGRES_DB_USER: user
POSTGRES_DB_PASS: secretpassword
postgres:
image: sameersbn/postgresql:9.5-2
volumes:
- postgres-data:/var/lib/postgresql
environment:
DB_NAME: databasename
DB_USER: user
DB_PASS: secretpassword
volumes:
postgres-data: {}
application-logs: {}

Resources