Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

[#53][#48]修复配置、注册发现冲突问题 #56

Merged
merged 1 commit into from
Oct 31, 2020
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 @@ -80,7 +80,7 @@ public QueryConfigurationsResponse queryConfigurations(QueryConfigurationsReques
}

if (allConfigMap.get(buildDimensionsInfo(request, false)) != null) {
configurations.putAll(allConfigMap.get(request.getServiceName()));
configurations.putAll(allConfigMap.get(buildDimensionsInfo(request, false)));
}

if (allConfigMap.get(dimensionsInfo) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@
import com.huaweicloud.dubbo.common.SchemaInfo;

public class RegistrationListener implements ApplicationListener<ApplicationEvent>, ApplicationEventPublisherAware {
private static final String PROTOCOL_CONSUMER = "consumer";

static class SubscriptionKey {
final String appId;

Expand Down Expand Up @@ -181,7 +179,6 @@ public void onApplicationEvent(ApplicationEvent applicationEvent) {
List<String> endpoints = new ArrayList<>();
if (registry != null) {
endpoints.addAll(registry.getRegisters().stream()
.filter(item -> !item.getProtocol().equals(PROTOCOL_CONSUMER))
.map(URL::toString)
.collect(Collectors.toList()));
}
Expand All @@ -201,13 +198,11 @@ public void onApplicationEvent(ApplicationEvent applicationEvent) {
waitRegistrationDone();
} else if (applicationEvent instanceof NewSubscriberEvent) {
NewSubscriberEvent newSubscriberEvent = (NewSubscriberEvent) applicationEvent;
if (newSubscriberEvent.getUrl().getProtocol().equals(PROTOCOL_CONSUMER)) {
if (registrationInProgress) {
pendingSubscribeEvent.add(newSubscriberEvent);
return;
}
processNewSubscriberEvent(newSubscriberEvent);
if (registrationInProgress) {
pendingSubscribeEvent.add(newSubscriberEvent);
return;
}
processNewSubscriberEvent(newSubscriberEvent);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import com.alibaba.dubbo.registry.support.FailbackRegistry;

public class ServiceCenterRegistry extends FailbackRegistry {
private static final String PROTOCOL_CONSUMER = "consumer";

private List<URL> registers;

private RegistrationListener registrationListener;
Expand All @@ -39,7 +41,9 @@ public ServiceCenterRegistry(URL url, RegistrationListener registrationListener)

@Override
protected void doRegister(URL url) {
this.registers.add(url);
if (!url.getProtocol().equals(PROTOCOL_CONSUMER)) {
this.registers.add(url);
}
}

@Override
Expand All @@ -49,7 +53,9 @@ protected void doUnregister(URL url) {

@Override
protected void doSubscribe(URL url, NotifyListener notifyListener) {
this.registrationListener.applicationEventPublisher().publishEvent(new NewSubscriberEvent(url, notifyListener));
if (url.getProtocol().equals(PROTOCOL_CONSUMER)) {
this.registrationListener.applicationEventPublisher().publishEvent(new NewSubscriberEvent(url, notifyListener));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.huaweicloud.it.price;

import java.util.concurrent.CompletableFuture;

public interface PriceServiceRest {
String sayHello(String name);

CompletableFuture<String> sayHelloAsync(String name);

String testConfiguration(String value);

String testConfigurationService(String value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public static void main(String[] args) throws Exception {
e.printStackTrace();
}

Thread.sleep(3000); // TODO: 尽可能规避 spring cloud huawei 的 bug, 需要等待新版本

System.out.println("running all test cases");
portalController.testAll();
System.out.println("running all test cases successfully");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@
import org.springframework.beans.factory.annotation.Qualifier;

import com.huaweicloud.it.price.PriceService;
import com.huaweicloud.it.price.PriceServiceRest;

@Path("/price")
public class PriceServiceRestImpl implements PriceService {
public class PriceServiceRestImpl implements PriceServiceRest {
@Autowired
@Qualifier("priceService")
private PriceService priceService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<property name="priceService" ref = "priceService"/>
</bean>

<dubbo:service interface="com.huaweicloud.it.price.PriceService" ref="priceServiceRest"/>
<dubbo:service interface="com.huaweicloud.it.price.PriceServiceRest" ref="priceServiceRest"/>

<dubbo:reference id="priceService" check="false" interface="com.huaweicloud.it.price.PriceService" scope="remote"/>
<dubbo:reference id="pingService" check="false" interface="com.huaweicloud.it.price.PingService" scope="remote"/>
Expand Down
10 changes: 10 additions & 0 deletions integration-tests/discovery-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@
<artifactId>discovery-tests</artifactId>
<packaging>pom</packaging>

<dependencyManagement>
<dependencies>
<!-- dubbo rest用了老版本, 升级一下 -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.7</version>
</dependency>
</dependencies>
</dependencyManagement>
<modules>
<module>common-api</module>
<module>price-provider</module>
Expand Down