Skip to content

justedlev/bridgewayhub

Repository files navigation

BridgeWay Hub

🧱 API Gateway

language framework Docker Image Version license stars issues

📋 About

BridgeWay Hub example implementation of API Gateway based on Spring Boot 3, Keycloak as a security layer and Eureka Client as service registry, in microservice architecture, detailed configuration will depend directly on additional business requirements and is applied in the application properties. For more details

🧾 References

⚠️ Requirements

Before running the app you need to configure the next services that depends on:

  • Keycloak - security layer
  • DB for Keycloak optional
  • Eureka Server, my solution optional

▶️ Run

Intellij

To run the app you can use simple run configuration (Intellij IDEA), that based on .env and jvm options

<component name="ProjectRunConfigurationManager">
    <configuration default="false" name="Default" type="SpringBootApplicationConfigurationType"
                   factoryName="Spring Boot">
        <option name="envFilePaths">
            <option value="$PROJECT_DIR$/.env"/>
        </option>
        <option name="FRAME_DEACTIVATION_UPDATE_POLICY" value="UpdateClassesAndResources"/>
        <module name="bridgewayhub"/>
        <selectedOptions>
            <option name="environmentVariables"/>
        </selectedOptions>
        <option name="SPRING_BOOT_MAIN_CLASS" value="io.justedlev.msrv.bridgeway.BridgeWayHubApplication"/>
        <option name="VM_PARAMETERS" value="@.vmoptions"/>
        <method v="2">
            <option name="Make" enabled="true"/>
        </method>
    </configuration>
</component>

Warning

Make sure that the next services already started

  • Service Registry (eureka server)
  • Keycloak server
  • Postgres DB

Note

The Service Registry (Discovery Service) can be disabled by using the properties if needed

spring:
  cloud:
    discovery:
      enabled: false
eureka:
  client:
    enabled: false

Tip

You can also disable it in .vmoptions, just adding the envs

-Dspring.cloud.discovery.enabled=false
-Deureka.client.enabled=false

OR

You can add the env props to the .env

SPRING_CLOUD_DISCOVERY_ENABLED=false
EUREKA_CLIENT_ENABLED=false

🐳 Docker

First build your amazing 😁 docker compose file and then run using the below cmd

docker compose build -d

Tip

I already prepared some image on 🐳 docker hub

📝 Docker compose

Simple command to run the container:

docker compose up -d --build

The full compose.yaml that I personally use

name: justedlev-msrv
services:
  api-gateway:
    container_name: bridgewayhub
    image: justedlev/bridgewayhub:latest
    build:
      context: docs
    env_file:
      - .env
    ports:
      - "8765:${SERVER_PORT}"
    depends_on:
      - sso
      - service-registry

  # Service discovery
  service-registry:
    container_name: eureka-server
    image: justedlev/simple-eureka-server:latest
    environment:
      SERVER_PORT: 8761
      EUREKA_INSTANCE_HOSTNAME: service-registry
      SPRING_SECURITY_USER_NAME: example
      SPRING_SECURITY_USER_PASSWORD: example
    ports:
      - "8761:${SERVER_PORT}"

  # SSO service (keycloak)
  sso:
    container_name: keycloak
    image: quay.io/keycloak/keycloak:25.0.6
    command: [ "start-dev" ]
    environment:
      KEYCLOAK_ADMIN: "{example}"
      KEYCLOAK_ADMIN_PASSWORD: "{example}"
      KC_HEALTH_ENABLED: true
      KC_HOSTNAME: localhost
      KC_DB: postgres
      KC_DB_URL: jdbc:postgresql://postgres:5432/{example}
      KC_DB_USERNAME: "{example}"
      KC_DB_PASSWORD: "{example}"
      KC_DB_SCHEMA: keycloak
    depends_on:
      - postgres
    ports:
      - "9321:8080"

  # Postgres DB
  postgres:
    container_name: postgres
    image: postgres:16.4-alpine
    environment:
      POSTGRES_DB: "{example}"
      POSTGRES_USER: "{example}"
      POSTGRES_PASSWORD: "{example}"
    volumes:
      - db-data:/var/lib/postgresql/data
      - /.db:/docker-entrypoint-initdb.d
    ports:
      - "5432:5432"
    healthcheck:
      test: [ "CMD", "pg_isready", "-U", "${POSTGRES_USER}", "-d" ]
      interval: 15s
      timeout: 10s
      retries: 5
      start_period: 12s
    restart: unless-stopped
    deploy:
      resources:
        limits:
          cpus: "1"
          memory: 250MB

volumes:
  db-data: