基于服务的架构不一定意味着分配?(services based architecture should not necessarily imply distribution?)
在我的工作场所(以及许多其他领域),人们非常重视围绕服务构建架构。 (我在电子商务初创公司工作)。 但是,我认为服务被隐含地视为分布式的。 我是第一个分配法则的信徒 - “不分发”。 所以,我认为我们不应该必然使架构复杂化。 它应该是一个可以发展的架构。 因此,解决问题的方法之一是创建定义良好的命名空间并围绕它构建代码,但通过java api保持通信。 (这使得监控要求低,可靠性/可用性问题低)。 通过将模块包装到Web服务中,可以轻松地将其演变为分布式体系结构,并且当规模要求启动时。 因此,问题是 - 将代码编写为单个应用程序并演变为分布式服务的缺点是什么,而不是直接跳入实现基于Web服务的体系结构? 我是否正确地假设服务应该暗示设计的基本原则(抽象,封装等),而不是通过网络分发?
In my workplace (and a lot of other areas), there is a lot of emphasis on building architecture around services. (I am working in an e-commerce startup). However, I think services are implicitly considered as distributed. I am a believer of the first law of distribution - "don't distribute". So, I believe that we should not un-necessarily complicate architecture. It should be an architecture which can evolve. So, one of the ways to approach the problem would be to create well defined namespaces and build code around it, but keep the communication via java api. (this keeps monitoring requirement low, and reliability/availability problems low). This can easily be evolved into a distributed architecture by wrapping modules into web service, as and when, the scale requirements kick-in. So, the question is - what are the cons of writing code as a single application and evolving into distributed services, rather than straight jumping into implementing web services based architecture? Am I right in assuming that services should imply the basic principles of design (abstraction, encapsulation etc), rather than distribution over network?
原文:https://stackoverflow.com/questions/7457160
最满意答案
func (o *MongoOps) AddToBsonMapElement(lstMap map[string]interface{}, Operation string, key string, value interface{}) (result map[string]interface{}) { status, msg := EmptyStructCheck(o) if status == true { LogError(msg) panic(msg) } if Operation == "$addToSetEach" { if _, ok := lstMap["$addToSet"]; ok { childmap := lstMap["$addToSet"] subchildmap := childmap.(map[string]interface{}) var val map[string]interface{} val = make(map[string]interface{}) val["$each"] = value subchildmap[key] = val lstMap["$addToSet"] = subchildmap } else { lstMap["$addToSet"] = bson.M{key: bson.M{"$each": value}} } fmt.Println(reflect.TypeOf(lstMap)) } else if _, ok := lstMap[Operation]; ok { childmap := lstMap[Operation] subchildmap := childmap.(map[string]interface{}) subchildmap[key] = value lstMap[Operation] = subchildmap } else { childmap := make(map[string]interface{}, 0) childmap[key] = value lstMap[Operation] = childmap } return lstMap }
这是你可以尝试的
func (o *MongoOps) AddToBsonMapElement(lstMap map[string]interface{}, Operation string, key string, value interface{}) (result map[string]interface{}) { status, msg := EmptyStructCheck(o) if status == true { LogError(msg) panic(msg) } if Operation == "$addToSetEach" { if _, ok := lstMap["$addToSet"]; ok { childmap := lstMap["$addToSet"] subchildmap := childmap.(map[string]interface{}) var val map[string]interface{} val = make(map[string]interface{}) val["$each"] = value subchildmap[key] = val lstMap["$addToSet"] = subchildmap } else { lstMap["$addToSet"] = bson.M{key: bson.M{"$each": value}} } fmt.Println(reflect.TypeOf(lstMap)) } else if _, ok := lstMap[Operation]; ok { childmap := lstMap[Operation] subchildmap := childmap.(map[string]interface{}) subchildmap[key] = value lstMap[Operation] = subchildmap } else { childmap := make(map[string]interface{}, 0) childmap[key] = value lstMap[Operation] = childmap } return lstMap }
This is what you can try
相关问答
更多-
如果文档声明这样可以选择哪些字段应该被检索以找到结果,那么将使用Select方法,因此使用$elemMatch运算符的投影可以与Select结合使用,最终查询如下所示: c.Find(bson.M{ "_id": bson.ObjectIdHex(p.ByName("id")) }).Select(bson.M{ "races": bson.M{ "$elemMatch": bson.M{ "_id": bson.ObjectIdHex(p.ByNam ...
-
这个怎么样: func buildBsonObject(value_1 string, value_2 string) bson.M { m := bson.M{ "$match": bson.M{ "xyz": "abc", }, } if value_1 != "" { m["$id_1"] = value_1 } if value_2 != "" { m["$id_2"] = value_2 } return m } 操场的 ...
-
以下是如何使用从其他查询返回的文档的ID来构造查询。 var docs []bson.M if err := c.Find(query).All(&docs); err != nil { // handle error } docIDs := make([]interface{}, len(docs)) for i := range docs { docIds[i] = docs[i]["_id"] } query = bson.M{"_id": bson.M{"$in": doc ...
-
我真的不觉得有。 您可以通过反射来加载一组类型,并为字段名称生成一组常量。 所以: type Test struct { Field string `bson:"Field" json:"field"` OtherField int `bson:"OtherField" json:"otherField"` } 可能会生成如下内容: var TestFields = struct{ Field string OtherField string }{" ...
-
mgo具有聚合和分组功能(mgo with aggregation and grouping)[2023-04-09]
你获得NULL的原因是你的$match过滤器在$group阶段之后过滤掉所有文件。 在$group的第一阶段之后,文档仅如下例所示: {"_id": { "user": "foo"}}, {"_id": { "user": "bar"}}, {"_id": { "user": "baz"}} 它们不再包含其他字段,即user , date_updated和organization 。 如果您想保留其值,可以使用Group Accumulator Operator 。 根据您的使用情况,您还可以 ... -
使用预先构建的字符串作为bson.M以便在mgo中进行查询(Use a pre-constructed string as bson.M for mgo query in go)[2022-04-14]
我通过Unmarshalling finalbody找到了解决方案[string] interface {},然后将其用作更新映射。 所以, finalbody, err := json.Marshal(body) var finalbodymap map[string]interface{} json.Unmarshal(finalbody, &finalbodymap) 当然,你需要添加一些错误处理,所以最终的代码看起来像这样 - finalbody, err := json.Marshal(body ... -
Golang BSON转换(Golang BSON conversion)[2022-06-15]
就你而言,这将是: bson.M{"$or": []bson.M{ {"dependencies.provider_id": "abc"}, {"actions.provider_id": "abc"}, }} In your case, it would be: bson.M{"$or": []bson.M{ {"dependencies.provider_id": "abc"}, {"actions.provider_id": "abc"}, }} -
golang中的Mongodb聚合(Mongodb aggregation in golang)[2022-04-18]
更改 err1 := pipe.One(&results) 至 err1 := pipe.All(&results) Change err1 := pipe.One(&results) to err1 := pipe.All(&results) -
func (o *MongoOps) AddToBsonMapElement(lstMap map[string]interface{}, Operation string, key string, value interface{}) (result map[string]interface{}) { status, msg := EmptyStructCheck(o) if status == true { LogError(msg) panic(msg) } if Op ...
-
用户搜索Golang mgo(User search with Golang mgo)[2022-07-01]
例如,mongo过滤器可以采用正则表达式; bson.M{"title": bson.M{"$regex": bson.RegEx{Pattern: title, Options: "i"}}} 所以在这种情况下,标题变量将是这样的; .*abc*. 。 选项:“i”使案例不敏感。 至于匹配子字符串(方案2),我不确定如何在正则表达式中实现。 The mongo filter can take regex, for example; bson.M{"title": bson ...