Uploaded image for project: 'Apache Dubbo'
  1. Apache Dubbo
  2. DUBBO-137

Unified IDL control for multiple protocols

    XMLWordPrintableJSON

Details

    Description

      Unified IDL control for multiple protocols

      Client and Server layer APIs can support both IDL and Non-IDL modes.
      For IDL mode(Triple + Protobuf), defining proto file and making use of protoc-gen-go-triple to generate related code are straightforward. Generated code(XXX.triple.go) would contain statements that invoking APIs provided by Client and Server layers.
      For Non-IDL mode, it needs users to write invoking code by themselves and is not convenient. Take Dubbo+Hessian2 as example:

      Client Side

      
      Cli, err := client.NewClient()
      	cli, err := client.NewClient(
      		client.WithClientProtocolDubbo(), )
      	)
      	withClientProtocolDubbo(), ) if err ! = nil {
      		panic(err)
      	}
      	conn, err := cli.Dial("GreetProvider",
      		client.WithURL("127.0.0.1:20000"), )
      	)
      	if err ! = nil {
      		panic(err)
      	}
      	var resp string
      	if err := conn.CallUnary(context.Background(), []interface{}{"hello", "new", "dubbo"}, &resp, "Greet"); err ! = nil {
      		logger.Errorf("GreetProvider.Greet err: %s", err)
      		errorf("GreetProvider.Greet err: %s", err)
      	}
      

      Server Side

      GreetProvider.
      type GreetProvider struct {
      }
      
      func (*GreetProvider) Greet(req string, req1 string, req2 string) (string, error) {
      	return req + req1 + req2, nil
      }
      
      srv, err := server.NewServer(
      	server.WithServerProtocol(
      		protocol.WithDubbo(), protocol.WithPort(20000))
      		protocol.WithPort(20000),
      	),
      )
      if err ! = nil {
      	panic(err)
      }
      if err := srv.Register(&GreetProvider{}, nil, server.WithInterface("GreetProvider")); err ! = nil {
      	panic(err)
      }
      if err := srv.Serve(); err ! = nil {
      	panic(err)
      }
      

      Proposal

      Even in Non-IDL mode, code is generated using protobuf IDL. In this way, whether you need schema (Protobuf) or not (Hessian2, Msgpack), it's all uniformly used: Protobuf IDL + generated code.

      Details:

      1. Generate Dubbo + Hessian2 related code with the help of Protobuf IDL. Compared to XXX.pb.go, XXX.hessian2.go would have much less content (due to Hessian2 schema-free), only structure definitions and the corresponding registration function (hessian2.Register(POJO)).
      2. Non-IDL (Hessian2) may not map perfectly to Protobuf IDL, and we need to define our own dialect in a way that is compatible with the official semantics of Protobuf IDL
      3. XXX.dubbo.go content is basically similar to XXX.triple.go, generating code that uses the APIs of Client layer and Server layer.

      Prerequisite:

      1. Provide tools for Dubbo side users to automatically convert Dubbo interface definitions into Protobuf IDL.
      2. Protobuf IDL can support extensions (add Hessian2-specific tag extensions, generate Hessian2-specific content)

      Results:

      Not only Dubbo + Hessian2, but also Triple + Hessian2, Triple + Json and other Non-IDLs can use the interface in a unified way.

      Mentor

      • Mentor: Albumen Kevin, Apache Dubbo PMC, albumenj@apache.org
      • Mailing List: dev@dubbo.apache.org

         

      Attachments

        Activity

          People

            Unassigned Unassigned
            albumenj Albumen Kevin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: