Skip to content

Commit

Permalink
[huaweicloud#53][huaweicloud#48]修复配置、注册发现冲突问题
Browse files Browse the repository at this point in the history
  • Loading branch information
liubao68 committed Oct 31, 2020
1 parent 56d18f9 commit 576d1d9
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 14 deletions.
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

0 comments on commit 576d1d9

Please sign in to comment.