FoghostCn commented on code in PR #2983:
URL: https://github.com/apache/dubbo-go/pull/2983#discussion_r2313093149
##########
metadata/metadata_service.go:
##########
@@ -147,27 +147,58 @@ type serviceExporter struct {
v2Exporter base.Exporter
}
-// Export will export the metadataService
+// Export will export metadata services using single port dual interface
architecture
+// This ensures compatibility and proper client discovery for both V1 and V2
func (e *serviceExporter) Export() error {
- var port string
- if e.opts.port == 0 {
- port = common.GetRandomPort("")
- } else {
- port = strconv.Itoa(e.opts.port)
+ port := e.getPort()
+
+ // Export V1 protocol for backward compatibility
+ if err := e.exportV1Services(port); err != nil {
+ return err
}
- if e.opts.protocol == constant.DefaultProtocol {
- err := e.exportDubbo(port)
- if err != nil {
- return err
+
+ // Export V2 protocol on same port with different interface name
+ // Only export V2 for tri protocol to maintain compatibility
+ if e.opts.protocol == constant.TriProtocol {
+ if err := e.exportV2(port); err != nil {
+ // Log warning but don't fail - V1 should continue
working
+ logger.Warnf("Failed to export MetadataService V2: %v",
err)
}
- } else {
- e.exportTripleV1(port)
- // v2 only supports triple protocol
- e.exportV2(port)
}
+
return nil
}
+// getPort returns the port to use for metadata service export
+func (e *serviceExporter) getPort() string {
+ if e.opts.port == 0 {
+ return common.GetRandomPort("")
+ }
+ return strconv.Itoa(e.opts.port)
+}
+
+// exportV1Services exports V1 metadata services based on configured protocol
+func (e *serviceExporter) exportV1Services(port string) error {
+ if e.opts.protocol == constant.DefaultProtocol {
+ // Export dubbo protocol with hessian2 serialization
+ return e.exportDubbo(port)
+ }
+ // Export tri protocol V1 with hessian2 serialization
+ return e.exportTripleV1(port)
+}
Review Comment:
if `e.opts.protocol == 'dubbo'` this will export dubbo and tripleV1 both?
Can they listen on the same port at the same time?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]