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

2 years ago
  1. package gomicro
  2. import (
  3. "github.com/micro/go-micro/v2"
  4. "github.com/micro/go-micro/v2/client"
  5. "github.com/micro/go-micro/v2/client/selector"
  6. )
  7. //call E.g:
  8. /*
  9. service := NewMicroService(func(rsp interface{}) error {
  10. r := rsp.(*MyResponse)
  11. r.Message = "hello error~: service not found!"
  12. return nil
  13. })
  14. yourService := pb.NewYourService("your micro service name", service.Client())
  15. */
  16. // defRsp fuseResponse 为熔断时的默认响应处理
  17. func NewMicroService(defRsp fuseResponse) micro.Service {
  18. se := selector.NewSelector(
  19. selector.SetStrategy(selector.RoundRobin),
  20. )
  21. service := micro.NewService(
  22. micro.Selector(se),
  23. micro.WrapClient(func(client client.Client) client.Client {
  24. return &HystrixWrapper{client, defRsp}
  25. }),
  26. micro.WrapClient(NewLogWrapper),
  27. )
  28. return service
  29. }