iluwatar / java-design-patterns

Design patterns implemented in Java
https://java-design-patterns.com
Other
89.55k stars 26.48k forks source link

Microservice pattern: Self registration #2687

Open iluwatar opened 11 months ago

iluwatar commented 11 months ago

Description:

The Microservices - Self Registration design pattern enables microservices to dynamically register themselves with a central registry when they start. This pattern is crucial for managing microservices in a dynamic environment where services can be added, removed, or updated frequently. By implementing this pattern, microservices become discoverable by other services, which allows for better scalability, resilience, and flexibility within the system.

Main Elements of the Pattern:

  1. Service Registry: A central repository that holds information about all available microservices.
  2. Service Instance: The actual microservices that need to register themselves with the service registry.
  3. Heartbeat Mechanism: A periodic check to ensure that registered services are still available and healthy.
  4. Discovery Client: A component that other microservices use to find and interact with the registered services.

Key Components to Implement:

  1. Service Registry Implementation: Set up a central registry using tools like Eureka, Consul, or Zookeeper.
  2. Service Registration: Code within each microservice to register itself with the central registry upon startup.
  3. Heartbeat/Health Check: Mechanism to ensure continuous availability and health status reporting of the services.
  4. Service Discovery Client: Implementation to enable other services to discover and communicate with registered services.

References:

Acceptance Criteria:

  1. Service Registry Setup:
    • A central service registry must be configured and running (e.g., Eureka, Consul, Zookeeper).
  2. Microservice Registration:
    • Each microservice must automatically register itself with the central registry upon startup.
  3. Health Check Mechanism:
    • A heartbeat or health check mechanism must be implemented to monitor the health of registered services.
  4. Service Discovery:
    • Other microservices must be able to discover and communicate with registered services using a discovery client.
  5. Documentation:
    • Comprehensive documentation must be provided, including setup instructions, code examples, and usage guidelines.
Pat-r1ck commented 10 months ago

Hi, can you assign me this one?

Pat-r1ck commented 10 months ago

just to clarify, I just have to design a microservice that has a discovery server and other services that meet the following criteria:

am I correct?

iluwatar commented 10 months ago

Yeah, look at the solution chapter for some implementation tips

stale[bot] commented 8 months ago

This issue has been automatically marked as stale because it has not had recent activity. The issue will be unassigned if no further activity occurs. Thank you for your contributions.

BahaBoualii commented 1 day ago

@iluwatar can I start working on this one?