Technolords / microservice-mock

A webservice to mock other web services, suitable for testing, for performance or regular. Optionally add delay or error codes. (latest release: 1.6.0)
MIT License
14 stars 7 forks source link

Add support to registry in Netflix Eureka or Consul Service Discovery #50

Closed jsoladur closed 6 years ago

jsoladur commented 6 years ago

If I want integrate in the Netflix microservices ecosystem, I need that I can config in the XML file the endpoint Eureka Service Registry or Consul Service Registry in order to registry this microservice, as if it were a real service

Technolords commented 6 years ago

Interesting idea and I see the benefit of this. Going to work on the Consul part first.

Technolords commented 6 years ago

Been playing and testing with it. Upon registration, I queried Consul for it's services:

{
    "mock-1": {
        "Kind": "",
        "ID": "mock-1",
        "Service": "mock-service",
        "Tags": [
            "mock"
        ],
        "Meta": {
            "GET": "/mock/get, /mock/*/get, /mock/1/get, /mock/*/get, /mock/1/get"
        },
        "Port": 9090,
        "Address": "192.168.10.23",
        "EnableTagOverride": false,
        "CreateIndex": 0,
        "ModifyIndex": 0,
        "ProxyDestination": "",
        "Connect": null
    }
}

... and the checks:

{
    "service:mock-1": {
        "Node": "97068118c16b",
        "CheckID": "service:mock-1",
        "Name": "Service 'mock-service' check",
        "Status": "passing",
        "Notes": "",
        "Output": "HTTP GET http://192.168.10.23:9090/mock/cmd?config=current: 200 OK Output: <SNIPPED/>",
        "ServiceID": "mock-1",
        "ServiceName": "mock-service",
        "ServiceTags": [
            "mock"
        ],
        "Definition": {},
        "CreateIndex": 0,
        "ModifyIndex": 0
    }
}

See also the attachments where I made screenshots of Consul before and after consul-after-registration consul-before-registration

@josemariasoladuran is this something you wanted?

jsoladur commented 6 years ago

Yes, it's exatly that I wanted. Only one detail. Send Consul the URL of health check microservices mock, and implemented handleGet for URL /health. It's very important in order to Consul can check the live of the microservice mock. Thank you for your quickly support!

jsoladur commented 6 years ago

¿What happen with Eureka? It's a Netflix service registry and I think that it is the most used.

jsoladur commented 6 years ago

@Technolords is important that you can register the microservice mock in the more than one endpoint Consul or Eureka. Sometimes, the microservices ecosystems replicate service discovery

Technolords commented 6 years ago

Oke, I'll make this flexible so you can register with many service registries, so the mock becomes shared between clusters if needed to be.

Current configuration (prototype) looks like:

  <service-registration>
    <consul address="192.168.10.14" port="8500">
      <service address="192.168.10.10" port="9090" id="mock-1" name="mock-service" >
        <health-check enabled="true" interval="60s" deregister-after="90m"/>
      </service>
    </consul>
  </service-registration>

... so the extension will look like:

  <service-registration>
    <consul ... />
    <consul ... />
    <eureka ... />
    <eureka ... />
  </service-registration>

Btw, to answer your question regarding health checks. This is covered and working. An example of a failed health check looks like: consul-with-failed-health-check

Technolords commented 6 years ago

Implemented, tested, released and documented: