main -> Principal mesmo que a master develop -> Branch para desenvolvimento, no qual, são feito os merges das features
feature/
bugfix/
release/
hotfix/
support/
https://itau.udemy.com/course/microsservicos-java-spring-cloud/
Script SQL
INSERT INTO tb_worker (name, daily_Income) VALUES ('Bob', 200.0);
INSERT INTO tb_worker (name, daily_Income) VALUES ('Maria', 300.0);
INSERT INTO tb_worker (name, daily_Income) VALUES ('Alex', 250.0);
application.properties
spring.application.name=hr-worker
server.port=8001
# Database configuration
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.username=sa
spring.datasource.password=
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console
application.properties
spring.application.name=hr-payroll
server.port=8101
Run configuration
-Dserver.port=8002
Porta padrão: 8761
Acessar o dashboard no navegador: http://localhost:8761
Eliminar o Ribbon de hr-payroll:
- Dependência Maven
- Annotation no programa principal
- Configuração em application.properties
Atenção: aguardar um pouco depois de subir os microsserviços
server.port=${PORT:0}
eureka.instance.instance-id=${spring.application.name}:${spring.application.instance_id:${random.value}}
Atenção: deletar as configurações múltiplas de execução de hr-worker
Atenção: testar antes sem a annotation do Hystrix
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=60000
ribbon.ConnectTimeout=10000
ribbon.ReadTimeout=20000
Porta padrão: 8765
Mesmo o timeout de Hystrix e Ribbon configurado em um microsserviço, se o Zuul não tiver seu timeout configurado, para ele será um problema de timeout. Então precisamos configurar o timeout no Zuul.
Se o timeout estiver configurado somente em Zuul, o Hystrix vai chamar o método alternativo no microsserviço específico.
Quando um microsserviço é levantado, antes de se registrar no Eureka, ele busca as configurações no repositório central de configurações.
hr-worker.properties
test.config=My config value default profile
hr-worker-test.properties
test.config=My config value test profile
Teste:
http://localhost:8888/hr-worker/default
http://localhost:8888/hr-worker/test
No arquivo bootstrap.properties configuramos somente o que for relacionado com o servidor de configuração, e também o profile do projeto.
Atenção: as configurações do bootstrap.properties tem prioridade sobre as do application.properties
Atenção: colocar @RefreshScope em toda classe que possua algum acesso às configurações
Atenção: reinicie a IDE depois de adicionar as variáveis de ambiente
INSERT INTO tb_user (name, email, password) VALUES ('Nina Brown', '[email protected]', '$2a$10$NYFZ/8WaQ3Qb6FCs.00jce4nxX9w7AkgWVsQCG6oUwTAcZqP9Flqu');
INSERT INTO tb_user (name, email, password) VALUES ('Leia Red', '[email protected]', '$2a$10$NYFZ/8WaQ3Qb6FCs.00jce4nxX9w7AkgWVsQCG6oUwTAcZqP9Flqu');
INSERT INTO tb_role (role_name) VALUES ('ROLE_OPERATOR');
INSERT INTO tb_role (role_name) VALUES ('ROLE_ADMIN');
INSERT INTO tb_user_role (user_id, role_id) VALUES (1, 1);
INSERT INTO tb_user_role (user_id, role_id) VALUES (2, 1);
INSERT INTO tb_user_role (user_id, role_id) VALUES (2, 2);
Source -> Override -> configure(AuthenticationManagerBuilder)
Source -> Override -> authenticationManager()
Basic authorization = "Basic " + Base64.encode(client-id + ":" + client-secret)
Variáveis:
- api-gateway: http://localhost:8765
- config-host: http://localhost:8888
- client-name: CLIENT-NAME
- client-secret: CLIENT-SECRET
- username: [email protected]
- password: 123456
- token:
Script para atribuir token à variável de ambiente do Postman:
if (responseCode.code >= 200 && responseCode.code < 300) {
var json = JSON.parse(responseBody);
postman.setEnvironmentVariable('token', json.access_token);
}
Teste no navegador:
fetch("http://localhost:8765/hr-worker/workers", {
"headers": {
"accept": "*/*",
"accept-language": "en-US,en;q=0.9,pt-BR;q=0.8,pt;q=0.7",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "cross-site"
},
"referrer": "http://localhost:3000",
"referrerPolicy": "no-referrer-when-downgrade",
"body": null,
"method": "GET",
"mode": "cors",
"credentials": "omit"
});
docker network create hr-net
docker pull postgres:12-alpine
docker run -p 5432:5432 --name hr-worker-pg12 --network hr-net -e POSTGRES_PASSWORD=1234567 -e POSTGRES_DB=db_hr_worker postgres:12-alpine
docker run -p 5432:5432 --name hr-user-pg12 --network hr-net -e POSTGRES_PASSWORD=1234567 -e POSTGRES_DB=db_hr_user postgres:12-alpine
FROM openjdk:11
VOLUME /tmp
EXPOSE 8888
ADD ./target/hr-config-server-0.0.1-SNAPSHOT.jar hr-config-server.jar
ENTRYPOINT ["java","-jar","/hr-config-server.jar"]
mvnw clean package
docker build -t hr-config-server:v1 .
docker run -p 8888:8888 --name hr-config-server --network hr-net -e GITHUB_USER=acenelio -e GITHUB_PASS= hr-config-server:v1
FROM openjdk:11
VOLUME /tmp
EXPOSE 8761
ADD ./target/hr-eureka-server-0.0.1-SNAPSHOT.jar hr-eureka-server.jar
ENTRYPOINT ["java","-jar","/hr-eureka-server.jar"]
mvnw clean package
docker build -t hr-eureka-server:v1 .
docker run -p 8761:8761 --name hr-eureka-server --network hr-net hr-eureka-server:v1
FROM openjdk:11
VOLUME /tmp
ADD ./target/hr-worker-0.0.1-SNAPSHOT.jar hr-worker.jar
ENTRYPOINT ["java","-jar","/hr-worker.jar"]
mvnw clean package -DskipTests
docker build -t hr-worker:v1 .
docker run -P --network hr-net hr-worker:v1
FROM openjdk:11
VOLUME /tmp
ADD ./target/hr-user-0.0.1-SNAPSHOT.jar hr-user.jar
ENTRYPOINT ["java","-jar","/hr-user.jar"]
mvnw clean package -DskipTests
docker build -t hr-user:v1 .
docker run -P --network hr-net hr-user:v1
FROM openjdk:11
VOLUME /tmp
ADD ./target/hr-payroll-0.0.1-SNAPSHOT.jar hr-payroll.jar
ENTRYPOINT ["java","-jar","/hr-payroll.jar"]
mvnw clean package -DskipTests
docker build -t hr-payroll:v1 .
docker run -P --network hr-net hr-payroll:v1
FROM openjdk:11
VOLUME /tmp
ADD ./target/hr-oauth-0.0.1-SNAPSHOT.jar hr-oauth.jar
ENTRYPOINT ["java","-jar","/hr-oauth.jar"]
mvnw clean package -DskipTests
docker build -t hr-oauth:v1 .
docker run -P --network hr-net hr-oauth:v1
FROM openjdk:11
VOLUME /tmp
EXPOSE 8765
ADD ./target/hr-api-gateway-zuul-0.0.1-SNAPSHOT.jar hr-api-gateway-zuul.jar
ENTRYPOINT ["java","-jar","/hr-api-gateway-zuul.jar"]
mvnw clean package -DskipTests
docker build -t hr-api-gateway-zuul:v1 .
docker run -p 8765:8765 --name hr-api-gateway-zuul --network hr-net hr-api-gateway-zuul:v1
Criar uma rede Docker
docker network create <nome-da-rede>
Baixar imagem do Dockerhub
docker pull <nome-da-imagem:tag>
Ver imagens
docker images
Criar/rodar um container de uma imagem
docker run -p <porta-externa>:<porta-interna> --name <nome-do-container> --network <nome-da-rede> <nome-da-imagem:tag>
Listar containers
docker ps
docker ps -a
Acompanhar logs do container em execução
docker logs -f <container-id>