fuziye01 commented on a change in pull request #801:
URL: 
https://github.com/apache/servicecomb-service-center/pull/801#discussion_r549603535



##########
File path: datasource/mongo/event/instance_event_handler.go
##########
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package event
+
+import (
+       "context"
+       "fmt"
+       "io/ioutil"
+       "path/filepath"
+
+       "github.com/apache/servicecomb-service-center/datasource/etcd/path"
+       "github.com/apache/servicecomb-service-center/datasource/mongo"
+       "github.com/apache/servicecomb-service-center/datasource/mongo/sd"
+       "github.com/apache/servicecomb-service-center/pkg/dump"
+       "github.com/apache/servicecomb-service-center/pkg/log"
+       "github.com/apache/servicecomb-service-center/pkg/util"
+       "github.com/apache/servicecomb-service-center/server/notify"
+       "github.com/apache/servicecomb-service-center/server/syncernotify"
+       
"github.com/apache/servicecomb-service-center/syncer/samples/multi-servicecenters/servicecenter/hello-server/servicecenter"
+       "github.com/go-chassis/cari/discovery"
+       "github.com/go-chassis/go-chassis/v2/storage"
+       "go.mongodb.org/mongo-driver/bson"
+       "gopkg.in/yaml.v2"
+)
+
+// InstanceEventHandler is the handler to handle events
+//as instance registry or instance delete, and notify syncer
+type InstanceEventHandler struct {
+}
+
+func (h InstanceEventHandler) Type() string {
+       return mongo.CollectionInstance
+}
+
+func (h InstanceEventHandler) OnEvent(evt sd.MongoEvent) {
+       action := evt.Type
+       instance := evt.Value.(sd.Instance)
+       providerID := instance.InstanceInfo.ServiceId
+       providerInstanceID := instance.InstanceInfo.InstanceId
+
+       cacheService := sd.Store().Service().Cache().Get(providerID)
+       var ms *discovery.MicroService
+       if cacheService != nil {
+               ms = cacheService.(sd.Service).ServiceInfo
+       }
+       if ms == nil {
+               log.Info("get cached service failed, then get from data base")
+               ms = getServiceFromDB(providerID) // service in the cache may 
not ready, query from db one time
+               if ms == nil {
+                       log.Warn(fmt.Sprintf("caught [%s] instance[%s/%s] 
event, endpoints %v, get provider's file failed from db\n",
+                               action, providerID, providerInstanceID, 
instance.InstanceInfo.Endpoints))
+                       return
+               }
+       }
+       if !syncernotify.GetSyncerNotifyCenter().Closed() {
+               NotifySyncerInstanceEvent(evt, ms)
+       }
+
+       if notify.Center().Closed() {

Review comment:
       notify与syncer无关,是外部订阅相关的逻辑,不用关注notify的状态。 

##########
File path: 
syncer/samples/multi-servicecenters/servicecenter/hello-server/servicecenter/config.go
##########
@@ -56,6 +56,15 @@ type Instance struct {
 type Registry struct {
        Address   string   `yaml:"address"`
        Endpoints []string `yaml:"-"`
+       MongoDB   *MongoDB `yaml:"mongo"`
+}

Review comment:
       是否能复用之前MongoDB的配置,不用自己新增配置




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to