Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[type:feature] support dubbo protobuf serialization #5903

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ private String buildRpcExt(final ServiceBean<?> serviceBean, final String method
.sent(Optional.ofNullable(serviceBean.getSent()).orElse(Boolean.FALSE))
.cluster(StringUtils.isNotEmpty(serviceBean.getCluster()) ? serviceBean.getCluster() : Constants.DEFAULT_CLUSTER)
.url("")
.serialization(serviceBean.getSerialization())
.build();
// set method config: loadbalance,retries,timeout,sent
Optional.ofNullable(serviceBean.getMethods()).orElse(Collections.emptyList()).stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public class DubboRpcExt implements Serializable {

private String protocol;

private String serialization;

/**
* constructor without parameter.
*/
Expand Down Expand Up @@ -71,7 +73,8 @@ public DubboRpcExt(final String group,
final String url,
final Boolean sent,
final String cluster,
final String protocol) {
final String protocol,
final String serialization) {
this.group = group;
this.version = version;
this.loadbalance = loadbalance;
Expand All @@ -81,6 +84,7 @@ public DubboRpcExt(final String group,
this.sent = sent;
this.cluster = cluster;
this.protocol = protocol;
this.serialization = serialization;
}

/**
Expand Down Expand Up @@ -245,6 +249,24 @@ public void setProtocol(final String protocol) {
this.protocol = protocol;
}

/**
* get serialization.
*
* @return serialization
*/
public String getSerialization() {
return serialization;
}

/**
* set serialization.
*
* @param serialization serialization
*/
public void setSerialization(final String serialization) {
this.serialization = serialization;
}

@Override
public String toString() {
return "DubboRpcExt{"
Expand All @@ -257,6 +279,7 @@ public String toString() {
+ ", sent=" + sent
+ ", cluster='" + cluster + '\''
+ ", protocol='" + protocol + '\''
+ ", serialization='" + serialization + '\''
+ '}';
}

Expand Down Expand Up @@ -292,6 +315,8 @@ public static final class Builder {

private String protocol;

private String serialization;

/**
* constructor without parameter.
*/
Expand Down Expand Up @@ -397,6 +422,17 @@ public Builder protocol(final String protocol) {
return this;
}

/**
* set serialization.
*
* @param serialization serialization
* @return Builder
*/
public Builder serialization(final String serialization) {
this.serialization = serialization;
return this;
}

/**
* build DubboRpcExt.
*
Expand All @@ -413,6 +449,7 @@ public DubboRpcExt build() {
dubboRpcExt.setSent(sent);
dubboRpcExt.setCluster(cluster);
dubboRpcExt.setProtocol(protocol);
dubboRpcExt.setSerialization(serialization);
return dubboRpcExt;
}
}
Expand Down
1 change: 1 addition & 0 deletions shenyu-examples/shenyu-examples-dubbo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<nacos-client.version>2.2.4</nacos-client.version>
<apache.dubbo.version>3.2.14</apache.dubbo.version>
<zookeeper.version>3.9.2</zookeeper.version>
<protobuf.version>3.25.5</protobuf.version>
</properties>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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.shenyu.examples.apache.dubbo.service.annotation.impl;

import com.google.protobuf.Empty;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.shenyu.client.dubbo.common.annotation.ShenyuDubboClient;
import org.apache.shenyu.examples.dubbo.api.service.DubboProtobufService;
import org.apache.shenyu.examples.dubbo.api.service.DubboTestProtobuf;

@DubboService(serialization = "protobuf")
@ShenyuDubboClient(value = "/protobufSerialization")
public class DubboProtobufServiceImpl implements DubboProtobufService {

@ShenyuDubboClient("/insert")
@Override
public DubboTestProtobuf insert(final DubboTestProtobuf request) {
return request;
}

@ShenyuDubboClient("/update")
@Override
public Empty update(final DubboTestProtobuf request) {
return Empty.getDefaultInstance();
}

@ShenyuDubboClient("/findOne")
@Override
public DubboTestProtobuf findOne(final Empty request) {
return DubboTestProtobuf.newBuilder().setId("1").setName("test1").build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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.shenyu.examples.apache.dubbo.service.xml.impl;

import com.google.protobuf.Empty;
import org.apache.shenyu.client.dubbo.common.annotation.ShenyuDubboClient;
import org.apache.shenyu.examples.dubbo.api.service.DubboProtobufService;
import org.apache.shenyu.examples.dubbo.api.service.DubboTestProtobuf;
import org.springframework.stereotype.Service;

@Service("dubboProtobufService")
@ShenyuDubboClient(value = "/protobufSerialization")
public class DubboProtobufServiceImpl implements DubboProtobufService {

@ShenyuDubboClient("/insert")
@Override
public DubboTestProtobuf insert(final DubboTestProtobuf request) {
return request;
}

@ShenyuDubboClient("/update")
@Override
public Empty update(final DubboTestProtobuf request) {
return Empty.getDefaultInstance();
}

@ShenyuDubboClient("/findOne")
@Override
public DubboTestProtobuf findOne(final Empty request) {
return DubboTestProtobuf.newBuilder().setId("1").setName("test1").build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@
<dubbo:service timeout="10000" interface="org.apache.shenyu.examples.dubbo.api.service.DubboMultiParamService" ref="dubboMultiParamService"/>
<dubbo:service timeout="10000" interface="org.apache.shenyu.examples.dubbo.api.service.DubboClassTestService" ref="dubboClassTestService"/>
<dubbo:service timeout="10000" interface="org.apache.shenyu.examples.dubbo.api.service.DubboClassMultiParamService" ref="dubboClassMultiParamService"/>
<dubbo:service timeout="10000" interface="org.apache.shenyu.examples.dubbo.api.service.DubboProtobufService" ref="dubboProtobufService" serialization="protobuf"/>

</beans>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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.shenyu.examples.apache.dubbo.service.impl;

import com.google.protobuf.Empty;
import org.apache.shenyu.client.dubbo.common.annotation.ShenyuDubboClient;
import org.apache.shenyu.examples.dubbo.api.service.DubboProtobufService;
import org.apache.shenyu.examples.dubbo.api.service.DubboTestProtobuf;
import org.springframework.stereotype.Service;

@ShenyuDubboClient(value = "/protobufSerialization")
@Service("dubboProtobufService")
public class DubboProtobufServiceImpl implements DubboProtobufService {

@ShenyuDubboClient("/insert")
@Override
public DubboTestProtobuf insert(final DubboTestProtobuf request) {
return request;
}

@ShenyuDubboClient("/update")
@Override
public Empty update(final DubboTestProtobuf request) {
return Empty.getDefaultInstance();
}

@ShenyuDubboClient("/findOne")
@Override
public DubboTestProtobuf findOne(final Empty request) {
return DubboTestProtobuf.newBuilder().setId("1").setName("test1").build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@

<dubbo:service timeout="10000" interface="org.apache.shenyu.examples.dubbo.api.service.DubboTestService" ref="dubboTestService" version="v0.0.2"/>
<dubbo:service timeout="10000" interface="org.apache.shenyu.examples.dubbo.api.service.DubboMultiParamService" ref="dubboMultiParamService" version="v0.0.2"/>
<dubbo:service timeout="10000" interface="org.apache.shenyu.examples.dubbo.api.service.DubboProtobufService" ref="dubboProtobufService" version="v0.0.2" serialization="protobuf"/>
</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,84 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>shenyu-examples-dubbo-api</artifactId>

<dependencies>
<dependency>
<groupId>org.apache.dubbo.extensions</groupId>
<artifactId>dubbo-serialization-protobuf</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>${apache.dubbo.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId>
<version>${protobuf.version}</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>${protobuf.version}</version>
</dependency>
</dependencies>

<build>
<finalName>shenyu-examples-dubbo-api</finalName>

<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.7.1</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.6.1</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}</protocArtifact>
<outputDirectory>${project.build.directory}/generated-sources/protobuf/java</outputDirectory>
<protocPlugins>
<protocPlugin>
<id>dubbo</id>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-compiler</artifactId>
<version>${apache.dubbo.version}</version>
<mainClass>org.apache.dubbo.gen.dubbo.Dubbo3Generator</mainClass>
</protocPlugin>
</protocPlugins>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/protobuf/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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";

option java_multiple_files = true;
option java_package = "org.apache.shenyu.examples.dubbo.api.service";
package DubboTestProtobuf;

import "google/protobuf/empty.proto";

message DubboTestProtobuf {
string id = 1;
string name = 2;
}

service DubboProtobufService {
rpc insert(DubboTestProtobuf) returns (DubboTestProtobuf) {}

rpc findOne(google.protobuf.Empty) returns (DubboTestProtobuf) {}

rpc update(DubboTestProtobuf) returns (google.protobuf.Empty) {}
}
Loading
Loading