You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

33 lines
808 B

package gomicro
import (
"github.com/micro/go-micro/v2"
"github.com/micro/go-micro/v2/client"
"github.com/micro/go-micro/v2/client/selector"
)
//call E.g:
/*
service := NewMicroService(func(rsp interface{}) error {
r := rsp.(*MyResponse)
r.Message = "hello error~: service not found!"
return nil
})
yourService := pb.NewYourService("your micro service name", service.Client())
*/
// defRsp fuseResponse 为熔断时的默认响应处理
func NewMicroService(defRsp fuseResponse) micro.Service {
se := selector.NewSelector(
selector.SetStrategy(selector.RoundRobin),
)
service := micro.NewService(
micro.Selector(se),
micro.WrapClient(func(client client.Client) client.Client {
return &HystrixWrapper{client, defRsp}
}),
micro.WrapClient(NewLogWrapper),
)
return service
}