diff --git a/configs/conf.yaml b/configs/conf.yaml index b2c545154..4f458edb1 100644 --- a/configs/conf.yaml +++ b/configs/conf.yaml @@ -40,6 +40,7 @@ static_resources: route: cluster: "test-dubbo" cluster_not_found_response_code: 505 + dynamic: true http_filters: - name: dgp.filter.http.apiconfig config: @@ -84,6 +85,13 @@ static_resources: adapters: - name: "dgp.adapter.springcloud" config: + services: + SPRING-CLOUD-PRODUCER: + id: SPRING-CLOUD-PRODUCER # 注册中心的服务名 + name: SPRING-CLOUD-PRODUCER # 服务名 + prefix: /scp # router 前缀 + strip-prefix: true # 代理请求时移除前缀 rm /scp + otherConfig: "pixiu" registries: "eureka": protocol: "eureka" diff --git a/pkg/adapter/springcloud/cloud.go b/pkg/adapter/springcloud/cloud.go index 031d02284..9dbfd60cc 100644 --- a/pkg/adapter/springcloud/cloud.go +++ b/pkg/adapter/springcloud/cloud.go @@ -78,7 +78,6 @@ func (a *CloudAdapter) Start() { go func() { // init SpringCloud Manager for control initialize - //cloudManager := SpringCloudManager(a.boot) cloudManager := NewSpringCloudManager(&SpringCloudConfig{boot: a.boot}) cloudManager.Start() diff --git a/pkg/adapter/springcloud/sc_manager.go b/pkg/adapter/springcloud/sc_manager.go index 57ff5534c..53ccc9d9a 100644 --- a/pkg/adapter/springcloud/sc_manager.go +++ b/pkg/adapter/springcloud/sc_manager.go @@ -4,6 +4,7 @@ import ( "github.com/apache/dubbo-go-pixiu/pkg/adapter/springcloud/discovery" "github.com/apache/dubbo-go-pixiu/pkg/logger" "github.com/apache/dubbo-go-pixiu/pkg/model" + "github.com/apache/dubbo-go-pixiu/pkg/server" ) // SpringCloudConfig SpringCloud that life cycle configuration @@ -45,6 +46,35 @@ type scManager struct { Stop func() } +func (m *scManager) initCluster() { + endpoint := &model.Endpoint{} + endpoint.ID = "spring-cloud-producer" // 192.168.0.105:spring-cloud-producer:9000 + endpoint.Address = model.SocketAddress{ + Address: "192.168.0.105", + Port: 9000, + } + cluster := &model.Cluster{} + cluster.Name = "spring-cloud-producer" + cluster.Lb = model.Rand + cluster.Endpoints = []*model.Endpoint{ + endpoint, + } + // add cluster into manager + cm := server.GetClusterManager() + cm.AddCluster(cluster) + + // transform into route + routeMatch := model.RouterMatch{ + Prefix: "/scp", + } + routeAction := model.RouteAction{ + Cluster: "spring-cloud-producer", + } + route := &model.Router{Match: routeMatch, Route: routeAction} + + server.GetRouterManager().AddRouter(route) +} + // load remote registry : nacos, consul... func loadRouterByRemoteConfig() { @@ -80,6 +110,7 @@ func NewSpringCloudManager(config *SpringCloudConfig) *scManager { scConfig: config, Start: func() *scManager { manager.initAll() + manager.initRouter() return manager }, initAll: func() { @@ -111,7 +142,7 @@ func NewSpringCloudManager(config *SpringCloudConfig) *scManager { //resources }, initRouter: func() { - + manager.initCluster() }, getServiceInfoById: func(serviceId string) { diff --git a/pkg/model/router.go b/pkg/model/router.go index a0c5ded42..db825c180 100644 --- a/pkg/model/router.go +++ b/pkg/model/router.go @@ -90,9 +90,10 @@ func (r *Router) MatchRouter(req *http2.Request) bool { return true } - if r.Match.matchMethod(req) { - return true - } + // pi 这地方 match method 可能需要调整,当前逻辑是只要为空就会返回true + //if r.Match.matchMethod(req) { + // return true + //} if r.Match.matchHeader(req) { return true