Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
@Component("annotatedConsumer")
public class GreetingServiceConsumer {

@DubboReference(version = "1.0.0")
@DubboReference(loadbalance = "roundrobin")
private GreetingService greetingService;

@DubboReference(version = "1.0.0", providedBy = "dubbo-quickstart-provider")
@DubboReference(version = "1.0.0")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么需要删除providedBy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

providedBy字段是多余的。providedBy = "dubbo-quickstart-provider"指定了使用名为dubbo-quickstart-provider的dubbo应用作为provider。启动demo的provider和consumer时,不用providedBy字段也能调用到dubbo-quickstart-provider中的服务。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

providedBy可以指定从某个被调服务获取服务信息数据,这个字段的作用可以再研究一下,填与不填的区别。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

providedBy可以指定从某个被调服务获取服务信息数据,这个字段的作用可以再研究一下,填与不填的区别。

不填写的时候,会通过mapping元数据找到提供该接口服务的全部应用,然后从北极星拉取这些应用的实例列表完成服务发现。

private EchoService echoService;

public String doSayHello(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@
import com.tencent.polaris.dubbo.example.api.GreetingService;
import org.apache.dubbo.config.annotation.DubboService;

@DubboService(version = "1.0.0")
@DubboService
public class AnnotatedGreetingService implements GreetingService {

public String sayHello(String name) {
return "hello, " + name;
String port = System.getProperty("dubbo.protocol.port");
return "hello, " + name + ", port: " + port;
}

@Override
public String sayHi(String name) {
return "[provider by polaris] hi, " + name;
String port = System.getProperty("dubbo.protocol.port");
return "[provider by polaris] hi, " + name + ", port: " + port;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.tencent.polaris.common.registry.PolarisOperators;
import com.tencent.polaris.common.utils.Consts;
import com.tencent.polaris.specification.api.v1.service.manage.ServiceContractProto;
import java.util.stream.Collectors;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.config.configcenter.ConfigItem;
import org.apache.dubbo.common.utils.ConcurrentHashSet;
Expand Down Expand Up @@ -82,6 +83,7 @@ public class PolarisMetadataReport extends AbstractMetadataReport {
this.another = MultiReportUtil.buildAnother(applicationModel, url);
}

// 保存应用的元数据
@Override
protected void doStoreProviderMetadata(MetadataIdentifier providerMetadataIdentifier, String serviceDefinitions) {
reportServiceContract(toDescriptor(providerMetadataIdentifier, serviceDefinitions));
Expand Down Expand Up @@ -255,22 +257,40 @@ private boolean reportServiceContract(ReportServiceContractRequest req) {
*/
@Override
public boolean registerServiceAppMapping(String serviceKey, String application, URL url) {
// TODO 顺序调整
// 直接上报mapping数据会导致提供相同接口的其他应用的mapping数据被覆写。
// 这里应该是追加写入应用-接口mapping数据。
// 1. 先获取初始mapping,过滤掉当前serviceKey对应的mapping
another.ifPresent(proxyReport -> proxyReport.getMetadataReport().registerServiceAppMapping(serviceKey, application, url));

GetServiceContractRequest getServiceContractRequest = new GetServiceContractRequest();
getServiceContractRequest.setName(formatMappingName(serviceKey));
getServiceContractRequest.setService("");
getServiceContractRequest.setVersion("");
Optional<ServiceContractProto.ServiceContract> result = getServiceContract(getServiceContractRequest);
List<InterfaceDescriptor> descriptors = result
.map(ServiceContractProto.ServiceContract::getInterfacesList)
.orElse(Collections.emptyList())
.stream()
.filter(descriptor -> !descriptor.getName().equals(application))
.map(descriptor -> {
InterfaceDescriptor interfaceDescriptor = new InterfaceDescriptor();
interfaceDescriptor.setName(descriptor.getName());
interfaceDescriptor.setPath(descriptor.getPath());
interfaceDescriptor.setMethod(descriptor.getMethod());
interfaceDescriptor.setContent(descriptor.getContent());
return interfaceDescriptor;
})
.collect(Collectors.toList());
// 2. 再添加当前serviceKey对应的mapping
ReportServiceContractRequest request = new ReportServiceContractRequest();
request.setName(formatMappingName(serviceKey));
request.setService("");
request.setVersion("");

List<InterfaceDescriptor> descriptors = new ArrayList<>();
InterfaceDescriptor descriptor = new InterfaceDescriptor();
descriptor.setName(application);
descriptor.setPath(application);
descriptor.setContent(application);
descriptor.setMethod("");
descriptors.add(descriptor);

request.setInterfaceDescriptors(descriptors);
return reportServiceContract(request);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void doRegister(URL url) {
int port = url.getPort();
if (port > 0) {
int weight = url.getParameter(Constants.WEIGHT_KEY, Constants.DEFAULT_WEIGHT);
String version = url.getParameter(CommonConstants.VERSION_KEY, "1.0.0");
String version = url.getParameter(CommonConstants.VERSION_KEY);
polarisOperator.register(url.getServiceInterface(), url.getHost(), port, url.getProtocol(), version, weight,
metadata);
registeredInstances.add(url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ protected void doRegister(ServiceInstance instance) throws RuntimeException {
metadata = new HashMap<>();
}
metadata.replaceAll((s, s2) -> StringUtils.defaultString(s2));
String version = instance.getMetadata(Consts.INSTANCE_VERSION, Consts.DEFAULT_VERSION);
Context.saveToGlobal(Consts.INSTANCE_VERSION, version);
String version = instance.getMetadata(Consts.INSTANCE_VERSION);
operator.register(
serviceName,
instance.getHost(),
Expand Down
8 changes: 8 additions & 0 deletions polaris-adapter-dubbo/src/main/resources/polaris.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
consumer:
serviceRouter:
plugin:
recoverRouter:
# 是否剔除被熔断的实例
excludeCircuitBreakInstances: false
# 关闭全死全活
allRecoverEnable: false