Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
ADDED: communication with eureka
Browse files Browse the repository at this point in the history
  • Loading branch information
AleixMT committed Jan 16, 2024
1 parent 518f578 commit 9830e3e
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 4 deletions.
14 changes: 10 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
version: "2.1"
services:
book-a-book-buscador:
image: aleixmt/book-a-book-buscador:latest
ports:
- "0.0.0.0:8082:8081"
#book-a-book-buscador:
# image: aleixmt/book-a-book-buscador:latest
# ports:
# - "0.0.0.0:8082:8081"
#restart: unless-stopped

book-a-book-operador:
Expand All @@ -13,6 +13,12 @@ services:
- "0.0.0.0:8084:8083"
#restart: unless-stopped

book-a-book-eureka:
image: aleixmt/book-a-book-eureka:latest
ports:
- "0.0.0.0:8762:8761"
restart: unless-stopped

postgres_db:
image: postgres
environment:
Expand Down
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
<scope>test</scope>
</dependency>

<!-- Eureka Client dependency -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>4.1.0</version>
</dependency>

<!-- For swagger in Spring Boot 3 -->
<dependency>
<groupId>org.springdoc</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package net.unir.missi.desarrollowebfullstack.bookabook.operador.controller;

import org.springframework.web.bind.annotation.RequestMapping;

public interface EurekaGreetingController {

String greeting();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package net.unir.missi.desarrollowebfullstack.bookabook.operador.controller;

import com.netflix.discovery.EurekaClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class EurekaGreetingControllerImpl implements EurekaGreetingController {

@Autowired
@Lazy
private EurekaClient eurekaClient;

@Value("${spring.application.name}")
private String appName;

@Override
@RequestMapping("/greeting")
public String greeting() {
return String.format(
"Hello from '%s'!", eurekaClient.getApplication(appName).getName());
}
}
12 changes: 12 additions & 0 deletions src/main/resources/application-prod.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,15 @@ spring.jpa.show-sql=true
# Format of the SQL queries written in the output
spring.jpa.properties.hibernate.format_sql=true

######################
### SERVER CONFIG ####
######################
# Random port because we will access this service by its name
server.port=0


##############
### EUREKA ###
##############
# URL of the Eureka service
eureka.client.serviceUrl.defaultZone=${EUREKA_URI:http://book-a-book-eureka:8761/eureka}
11 changes: 11 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,14 @@ server.port=8083
##############
# swagger-ui custom path
springdoc.swagger-ui.path=/swagger-ui.html


##############
### EUREKA ###
##############
# Configure application name for
spring.application.name=operador
# URL of the Eureka service
eureka.client.serviceUrl.defaultZone=${EUREKA_URI:http://localhost:8761/eureka}
# Use IP address
eureka.instance.preferIpAddress=true

0 comments on commit 9830e3e

Please sign in to comment.