Skip to content
Permalink
Browse files
Merge branch 'private'
  • Loading branch information
hufeng committed Apr 19, 2018
2 parents fd4608c + 8dfaa7d commit 0dbb7c857ca024d25ba0ce84f2607e9badcc51ee
Show file tree
Hide file tree
Showing 26 changed files with 380 additions and 206 deletions.
@@ -8,5 +8,12 @@ clean-dubbo:
rm -rf ./packages/dubbo/es7
@echo "clean dubbo successfully 👌\n"

test-dubbo:
test-dubbo: build-demo
./node_modules/.bin/jest --testPathPattern packages/dubbo/src/__tests__ --verbose --watch

build-demo: demo-api-build
ts-node ./packages/interpret-cli/src/cli.ts interpret -c dubbo.json

demo-api-build:
cd ./java/dubbo-demo/dubbo-demo-api && mvn package
cd ./java/dubbo-demo/dubbo-demo-api && mvn install dependency:copy-dependencies
@@ -0,0 +1,6 @@
{
"output": "./packages/dubbo/src/__tests__/providers",
"entry": "com.alibaba.dubbo.demo",
"entryJarPath": "./java/dubbo-demo/dubbo-demo-api/target/dubbo-demo-api-2.5.7.jar",
"libDirPath": "./java/dubbo-demo/dubbo-demo-api/target/dependency/"
}
@@ -1,6 +1,6 @@
package com.alibaba.dubbo.demo;

public interface BasicTypeService {
public interface BasicTypeProvider {
TypeRequest testBasicType(TypeRequest request);

}
@@ -1,28 +1,28 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed 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.alibaba.dubbo.demo;

public interface DemoService {

String sayHello(String name);

String echo() ;

void test();

UserResponse getUserInfo(UserRequest request);

/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed 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.alibaba.dubbo.demo;

public interface DemoProvider {

String sayHello(String name);

String echo() ;

void test();

UserResponse getUserInfo(UserRequest request);

}
@@ -1,5 +1,5 @@
package com.alibaba.dubbo.demo;

public interface ErrorService {
public interface ErrorProvider {
void errorTest() throws CustomizeException;
}
@@ -13,7 +13,7 @@ public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"META-INF/spring/dubbo-demo-consumer.xml"});
context.start();

// DemoService demoService = (DemoService) context.getBean("demoService"); // 获取远程服务代理
// DemoProvider demoService = (DemoProvider) context.getBean("demoService"); // 获取远程服务代理
//// String hello = demoService.sayHello("world"); // 执行远程方法
//
//// System.out.println(hello); // 显示调用结果
@@ -30,7 +30,7 @@ public static void main(String[] args) {
// UserResponse userInfo = demoService.getUserInfo(request);
// System.out.println(userInfo);

BasicTypeService basicTypeService = (BasicTypeService) context.getBean("basicTypeService");
BasicTypeProvider basicTypeService = (BasicTypeProvider) context.getBean("basicTypeService");
System.out.println(basicTypeService.testBasicType(new TypeRequest()));

try {
@@ -27,7 +27,9 @@
<dubbo:registry address="localhost:2181" protocol="zookeeper"/>

<!-- 生成远程服务代理,可以和本地bean一样使用demoService -->
<dubbo:reference id="demoService" url="dubbo://localhost:20880" check="false" interface="com.alibaba.dubbo.demo.DemoService" version="1.0.0"/>
<dubbo:reference id="demoService" url="dubbo://localhost:20880" check="false"
interface="com.alibaba.dubbo.demo.DemoProvider" version="1.0.0"/>

<dubbo:reference id="basicTypeService" check="false" interface="com.alibaba.dubbo.demo.BasicTypeService" version="2.0.0"/>
<dubbo:reference id="basicTypeService" check="false" interface="com.alibaba.dubbo.demo.BasicTypeProvider"
version="2.0.0"/>
</beans>
@@ -1,11 +1,9 @@
package com.alibaba.dubbo.demo.provider;

import com.alibaba.dubbo.demo.BasicTypeService;
import com.alibaba.dubbo.demo.BasicTypeProvider;
import com.alibaba.dubbo.demo.TypeRequest;

import java.util.Map;

public class BasicTypeServiceImpl implements BasicTypeService{
public class BasicTypeServiceImpl implements BasicTypeProvider {
@Override
public TypeRequest testBasicType(TypeRequest request) {
return request;
@@ -0,0 +1,58 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed 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.alibaba.dubbo.demo.provider;

import com.alibaba.dubbo.demo.DemoProvider;
import com.alibaba.dubbo.demo.UserRequest;
import com.alibaba.dubbo.demo.UserResponse;
import com.alibaba.dubbo.rpc.RpcContext;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class DemoProviderImpl implements DemoProvider {

public String sayHello(String name) {
System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] Hello " + name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress());
return "Hello " + name + ", response form provider: " + RpcContext.getContext().getLocalAddress();
}

@Override
public String echo() {
System.out.println("receive....");
return "pang";
}

@Override
public void test() {
System.out.println("test");
}

@Override
public UserResponse getUserInfo(UserRequest request) {
System.out.println(request);
UserResponse response = new UserResponse();
response.setStatus("ok");
Map<String, String> map = new HashMap<String, String>();
map.put("id", "1");
map.put("name", "test");
response.setInfo(map);
return response;
}

}
@@ -0,0 +1,11 @@
package com.alibaba.dubbo.demo.provider;

import com.alibaba.dubbo.demo.CustomizeException;
import com.alibaba.dubbo.demo.ErrorProvider;

public class ErrorProviderImpl implements ErrorProvider {
@Override
public void errorTest() throws CustomizeException {
throw new CustomizeException("exception");
}
}
@@ -30,13 +30,13 @@
<dubbo:protocol name="dubbo" port="20881"/>

<!-- 和本地bean一样实现服务 -->
<bean id="demoService" class="com.alibaba.dubbo.demo.provider.DemoServiceImpl"/>
<bean id="demoService" class="com.alibaba.dubbo.demo.provider.DemoProviderImpl"/>
<bean id="basicTypeService" class="com.alibaba.dubbo.demo.provider.BasicTypeServiceImpl"/>
<bean id="errorService" class="com.alibaba.dubbo.demo.provider.ErrorServiceImpl"/>
<bean id="errorService" class="com.alibaba.dubbo.demo.provider.ErrorProviderImpl"/>

<!-- 声明需要暴露的服务接口 -->
<dubbo:service interface="com.alibaba.dubbo.demo.DemoService" ref="demoService" version="1.0.0"/>
<dubbo:service interface="com.alibaba.dubbo.demo.BasicTypeService" ref="basicTypeService" version="2.0.0"/>
<dubbo:service interface="com.alibaba.dubbo.demo.ErrorService" ref="errorService" version="1.0.0"/>
<dubbo:service interface="com.alibaba.dubbo.demo.DemoProvider" ref="demoService" version="1.0.0"/>
<dubbo:service interface="com.alibaba.dubbo.demo.BasicTypeProvider" ref="basicTypeService" version="2.0.0"/>
<dubbo:service interface="com.alibaba.dubbo.demo.ErrorProvider" ref="errorService" version="1.0.0"/>

</beans>
@@ -18,5 +18,8 @@
"ip": "1.1.5",
"js-to-java": "2.4.0",
"node-zookeeper-client": "0.2.2"
},
"devDependencies": {
"interpret-util": "0.0.2"
}
}

0 comments on commit 0dbb7c8

Please sign in to comment.