Skip to content

feat: add eureka and nacos support #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ java -jar demo.jar --server.port=8081

The default username is `admin`, and password is: `123456`.

## Service Registry Center

This project can register itself to the service registry center.

### Nacos

Register to [Nacos](https://github.com/alibaba/nacos):

```shell
java -jar demo.jar --nacos.server.enabled=true \
--nacos.server-addr=192.168.10.52:8448
```

## OpenAPI definition
You can visit it via: http://localhost:8080/v3/api-docs

Expand Down
60 changes: 54 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.0</version>
<version>3.4.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>io.github.devops-ws</groupId>
Expand All @@ -17,6 +17,9 @@
<properties>
<java.version>17</java.version>
<trpc-maven-plugin.version>1.0.0</trpc-maven-plugin.version>
<nacos.version>0.3.0-RC</nacos.version>
<spring-cloud.version>2024.0.1</spring-cloud.version>
<spring-boot.version>3.4.4</spring-boot.version>
</properties>

<dependencies>
Expand All @@ -35,6 +38,39 @@
<artifactId>spring-boot-starter-graphql</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-netflix-eureka-client</artifactId>
<version>3.1.8</version>
</dependency>

<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-config-spring-boot-starter</artifactId>
<version>${nacos.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-config-spring-boot-actuator</artifactId>
<version>${nacos.version}</version>
</dependency>

<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-discovery-spring-boot-starter</artifactId>
<version>${nacos.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-discovery-spring-boot-actuator</artifactId>
<version>${nacos.version}</version>
</dependency>

<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
Expand All @@ -47,10 +83,6 @@
<version>1.1.0</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
Expand All @@ -65,6 +97,22 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</path>
<path>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
Expand All @@ -75,7 +123,7 @@
<version>${trpc-maven-plugin.version}</version>
<executions>
<execution>
<phase>validate</phase>
<phase>validate</phase>
<goals>
<goal>gen-code</goal>
</goals>
Expand Down
54 changes: 53 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,57 @@
# https://spring.io/guides/gs/graphql-server/
spring:
application:
name: learn-springboot
graphql:
graphiql:
enabled: true
cloud:
discovery:
enabled: true
loadbalancer:
hint-header-name: ${DEV_MODE:dev}
zone: ${DEV_MODE:dev}
nacos:
discovery:
metadata:
ephemeral: false

server:
port: 8080

nacos:
discovery:
auto-register: ${nacos.server.enabled:false}
register:
enabled: ${nacos.server.enabled:false}
server-addr: ${nacos.server-addr:127.0.0.1:8848}
client:
grpc:
enable: false

eureka:
instance:
prefer-ip-address: true
ip-address: ${server.ip:127.0.0.1}
non-secure-port: ${server.port:8080}
hostname: ${server.ip:127.0.0.1}
instance-id: ${server.ip:127.0.0.1}:${spring.application.name}:${server.port:8080}
metadata-map:
hint: ${DEV_MODE:dev}
zone: ${DEV_MODE:dev}
health-check-url-path: /actuator/health
status-page-url-path: /actuator/info
home-page-url-path: /actuator/info

client:
enabled: ${EUREKA_ENABLED:false}
fetch-registry: true
register-with-eureka: true
healthcheck:
enabled: true
service-url:
defaultZone: ${EUREKA_URL:http://127.0.0.1:17001/eureka}

trpc:
server:
app: TestApp # App name
Expand All @@ -17,7 +62,7 @@ trpc:
impls: # Service implement classes
- io.github.devopsws.demo.service.TRPCService
ip: 0.0.0.0 # Listen ip
port: 9090 # Listen port
port: ${trpc.server.port:9090} # Listen port
network: tcp # Network type, tcp or udp

# https://spring.academy/guides/spring-spring-prometheus
Expand All @@ -29,3 +74,10 @@ management:
metrics:
tags:
application: ${spring.application.name}

logging:
level:
root: info
org.springframework.web: info
org.springframework.cloud: info
org.springframework.cloud.netflix.eureka: debug
Loading