func MongoDbOutputerInit(buffer chan bytes.Buffer, config map[string]string) (mo MongoDbOutputer) { mo.buffer = buffer mo.wq = lib.NewWaitQuit("mongodb outputer", -1) mo.mongosAddr, _ = config["mongos"] mo.db , _ = config["db"] mo.collection , _ = config["collection"] mo.session = initMongoDbSession(mo.mongosAddr) //暂时出错直接退出 if mo.session == nil { loglib.Error("init mongodb session failed") os.Exit(1) } upsert, _ := config["upsert"] if upsert == "true" { mo.isUpsert = true }else{ mo.isUpsert = false } bulkSize, _ := config["bulk_size"] nBulk, err := strconv.Atoi(bulkSize) if err == nil { mo.bulkSize = nBulk }else{ mo.bulkSize = 50 } savers, _ := config["savers"] nSavers, err := strconv.Atoi(savers) if err == nil { mo.savers = nSavers }else{ mo.savers = 20 } //创建文件缓存目录 mo.file_mem_folder_name = "tempfile" if !lib.FileExists(mo.file_mem_folder_name) { os.MkdirAll(mo.file_mem_folder_name, 0775) } mo.transactionIdKey = "transaction_id" mo.fileList = lib.GlobalListInit() return mo }
import ( "bytes" "fmt" "io/ioutil" "logd/lib" "logd/loglib" "logd/tcp_pack" "net" "os" "strconv" "sync" "time" ) var once sync.Once var fileList *lib.GlobalList = lib.GlobalListInit() type Sender struct { id int sBuffer chan bytes.Buffer file_mem_folder_name string memBuffer chan bytes.Buffer //sender自己的chan,用于保证sBuffer不阻塞 connection Connection status *int sendToAddress string wq *lib.WaitQuit } //工厂初始化函数 //增加备用地址,暂时支持一个备用地址