func registerService(providerServices map[string]*config.ServiceConfig, server *grpc.Server) {
	for key, providerService := range providerServices {
		service := config.GetProviderService(key)
		ds, ok := service.(DubboGrpcService)
		if !ok {
			panic("illegal service type registered")
		}
		serviceKey := common.ServiceKey(providerService.Interface, providerService.Group, providerService.Version)
		exporter, _ := grpcProtocol.ExporterMap().Load(serviceKey)
		if exporter == nil {
			panic(fmt.Sprintf("no exporter found for servicekey: %v", serviceKey))
		}
		invoker := exporter.(protocol.Exporter).GetInvoker()
		if invoker == nil {
			panic(fmt.Sprintf("no invoker found for servicekey: %v", serviceKey))
		}
		ds.SetProxyImpl(invoker)
		server.RegisterService(ds.ServiceDesc(), service)
	}
}
registerService SetProxyImpl invoker and grpc service
package grpc
import (
	"fmt"
	"net"
	"sync"
	"time"
)
import (
	"github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc"
	"github.com/opentracing/opentracing-go"
	"google.golang.org/grpc"
	"google.golang.org/grpc/reflection"
)
import (
	"dubbo.apache.org/dubbo-go/v3/common"
	"dubbo.apache.org/dubbo-go/v3/common/logger"
	"dubbo.apache.org/dubbo-go/v3/config"
	"dubbo.apache.org/dubbo-go/v3/protocol"
)
type DubboGrpcService interface {
	SetProxyImpl(impl protocol.Invoker)
	GetProxyImpl() protocol.Invoker
	ServiceDesc() *grpc.ServiceDesc
}
type Server struct {
	grpcServer *grpc.Server
	bufferSize int
}
func NewServer() *Server {
	return &Server{}
}
func (s *Server) SetBufferSize(n int) {
	s.bufferSize = n
}
func (s *Server) Start(url *common.URL) {
	var (
		addr string
		err  error
	)
	addr = url.Location
	lis, err := net.Listen("tcp", addr)
	if err != nil {
		panic(err)
	}
	tracer := opentracing.GlobalTracer()
	server := grpc.NewServer(
		grpc.UnaryInterceptor(otgrpc.OpenTracingServerInterceptor(tracer)),
		grpc.StreamInterceptor(otgrpc.OpenTracingStreamServerInterceptor(tracer)),
		grpc.MaxRecvMsgSize(1024*1024*s.bufferSize),
		grpc.MaxSendMsgSize(1024*1024*s.bufferSize),
	)
	s.grpcServer = server
	go func() {
		providerServices := config.GetProviderConfig().Services
		if len(providerServices) == 0 {
			panic("provider service map is null")
		}
		waitGrpcExporter(providerServices)
		registerService(providerServices, server)
		reflection.Register(server)
		if err = server.Serve(lis); err != nil {
			logger.Errorf("server serve failed with err: %v", err)
		}
	}()
}
func getSyncMapLen(m *sync.Map) int {
	length := 0
	m.Range(func(_, _ interface{}) bool {
		length++
		return true
	})
	return length
}
func waitGrpcExporter(providerServices map[string]*config.ServiceConfig) {
	t := time.NewTicker(50 * time.Millisecond)
	defer t.Stop()
	pLen := len(providerServices)
	ta := time.NewTimer(10 * time.Second)
	defer ta.Stop()
	for {
		select {
		case <-t.C:
			mLen := getSyncMapLen(grpcProtocol.ExporterMap())
			if pLen == mLen {
				return
			}
		case <-ta.C:
			panic("wait grpc exporter timeout when start grpc server")
		}
	}
}