Skip to content

Commit

Permalink
fix MetadataService port conflict (apache#9184)
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazyHZM authored Nov 4, 2021
1 parent c1f29cd commit c6e4279
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ private String findConfigedHosts(ProtocolConfig protocolConfig,
private Integer findConfigedPorts(ProtocolConfig protocolConfig,
String name,
Map<String, String> map) {
Integer portToBind = null;
Integer portToBind;

// parse bind port from environment
String port = getValueFromConfig(protocolConfig, DUBBO_PORT_TO_BIND);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@

dubbo.application.name=dubbo-demo-annotation-consumer
dubbo.registry.address=zookeeper://127.0.0.1:2181
dubbo.protocol.port=-1
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@

dubbo.application.name=dubbo-demo-annotation-provider
dubbo.protocol.name=dubbo
dubbo.protocol.port=20880
dubbo.protocol.port=-1
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
*/
package org.apache.dubbo.demo.consumer;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.MetadataReportConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.demo.DemoService;
import org.apache.dubbo.rpc.service.GenericService;
Expand All @@ -44,18 +46,19 @@ private static void runWithBootstrap() {

DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap.application(new ApplicationConfig("dubbo-demo-api-consumer"))
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
.reference(reference)
.start();
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
.protocol(new ProtocolConfig(CommonConstants.DUBBO, -1))
.reference(reference)
.start();

DemoService demoService = bootstrap.getCache().get(reference);
String message = demoService.sayHello("dubbo");
System.out.println(message);

// generic invoke
GenericService genericService = (GenericService) demoService;
Object genericInvokeResult = genericService.$invoke("sayHello", new String[] { String.class.getName() },
new Object[] { "dubbo generic invoke" });
Object genericInvokeResult = genericService.$invoke("sayHello", new String[]{String.class.getName()},
new Object[]{"dubbo generic invoke"});
System.out.println(genericInvokeResult);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
*/
package org.apache.dubbo.demo.provider;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.MetadataReportConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.demo.DemoService;

Expand All @@ -46,6 +48,7 @@ private static void startWithBootstrap() {
DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap.application(new ApplicationConfig("dubbo-demo-api-provider"))
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
.protocol(new ProtocolConfig(CommonConstants.DUBBO, -1))
.service(service)
.start()
.await();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.dubbo.config.MetadataReportConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.rpc.service.GenericService;

Expand Down Expand Up @@ -54,6 +55,7 @@ private static void runWithBootstrap(String[] args) {
DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap.application(applicationConfig)
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
.protocol(new ProtocolConfig(CommonConstants.DUBBO, -1))
.reference(reference)
.start();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
package com.apache.dubbo.demo.graalvm.consumer;

import org.apace.dubbo.graalvm.demo.DemoService;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
Expand All @@ -29,7 +31,7 @@ public class Application {

public static void main(String[] args) {
System.setProperty("dubbo.application.logger", "log4j");
System.setProperty("native","true");
System.setProperty("native", "true");
if (isClassic(args)) {
runWithRefer();
} else {
Expand All @@ -47,17 +49,18 @@ private static void runWithBootstrap() {
reference.setGeneric("false");

DubboBootstrap bootstrap = DubboBootstrap.getInstance();
ApplicationConfig applicationConfig = new ApplicationConfig("dubbo-demo-api-consumer");
ApplicationConfig applicationConfig = new ApplicationConfig("dubbo-demo-api-consumer");
applicationConfig.setQosEnable(false);
applicationConfig.setCompiler("jdk");
Map<String,String> m = new HashMap<>(1);
m.put("proxy","jdk");
Map<String, String> m = new HashMap<>(1);
m.put("proxy", "jdk");
applicationConfig.setParameters(m);

bootstrap.application(applicationConfig)
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
.reference(reference)
.start();
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
.protocol(new ProtocolConfig(CommonConstants.DUBBO, -1))
.reference(reference)
.start();

DemoService demoService = bootstrap.getCache().get(reference);
String message = demoService.sayHello("Native");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
*/
package org.apache.dubbo.demo.graalvm.provider;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
Expand Down Expand Up @@ -54,15 +56,16 @@ private static void startWithBootstrap() {
ApplicationConfig applicationConfig = new ApplicationConfig("dubbo-demo-api-provider");
applicationConfig.setQosEnable(false);
applicationConfig.setCompiler("jdk");
Map<String,String> m = new HashMap<>(1);
m.put("proxy","jdk");
Map<String, String> m = new HashMap<>(1);
m.put("proxy", "jdk");
applicationConfig.setParameters(m);

bootstrap.application(applicationConfig)
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
.service(service)
.start()
.await();
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
.protocol(new ProtocolConfig(CommonConstants.DUBBO, -1))
.service(service)
.start()
.await();
}

private static void startWithExport() throws InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
Expand All @@ -39,16 +40,17 @@ public static void main(String[] args) throws InterruptedException, IOException

DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap.application(new ApplicationConfig("dubbo-demo-triple-api-consumer"))
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
.reference(referenceConfig)
.start();
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
.protocol(new ProtocolConfig(CommonConstants.TRIPLE, -1))
.reference(referenceConfig)
.start();

GreeterService greeterService = referenceConfig.get();
System.out.println("dubbo referenceConfig started");
try {
final HelloReply reply = greeterService.sayHello(HelloRequest.newBuilder()
.setName("triple")
.build());
.setName("triple")
.build());
TimeUnit.SECONDS.sleep(1);
System.out.println("Reply: " + reply.getMessage());
} catch (Throwable t) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
*/
package org.apache.dubbo.demo.consumer;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
Expand All @@ -34,9 +36,10 @@ public static void main(String[] args) throws IOException {

DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap.application(new ApplicationConfig("dubbo-demo-triple-api-wrapper-consumer"))
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
.reference(referenceConfig)
.start();
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
.protocol(new ProtocolConfig(CommonConstants.TRIPLE, -1))
.reference(referenceConfig)
.start();

final GreeterWrapperService greeterWrapperService = referenceConfig.get();
System.out.println("dubbo referenceConfig started");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public static void main(String[] args) throws InterruptedException {

DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap.application(new ApplicationConfig("dubbo-demo-triple-api-provider"))
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
.protocol(new ProtocolConfig(CommonConstants.TRIPLE, 50051))
.service(serviceConfig)
.start()
.await();
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
.protocol(new ProtocolConfig(CommonConstants.TRIPLE, -1))
.service(serviceConfig)
.start()
.await();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public static void main(String[] args) throws IOException {

DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap.application(new ApplicationConfig("dubbo-demo-triple-api-wrapper-provider"))
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
.protocol(new ProtocolConfig(CommonConstants.TRIPLE, 50051))
.service(serviceConfig)
.start()
.await();
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
.protocol(new ProtocolConfig(CommonConstants.TRIPLE, -1))
.service(serviceConfig)
.start()
.await();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@

<dubbo:registry address="zookeeper://127.0.0.1:2181"/>

<dubbo:protocol name="dubbo" port="-1"/>
<dubbo:protocol name="rest" port="-1"/>
<dubbo:protocol name="tri" port="-1"/>

<dubbo:reference id="demoService" check="false"
interface="org.apache.dubbo.demo.DemoService"/>

Expand Down

0 comments on commit c6e4279

Please sign in to comment.