Skip to content

Commit

Permalink
Fix#2543, nacos App Metadata not compatible with java (#2563)
Browse files Browse the repository at this point in the history
  • Loading branch information
FoghostCn authored Jan 19, 2024
1 parent 68e999d commit 6dba60a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
27 changes: 23 additions & 4 deletions metadata/report/nacos/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,24 @@ type nacosMetadataReport struct {

// GetAppMetadata get metadata info from nacos
func (n *nacosMetadataReport) GetAppMetadata(metadataIdentifier *identifier.SubscriberMetadataIdentifier) (*common.MetadataInfo, error) {
// compatible with java impl first
data, err := n.getConfig(vo.ConfigParam{
DataId: metadataIdentifier.GetIdentifierKey(),
Group: n.group,
DataId: metadataIdentifier.Application,
Group: metadataIdentifier.Revision,
})
if err != nil {
return nil, err
}

if data == "" {
// compatible with dubbo-go 3.1.x before
data, err = n.getConfig(vo.ConfigParam{
DataId: metadataIdentifier.GetIdentifierKey(),
Group: n.group,
})
if err != nil {
return nil, err
}
}
var metadataInfo common.MetadataInfo
err = json.Unmarshal([]byte(data), &metadataInfo)
if err != nil {
Expand All @@ -91,7 +101,16 @@ func (n *nacosMetadataReport) PublishAppMetadata(metadataIdentifier *identifier.
if err != nil {
return err
}

// compatible with java impl
err = n.storeMetadata(vo.ConfigParam{
DataId: metadataIdentifier.Application,
Group: metadataIdentifier.Revision,
Content: string(data),
})
if err != nil {
return err
}
// compatible with dubbo-go 3.1.x before
return n.storeMetadata(vo.ConfigParam{
DataId: metadataIdentifier.GetIdentifierKey(),
Group: n.group,
Expand Down
4 changes: 2 additions & 2 deletions metadata/report/nacos/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func Test_nacosMetadataReport_GetAppMetadata(t *testing.T) {

ctrl := gomock.NewController(t)
mnc := NewMockIConfigClient(ctrl)
mnc.EXPECT().GetConfig(gomock.Any()).Return(string(data), nil)
mnc.EXPECT().GetConfig(gomock.Any()).MaxTimes(2).Return(string(data), nil)
nc := &nacosClient.NacosConfigClient{}
nc.SetClient(mnc)

Expand Down Expand Up @@ -253,7 +253,7 @@ func Test_nacosMetadataReport_GetAppMetadata(t *testing.T) {
func Test_nacosMetadataReport_PublishAppMetadata(t *testing.T) {
ctrl := gomock.NewController(t)
mnc := NewMockIConfigClient(ctrl)
mnc.EXPECT().PublishConfig(gomock.Any()).Return(true, nil)
mnc.EXPECT().PublishConfig(gomock.Any()).Times(2).Return(true, nil)
nc := &nacosClient.NacosConfigClient{}
nc.SetClient(mnc)

Expand Down

0 comments on commit 6dba60a

Please sign in to comment.