Skip to content
Permalink
Browse files
Add tri migration demo
  • Loading branch information
EarthChen committed Sep 7, 2021
1 parent e0feb8a commit 9a674aeee38b85c4fc25b06bbd4f1aa1075e2eb4
Showing 20 changed files with 420 additions and 17 deletions.
@@ -33,7 +33,7 @@ public static void main(String[] args) {
DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap.application(new ApplicationConfig("demo-provider"))
.registry(new RegistryConfig(TriSampleConstants.ZK_ADDRESS))
.protocol(new ProtocolConfig(CommonConstants.TRIPLE, TriSampleConstants.SERVER_POINT))
.protocol(new ProtocolConfig(CommonConstants.TRIPLE, TriSampleConstants.SERVER_PORT))
.service(service)
.start()
.await();
@@ -24,11 +24,11 @@
import org.apache.dubbo.config.bootstrap.DubboBootstrap;

class ApiWrapperConsumer {
private final IGreeter2 delegate;
private final IWrapperGreeter delegate;

public ApiWrapperConsumer() {
ReferenceConfig<IGreeter2> ref = new ReferenceConfig<>();
ref.setInterface(IGreeter2.class);
ReferenceConfig<IWrapperGreeter> ref = new ReferenceConfig<>();
ref.setInterface(IWrapperGreeter.class);
ref.setCheck(false);
ref.setTimeout(3000);
ref.setProtocol("tri");
@@ -26,14 +26,14 @@

class ApiWrapperProvider {
public static void main(String[] args) {
ServiceConfig<IGreeter2> service = new ServiceConfig<>();
service.setInterface(IGreeter2.class);
ServiceConfig<IWrapperGreeter> service = new ServiceConfig<>();
service.setInterface(IWrapperGreeter.class);
service.setRef(new IGreeter2Impl());

DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap.application(new ApplicationConfig("demo-provider"))
.registry(new RegistryConfig(TriSampleConstants.ZK_ADDRESS))
.protocol(new ProtocolConfig(CommonConstants.TRIPLE, TriSampleConstants.SERVER_POINT))
.protocol(new ProtocolConfig(CommonConstants.TRIPLE, TriSampleConstants.SERVER_PORT))
.service(service)
.start()
.await();
@@ -20,7 +20,7 @@
import org.apache.dubbo.common.stream.StreamObserver;
import org.apache.dubbo.rpc.RpcContext;

public class IGreeter2Impl implements IGreeter2 {
public class IGreeter2Impl implements IWrapperGreeter {

@Override
public String sayHello(String request) {
@@ -19,8 +19,7 @@

import org.apache.dubbo.common.stream.StreamObserver;

public interface IGreeter2 {

public interface IWrapperGreeter {

String sayHello(String request);

@@ -11,7 +11,7 @@

private final String name;

StdoutStreamObserver(String name) {
public StdoutStreamObserver(String name) {
this.name = name;
}

@@ -21,11 +21,13 @@
public class TriSampleConstants {

// macos 11 later the 50051 is occupied by system (pid=1!!!)
public static final int SERVER_POINT = 50052;
public static final int SERVER_PORT = 50052;

public static final int DEFAULT_DUBBO_PORT=20880;

public static final String ZK_ADDRESS = "zookeeper://127.0.0.1:2181";

public static final String HOST = "127.0.0.1";

public static final String DEFAULT_ADDRESS = "tri://" + HOST + ":" + SERVER_POINT;
public static final String DEFAULT_ADDRESS = "tri://" + HOST + ":" + SERVER_PORT;
}
@@ -0,0 +1,72 @@
/*
* 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 org.apache.dubbo.sample.tri.migration;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.sample.tri.IWrapperGreeter;
import org.apache.dubbo.sample.tri.TriSampleConstants;

class ApiMigrationBothConsumer {
private final IWrapperGreeter dubboDelegate;
private final IWrapperGreeter triDelegate;

public ApiMigrationBothConsumer() {
ReferenceConfig<IWrapperGreeter> ref = new ReferenceConfig<>();
ref.setInterface(IWrapperGreeter.class);
ref.setCheck(false);
ref.setTimeout(3000);
ref.setProtocol(CommonConstants.DUBBO_PROTOCOL);
ref.setLazy(true);

ReferenceConfig<IWrapperGreeter> ref2 = new ReferenceConfig<>();
ref2.setInterface(IWrapperGreeter.class);
ref2.setCheck(false);
ref2.setTimeout(3000);
ref2.setProtocol(CommonConstants.TRIPLE);
ref2.setLazy(true);

DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap.application(new ApplicationConfig("demo-migration-dubbo-consumer"))
.registry(new RegistryConfig(TriSampleConstants.ZK_ADDRESS))
.reference(ref)
.reference(ref2)
.start();
this.dubboDelegate = ref.get();
this.triDelegate = ref2.get();
}

public static void main(String[] args) {
final ApiMigrationBothConsumer consumer = new ApiMigrationBothConsumer();
System.out.println("demo-migration-both-consumer started");
consumer.sayHelloUnary(CommonConstants.DUBBO_PROTOCOL);
consumer.sayTriHelloUnary(CommonConstants.TRIPLE);
}

public void sayHelloUnary(String protocol) {
System.out.println(dubboDelegate.sayHello("unary" + "--" + protocol));
}

public void sayTriHelloUnary(String protocol) {
System.out.println(triDelegate.sayHello("unary" + "--" + protocol));
}

}
@@ -0,0 +1,48 @@
/*
* 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 org.apache.dubbo.sample.tri.migration;

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;
import org.apache.dubbo.sample.tri.IGreeter2Impl;
import org.apache.dubbo.sample.tri.IWrapperGreeter;
import org.apache.dubbo.sample.tri.TriSampleConstants;

class ApiMigrationBothProvider {

public static void main(String[] args) {

ServiceConfig<IWrapperGreeter> service = new ServiceConfig<>();
service.setInterface(IWrapperGreeter.class);
service.setRef(new IGreeter2Impl());

DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap.application(new ApplicationConfig("demo-migration-both-provider"))
.registry(new RegistryConfig(TriSampleConstants.ZK_ADDRESS))
.protocol(new ProtocolConfig(CommonConstants.DUBBO, TriSampleConstants.DEFAULT_DUBBO_PORT))
.protocol(new ProtocolConfig(CommonConstants.TRIPLE, TriSampleConstants.SERVER_PORT))
.service(service)
.start()
.await();

}
}
@@ -0,0 +1,57 @@
/*
* 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 org.apache.dubbo.sample.tri.migration;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.sample.tri.IWrapperGreeter;
import org.apache.dubbo.sample.tri.TriSampleConstants;

class ApiMigrationDubboConsumer {
private final IWrapperGreeter delegate;

public ApiMigrationDubboConsumer() {
ReferenceConfig<IWrapperGreeter> ref = new ReferenceConfig<>();
ref.setInterface(IWrapperGreeter.class);
ref.setCheck(false);
ref.setTimeout(3000);
ref.setProtocol(CommonConstants.DUBBO_PROTOCOL);
ref.setLazy(true);

DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap.application(new ApplicationConfig("demo-migration-dubbo-consumer"))
.registry(new RegistryConfig(TriSampleConstants.ZK_ADDRESS))
.reference(ref)
.start();
this.delegate = ref.get();
}

public static void main(String[] args) {
final ApiMigrationDubboConsumer consumer = new ApiMigrationDubboConsumer();
System.out.println("demo-migration-dubbo-consumer dubbo started");
consumer.sayHelloUnary(CommonConstants.DUBBO_PROTOCOL);
}

public void sayHelloUnary(String protocol) {
System.out.println(delegate.sayHello("unary" + "--" + protocol));
}

}
@@ -0,0 +1,46 @@
/*
* 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 org.apache.dubbo.sample.tri.migration;

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;
import org.apache.dubbo.sample.tri.IGreeter2Impl;
import org.apache.dubbo.sample.tri.IWrapperGreeter;
import org.apache.dubbo.sample.tri.TriSampleConstants;

class ApiMigrationDubboProvider {

public static void main(String[] args) {
ServiceConfig<IWrapperGreeter> service2 = new ServiceConfig<>();
service2.setInterface(IWrapperGreeter.class);
service2.setRef(new IGreeter2Impl());

DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap.application(new ApplicationConfig("demo-migration-dubbo-provider"))
.registry(new RegistryConfig(TriSampleConstants.ZK_ADDRESS))
.protocol(new ProtocolConfig(CommonConstants.DUBBO, TriSampleConstants.DEFAULT_DUBBO_PORT))
.service(service2)
.start()
.await();

}
}
@@ -0,0 +1,57 @@
/*
* 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 org.apache.dubbo.sample.tri.migration;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.sample.tri.IWrapperGreeter;
import org.apache.dubbo.sample.tri.TriSampleConstants;

class ApiMigrationTriConsumer {
private final IWrapperGreeter triDelegate;

public ApiMigrationTriConsumer() {
ReferenceConfig<IWrapperGreeter> ref2 = new ReferenceConfig<>();
ref2.setInterface(IWrapperGreeter.class);
ref2.setCheck(false);
ref2.setTimeout(3000);
ref2.setProtocol(CommonConstants.TRIPLE);
ref2.setLazy(true);

DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap.application(new ApplicationConfig("demo-migration-tri-consumer"))
.registry(new RegistryConfig(TriSampleConstants.ZK_ADDRESS))
.reference(ref2)
.start();
this.triDelegate = ref2.get();
}

public static void main(String[] args) {
final ApiMigrationTriConsumer consumer = new ApiMigrationTriConsumer();
System.out.println("demo-migration-both-consumer started");
consumer.sayTriHelloUnary(CommonConstants.TRIPLE);
}

public void sayTriHelloUnary(String protocol) {
System.out.println(triDelegate.sayHello("unary" + "--" + protocol));
}

}

0 comments on commit 9a674ae

Please sign in to comment.