Skip to content

Commit d6707ed

Browse files
author
林尧
committed
add java provider demo
1 parent 857e74a commit d6707ed

File tree

11 files changed

+487
-0
lines changed

11 files changed

+487
-0
lines changed

tests/dubbo_test1.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one or more
5+
* contributor license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright ownership.
7+
* The ASF licenses this file to You under the Apache License, Version 2.0
8+
* (the "License"); you may not use this file except in compliance with
9+
* the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
"""
20+
21+
import json
22+
import logging
23+
import unittest
24+
from dubbo.common.loggers import init_log
25+
from dubbo.client import DubboClient, ZkRegister
26+
27+
logger = logging.getLogger('python-dubbo')
28+
29+
30+
def pretty_print(value):
31+
logger.debug(json.dumps(value, ensure_ascii=False, indent=4, sort_keys=True))
32+
33+
34+
class TestDubbo(unittest.TestCase):
35+
def setUp(self):
36+
init_log() # 初始化日志配置,调用端需要自己配置日志属性
37+
38+
zk = ZkRegister('127.0.0.1:2181')
39+
self.dubbo = DubboClient('org.apache.dubbo.springboot.demo.DemoService', zk_register=zk)
40+
# self.dubbo = DubboClient('me.hourui.echo.provider.Echo', host='127.0.0.1:20880')
41+
42+
def tearDown(self):
43+
# Do something to clear the test environment here.
44+
pass
45+
46+
# @unittest.skip('skip base test')
47+
def test(self):
48+
dubbo = self.dubbo
49+
pretty_print(dubbo.call('sayHello', '张老师'))
50+
51+
52+
53+
if __name__ == '__main__':
54+
test = TestDubbo()
55+
test.test()
56+
# test.test_performance()
57+
# unittest.main()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!--
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<project xmlns="http://maven.apache.org/POM/4.0.0"
18+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20+
<modelVersion>4.0.0</modelVersion>
21+
22+
<groupId>org.apache.dubbo</groupId>
23+
<version>1.0-SNAPSHOT</version>
24+
<artifactId>dubbo-samples-spring-boot-interface</artifactId>
25+
26+
<properties>
27+
<maven.compiler.source>8</maven.compiler.source>
28+
<maven.compiler.target>8</maven.compiler.target>
29+
</properties>
30+
</project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.dubbo.springboot.demo;
18+
19+
public interface DemoService {
20+
21+
String sayHello(String name);
22+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<!--
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<project xmlns="http://maven.apache.org/POM/4.0.0"
18+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20+
<modelVersion>4.0.0</modelVersion>
21+
22+
<artifactId>dubbo-samples-spring-boot-provider</artifactId>
23+
<version>1.0-SNAPSHOT</version>
24+
<groupId>org.apache.dubbo</groupId>
25+
26+
<properties>
27+
<maven.compiler.source>8</maven.compiler.source>
28+
<maven.compiler.target>8</maven.compiler.target>
29+
</properties>
30+
31+
<dependencies>
32+
<dependency>
33+
<groupId>org.apache.dubbo</groupId>
34+
<artifactId>dubbo-samples-spring-boot-interface</artifactId>
35+
<version>1.0-SNAPSHOT</version>
36+
</dependency>
37+
38+
<!-- dubbo -->
39+
<dependency>
40+
<groupId>org.apache.dubbo</groupId>
41+
<artifactId>dubbo-spring-boot-starter</artifactId>
42+
<version>3.1.11</version>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.apache.dubbo</groupId>
46+
<artifactId>dubbo-registry-zookeeper</artifactId>
47+
<version>3.1.11</version>
48+
</dependency>
49+
50+
<!-- spring starter -->
51+
<dependency>
52+
<groupId>org.springframework.boot</groupId>
53+
<artifactId>spring-boot-starter</artifactId>
54+
<version>2.2.0.RELEASE</version>
55+
<exclusions>
56+
<exclusion>
57+
<groupId>org.springframework.boot</groupId>
58+
<artifactId>spring-boot-starter-logging</artifactId>
59+
</exclusion>
60+
</exclusions>
61+
</dependency>
62+
63+
<dependency>
64+
<groupId>org.springframework.boot</groupId>
65+
<artifactId>spring-boot-starter-log4j2</artifactId>
66+
<version>2.2.0.RELEASE</version>
67+
</dependency>
68+
</dependencies>
69+
70+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.dubbo.springboot.demo.provider;
18+
19+
20+
import org.apache.dubbo.config.annotation.DubboService;
21+
import org.apache.dubbo.springboot.demo.DemoService;
22+
23+
@DubboService
24+
public class DemoServiceImpl implements DemoService {
25+
26+
@Override
27+
public String sayHello(String name) {
28+
return "Hello " + name;
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.dubbo.springboot.demo.provider;
19+
20+
21+
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
22+
import org.springframework.boot.SpringApplication;
23+
import org.springframework.boot.autoconfigure.SpringBootApplication;
24+
25+
@SpringBootApplication
26+
@EnableDubbo
27+
public class ProviderApplication {
28+
public static void main(String[] args) {
29+
SpringApplication.run(ProviderApplication.class, args);
30+
}
31+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
dubbo:
18+
application:
19+
name: dubbo-springboot-demo-provider
20+
logger: slf4j
21+
protocol:
22+
name: dubbo
23+
port: 50052
24+
registry:
25+
address: zookeeper://${zookeeper.address:127.0.0.1}:2181
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one or more
4+
~ contributor license agreements. See the NOTICE file distributed with
5+
~ this work for additional information regarding copyright ownership.
6+
~ The ASF licenses this file to You under the Apache License, Version 2.0
7+
~ (the "License"); you may not use this file except in compliance with
8+
~ the License. You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
-->
18+
<Configuration status="WARN">
19+
<Appenders>
20+
<Console name="Console" target="SYSTEM_OUT" follow="true">
21+
<PatternLayout pattern="%style{%d{HH:mm:ss.SSS}}{Magenta} %style{|-}{White}%highlight{%-5p} [%t] %style{%40.40c}{Cyan}:%style{%-3L}{Blue} %style{-|}{White} %m%n%rEx{filters(jdk.internal.reflect,java.lang.reflect,sun.reflect)}" disableAnsi="false" charset="UTF-8"/>
22+
</Console>
23+
</Appenders>
24+
<Loggers>
25+
<Root level="info">
26+
<AppenderRef ref="Console"/>
27+
</Root>
28+
<Logger name="log4j.logger.org.apache.zookeeper" level="warn" />
29+
<Logger name="log4j.logger.org.apache.dubbo.registry.zookeeper" level="warn" />
30+
<Logger name="log4j.logger.org.apache.dubbo.config.deploy" level="warn" />
31+
<Logger name="log4j.logger.org.apache.dubbo.registry.client" level="warn" />
32+
<Logger name="log4j.logger.org.apache.dubbo.rpc.model" level="warn" />
33+
</Loggers>
34+
</Configuration>

0 commit comments

Comments
 (0)