Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Merge branch 'protobuf-demo' of https://github.com/vio-lin/dubbo-samples
- Loading branch information
Showing
22 changed files
with
1,470 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# About this sample | ||
|
||
This sample code demonstrates building up dubbo service provider and service consumer with the pure API approach. | ||
|
||
## About Request and Response Entity | ||
Google protocol file is in protobuf-json-serialization-api\src\main\resources\protobuf\googleProtobufBasic.proto. | ||
when protocol be modified, should refresh **org.apache.dubbo.sample.protobuf.GoogleProtobufBasic**. | ||
1. modify googleProtobufBasic.proto | ||
2. add <plugin> protobuf-maven-plugin</plugin> to dubbo-samples-protobuf\protobuf-json-serialization-api\pom.xml | ||
3. run bash ``` | ||
mvn generate-sources | ||
``` | ||
4. copy code generated located in target directory to dubbo-samples-protobuf\protobuf-json-serialization-api\src\main\java | ||
|
||
## Start the service provider | ||
|
||
``` | ||
Main class: org.apache.dubbo.sample.protobuf.provider.ProviderStarter | ||
``` | ||
|
||
## Invoke the service consumer | ||
|
||
``` | ||
normar client | ||
Main class: org.apache.dubbo.sample.protobuf.consumer.ConsumerStarter | ||
generic reference | ||
Main class: org.apache.dubbo.sample.protobuf.genericCall.GenericClient | ||
``` | ||
|
||
## About Service Metadata of protobuf Service | ||
When invoke service with generic reference, we can construct request by referencing service meta data. | ||
Demo show how to use service meta data. | ||
``` | ||
org.apache.dubbo.sample.protobuf.genericCall.GenericClient.printServiceData | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<groupId>org.apache.dubbo</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>dubbo-samples-protobuf-json</artifactId> | ||
<packaging>pom</packaging> | ||
<modules> | ||
<module>protobuf-json-serialization-api</module> | ||
<module>protobuf-json-serialization-demo</module> | ||
<module>protobuf-json-serialization-implement</module> | ||
</modules> | ||
|
||
<properties> | ||
<source.level>1.8</source.level> | ||
<target.level>1.8</target.level> | ||
<dubbo.version>2.7.4.1</dubbo.version> | ||
<protobuf.java>3.6.0</protobuf.java> | ||
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version> | ||
<maven-failsafe-plugin.version>2.21.0</maven-failsafe-plugin.version> | ||
<junit.version>4.12</junit.version> | ||
<spring.version>4.3.16.RELEASE</spring.version> | ||
<dubbo.port>20880</dubbo.port> | ||
<zookeeper.port>2181</zookeeper.port> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo</artifactId> | ||
<version>${dubbo.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-dependencies-zookeeper</artifactId> | ||
<version>${dubbo.version}</version> | ||
<type>pom</type> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.google.protobuf</groupId> | ||
<artifactId>protobuf-java</artifactId> | ||
<version>${protobuf.java}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>${junit.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-test</artifactId> | ||
<version>${spring.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>${maven-compiler-plugin.version}</version> | ||
<configuration> | ||
<source>${source.level}</source> | ||
<target>${target.level}</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ 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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>dubbo-samples-protobuf-json</artifactId> | ||
<groupId>org.apache.dubbo</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>protobuf-json-serialization-api</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.protobuf</groupId> | ||
<artifactId>protobuf-java</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<extensions> | ||
<extension> | ||
<groupId>kr.motd.maven</groupId> | ||
<artifactId>os-maven-plugin</artifactId> | ||
<version>1.6.0</version> | ||
</extension> | ||
</extensions> | ||
<plugins> | ||
<!--For CodeGen only--> | ||
<plugin> | ||
<groupId>org.xolstice.maven.plugins</groupId> | ||
<artifactId>protobuf-maven-plugin</artifactId> | ||
<version>0.6.1</version> | ||
<extensions>true</extensions> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>compile</goal> | ||
<goal>test-compile</goal> | ||
</goals> | ||
<configuration> | ||
<protoSourceRoot>${basedir}/src/main/resources/protobuf</protoSourceRoot> | ||
<protocArtifact>com.google.protobuf:protoc:3.4.0:exe:${os.detected.classifier} | ||
</protocArtifact> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* 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.protobuf; | ||
|
||
/** | ||
* @author lin | ||
* Date: 2019-10-03 | ||
*/ | ||
public interface GoogleProtobufService { | ||
GoogleProtobufBasic.GooglePBResponseType callGoogleProtobuf(GoogleProtobufBasic.GooglePBRequestType requestType); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
syntax = "proto3"; | ||
package org.apache.dubbo.sample.protobuf; | ||
|
||
message GooglePBRequestType { | ||
double double = 1; | ||
float float = 2; | ||
int32 int32 = 3; | ||
int64 int64 = 4; | ||
uint32 uint32 =5; | ||
uint64 uint64 =6; | ||
sint32 sint32 =7; | ||
sint64 sint64 =8; | ||
fixed32 fixed32 =9; | ||
fixed64 fixed64 =10; | ||
sfixed32 sfixed32 =11; | ||
sfixed64 sfixed64 =12; | ||
bool bool = 13; | ||
string string = 14; | ||
bytes bytesType = 15; | ||
DriverCard card = 16; | ||
repeated DriverCard cards = 17; | ||
map<string, DriverCard> cardsmap = 18; | ||
} | ||
|
||
enum LEVEL { | ||
C1 = 0; | ||
C2 = 1; | ||
C3 = 2; | ||
} | ||
|
||
message DriverCard { | ||
LEVEL level = 1; | ||
string id = 2; | ||
int32 years = 3; | ||
} | ||
|
||
message GooglePBResponseType { | ||
double double = 1; | ||
float float = 2; | ||
int32 int32 = 3; | ||
int64 int64 = 4; | ||
uint32 uint32 =5; | ||
uint64 uint64 =6; | ||
sint32 sint32 =7; | ||
sint64 sint64 =8; | ||
fixed32 fixed32 =9; | ||
fixed64 fixed64 =10; | ||
sfixed32 sfixed32 =11; | ||
sfixed64 sfixed64 =12; | ||
bool bool = 13; | ||
string string = 14; | ||
bytes bytesType = 15; | ||
DriverCard card = 16; | ||
repeated DriverCard cards = 17; | ||
map<string, DriverCard> cardsmap = 18; | ||
} | ||
|
||
service CDubboGooglePBService { | ||
rpc sayHello (GooglePBRequestType) returns (GooglePBResponseType); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ 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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>dubbo-samples-protobuf-json</artifactId> | ||
<groupId>org.apache.dubbo</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>protobuf-json-serialization-demo</artifactId> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>protobuf-json-serialization-api</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>protobuf-json-serialization-implement</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-dependencies-zookeeper</artifactId> | ||
<version>${dubbo.version}</version> | ||
<type>pom</type> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-dependencies-zookeeper</artifactId> | ||
<version>${dubbo.version}</version> | ||
<type>pom</type> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-metadata-definition-protobuf</artifactId> | ||
<version>${dubbo.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<profiles> | ||
<profile> | ||
<id>javax.annotation</id> | ||
<activation> | ||
<jdk>[1.11,)</jdk> | ||
</activation> | ||
<dependencies> | ||
<dependency> | ||
<groupId>javax.annotation</groupId> | ||
<artifactId>javax.annotation-api</artifactId> | ||
<version>1.3.2</version> | ||
</dependency> | ||
</dependencies> | ||
</profile> | ||
</profiles> | ||
|
||
</project> |
Oops, something went wrong.