Kaynağa Gözat

qyxy 生es,支持配置第二个服务器地址

wcc 1 yıl önce
ebeveyn
işleme
883a2afab5
3 değiştirilmiş dosya ile 23 ekleme ve 0 silme
  1. 3 0
      qyxy_es_new/config.json
  2. 12 0
      qyxy_es_new/main.go
  3. 8 0
      qyxy_es_new/task.go

+ 3 - 0
qyxy_es_new/config.json

@@ -14,6 +14,9 @@
     "itype": "qyxy",
     "username": "",
     "password": "",
+    "addr2": "http://192.168.3.149:9200",
+    "username2": "",
+    "password2": "",
     "pool": 12,
     "esfields": [
       "_id",

+ 12 - 0
qyxy_es_new/main.go

@@ -19,6 +19,7 @@ var (
 	Dbname    string
 	Dbcoll    string
 	Es        *elastic.Elastic
+	Es2       *elastic.Elastic
 	Index     string
 	//Itype     string
 	EsFields []string
@@ -55,6 +56,17 @@ func init() {
 	}
 	Es.InitElasticSize()
 
+	//集群2
+	if utils.ObjToString(econf["addr2"]) != "" {
+		Es2 = &elastic.Elastic{
+			S_esurl:  econf["addr2"].(string),
+			I_size:   utils.IntAllDef(econf["pool"], 12),
+			Username: econf["username2"].(string),
+			Password: econf["password2"].(string),
+		}
+		Es2.InitElasticSize()
+	}
+
 	EsFields = utils.ObjArrToStringArr(econf["esfields"].([]interface{}))
 
 	//Updatetime = utils.Int64All(Sysconfig["updatetime"])

+ 8 - 0
qyxy_es_new/task.go

@@ -456,6 +456,10 @@ func SaveEs() {
 						<-SP
 					}()
 					Es.BulkSave(Index, arru)
+					// 存在第二个集群
+					if Es2.S_esurl != "" {
+						Es2.BulkSave(Index, arru)
+					}
 				}(arru)
 				arru = make([]map[string]interface{}, 100)
 				indexu = 0
@@ -468,6 +472,10 @@ func SaveEs() {
 						<-SP
 					}()
 					Es.BulkSave(Index, arru)
+					// 存在第二个集群
+					if Es2.S_esurl != "" {
+						Es2.BulkSave(Index, arru)
+					}
 				}(arru[:indexu])
 				arru = make([]map[string]interface{}, 100)
 				indexu = 0