Knotx / knotx

Knot.x is a highly-efficient and scalable integration framework designed to build backend APIs
https://knotx.io
Apache License 2.0
126 stars 26 forks source link

Move service definition from Knots to Adapters configuration #195

Closed malaskowski closed 6 years ago

malaskowski commented 7 years ago

The goal of this task is to move services section from Knot configuration to Adapter configuration. Example: current

    "com.cognifide.knotx.knot.service.ServiceKnotVerticle": {
     "config": {
        "address": "knotx.knot.service",
        ...
        "services": [
          {
            "name" : "first-service",
            "address" : "knotx.adapter.service.http",
            "params": {
              "path": "/service/mock/first.json"
            },
            "cacheKey": "first"
          },
          {
            "name" : "second-service",
            "address" : "knotx.adapter.service.http",
            "params": {
              "path": "/service/mock/second.json"
            }
          }
        ]
      }
    },

...

"com.cognifide.knotx.adapter.service.http.HttpServiceAdapterVerticle" :{
      "config": {
        "address": "knotx.adapter.service.http",
         ...
        "services": [
          {
            "path": "/service/mock/.*",
            "domain": "localhost",
            "port": 3000,
            "allowed.request.headers": [
              "Content-Type",
              "Cookie",
              "X-*"
            ]
          },
          {
            "path": "/service/.*",
            "domain": "localhost",
            "port": 8080,
            "allowed.request.headers": [
              "Content-Type",
              "X-*"
            ]
          }
        ]
      }
    },

Should be configured after the change like: knots.json

    "com.cognifide.knotx.knot.service.ServiceKnotVerticle": {
     "config": {
        "address": "knotx.knot.service",
         ...
      }
    },

adapters.json

"com.cognifide.knotx.adapter.service.http.HttpServiceAdapterVerticle" :{
      "config": {
        "address": "knotx.adapter.service.http",
        ...
        "endpoints": [
          {
            "path": "/service/mock/.*",
            "domain": "localhost",
            "port": 3000,
            "allowed.request.headers": [
              "Content-Type",
              "Cookie",
              "X-*"
            ]
          },
          {
            "path": "/service/.*",
            "domain": "localhost",
            "port": 8080,
            "allowed.request.headers": [
              "Content-Type",
              "X-*"
            ]
          }
        ],
        "variants": [
          {
            "name" : "first-service",
            "params": {
              "path": "/service/mock/first.json"
            },
            "cacheKey": "first"
          },
          {
            "name" : "second-service",
            "params": {
              "path": "/service/mock/second.json"
            }
          }
        ]
      }
    },

This task depends on #194 .

In order to Knot can see Adapters variants, AdaptersRegistry mechanism should be implemented. The idea is, that every Knot registers to AdapterRegistry as an Observer and every Adapter registers as an Observable. When new a Adapter is created it simply notifies all Knots that it can support defined variants and can be requested under defined address on the Event Bus.

tomaszmichalak commented 7 years ago

Please see ServiceDiscovery mechanism provided in Vertx (http://vertx.io/docs/vertx-service-discovery/java/).

malaskowski commented 6 years ago

Configuration concept is going to be re-written in the milestone: backpressure-and-configs. Follow the updated wiki docks for more details.