You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by zh...@apache.org on 2023/01/13 07:13:20 UTC
[shenyu] branch master updated: [ISSUE #3450]Add brpc example (#4309)
This is an automated email from the ASF dual-hosted git repository.
zhangzicheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new f97751172 [ISSUE #3450]Add brpc example (#4309)
f97751172 is described below
commit f977511726ce18cfac6f228a138f3168011ea085
Author: SongTao Zhuang <51...@users.noreply.github.com>
AuthorDate: Fri Jan 13 15:13:13 2023 +0800
[ISSUE #3450]Add brpc example (#4309)
* add: brpc example
* add: brpc example docker file
* remove: unused config
* update
* add: brpc service annotation attributes
Co-authored-by: dragon-zhang <zh...@apache.org>
---
.../brpc/BrpcContextRefreshedEventListener.java | 10 +-
.../brpc/common/annotation/ShenyuBrpcService.java | 62 +++++++++
shenyu-examples/pom.xml | 1 +
shenyu-examples/shenyu-examples-brpc/Dockerfile | 29 +++++
shenyu-examples/shenyu-examples-brpc/pom.xml | 51 ++++++++
.../shenyu-examples-brpc-api/pom.xml | 43 +++++++
.../shenyu/examples/brpc/api/entity/Address.java | 26 ++++
.../shenyu/examples/brpc/api/entity/ExtInfo.java | 29 +++++
.../shenyu/examples/brpc/api/entity/Gender.java | 28 ++++
.../shenyu/examples/brpc/api/entity/User.java | 141 +++++++++++++++++++++
.../examples/brpc/api/service/BrpcDemoService.java | 62 +++++++++
.../shenyu-examples-brpc-service/pom.xml | 52 ++++++++
.../src/main/http/brpc-test-api.http | 54 ++++++++
.../examples/brpc/service/TestBrpcApplication.java | 39 ++++++
.../brpc/service/impl/BrpcDemoServiceImpl.java | 106 ++++++++++++++++
.../src/main/resources/application.yml | 47 +++++++
.../shenyu/plugin/brpc/proxy/BrpcProxyService.java | 4 +-
17 files changed, 773 insertions(+), 11 deletions(-)
diff --git a/shenyu-client/shenyu-client-brpc/src/main/java/org/apache/shenyu/client/brpc/BrpcContextRefreshedEventListener.java b/shenyu-client/shenyu-client-brpc/src/main/java/org/apache/shenyu/client/brpc/BrpcContextRefreshedEventListener.java
index 03170e8df..59f8ed7e7 100644
--- a/shenyu-client/shenyu-client-brpc/src/main/java/org/apache/shenyu/client/brpc/BrpcContextRefreshedEventListener.java
+++ b/shenyu-client/shenyu-client-brpc/src/main/java/org/apache/shenyu/client/brpc/BrpcContextRefreshedEventListener.java
@@ -17,7 +17,6 @@
package org.apache.shenyu.client.brpc;
-import com.baidu.cloud.starlight.springcloud.server.annotation.RpcService;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.shenyu.client.brpc.common.annotation.ShenyuBrpcClient;
@@ -131,14 +130,7 @@ public class BrpcContextRefreshedEventListener extends AbstractContextRefreshedE
@Override
protected MetaDataRegisterDTO buildMetaDataDTO(final Object bean, final ShenyuBrpcClient shenyuBrpcClient, final String superPath, final Class<?> clazz, final Method method) {
- String serviceName = clazz.getAnnotation(RpcService.class).serviceId();
- if (StringUtils.isEmpty(serviceName)) {
- if (clazz.getInterfaces().length > 0) {
- serviceName = clazz.getInterfaces()[0].getName();
- } else {
- serviceName = clazz.getName();
- }
- }
+ String serviceName = clazz.getInterfaces().length > 0 ? clazz.getInterfaces()[0].getName() : clazz.getName();
String path = superPath;
String desc = shenyuBrpcClient.desc();
String host = IpUtils.isCompleteHost(this.getHost()) ? this.getHost() : IpUtils.getHost(this.getHost());
diff --git a/shenyu-client/shenyu-client-brpc/src/main/java/org/apache/shenyu/client/brpc/common/annotation/ShenyuBrpcService.java b/shenyu-client/shenyu-client-brpc/src/main/java/org/apache/shenyu/client/brpc/common/annotation/ShenyuBrpcService.java
new file mode 100644
index 000000000..b3bafd479
--- /dev/null
+++ b/shenyu-client/shenyu-client-brpc/src/main/java/org/apache/shenyu/client/brpc/common/annotation/ShenyuBrpcService.java
@@ -0,0 +1,62 @@
+/*
+ * 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.client.brpc.common.annotation;
+
+import com.baidu.cloud.starlight.springcloud.server.annotation.RpcService;
+import org.springframework.core.annotation.AliasFor;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Shenyu brpc service annotation.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+@Inherited
+@RpcService
+@ShenyuBrpcClient
+public @interface ShenyuBrpcService {
+
+ /**
+ * service id.
+ *
+ * @return the string
+ */
+ @AliasFor(annotation = RpcService.class)
+ String serviceId() default "";
+
+ /**
+ * protocol.
+ *
+ * @return the string
+ */
+ @AliasFor(annotation = RpcService.class)
+ String protocol() default "";
+
+ /**
+ * filters.
+ *
+ * @return the string
+ */
+ @AliasFor(annotation = RpcService.class)
+ String filters() default "";
+}
diff --git a/shenyu-examples/pom.xml b/shenyu-examples/pom.xml
index 135adfe4f..1890e5b15 100644
--- a/shenyu-examples/pom.xml
+++ b/shenyu-examples/pom.xml
@@ -56,6 +56,7 @@
<module>shenyu-examples-springmvc</module>
<module>shenyu-examples-springmvc-tomcat</module>
<module>shenyu-examples-sdk</module>
+ <module>shenyu-examples-brpc</module>
</modules>
<build>
diff --git a/shenyu-examples/shenyu-examples-brpc/Dockerfile b/shenyu-examples/shenyu-examples-brpc/Dockerfile
new file mode 100644
index 000000000..ac04a788b
--- /dev/null
+++ b/shenyu-examples/shenyu-examples-brpc/Dockerfile
@@ -0,0 +1,29 @@
+# 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.
+
+FROM openjdk:8-jre-alpine
+
+ENV APP_NAME shenyu-examples-brpc
+ENV LOCAL_PATH /opt/${APP_NAME}
+
+RUN mkdir -p ${LOCAL_PATH}
+
+ADD target/${APP_NAME}.jar ${LOCAL_PATH}
+
+WORKDIR ${LOCAL_PATH}
+EXPOSE 8005
+
+CMD java -jar ${APP_NAME}.jar
diff --git a/shenyu-examples/shenyu-examples-brpc/pom.xml b/shenyu-examples/shenyu-examples-brpc/pom.xml
new file mode 100644
index 000000000..44830f804
--- /dev/null
+++ b/shenyu-examples/shenyu-examples-brpc/pom.xml
@@ -0,0 +1,51 @@
+<?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>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-examples</artifactId>
+ <version>2.5.1-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>shenyu-examples-brpc</artifactId>
+ <packaging>pom</packaging>
+
+ <modules>
+ <module>shenyu-examples-brpc-api</module>
+ <module>shenyu-examples-brpc-service</module>
+ </modules>
+
+ <properties>
+ <spring.cloud-version>2021.0.5</spring.cloud-version>
+ </properties>
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.cloud</groupId>
+ <artifactId>spring-cloud-dependencies</artifactId>
+ <version>${spring.cloud-version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+</project>
diff --git a/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-api/pom.xml b/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-api/pom.xml
new file mode 100644
index 000000000..2434601d0
--- /dev/null
+++ b/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-api/pom.xml
@@ -0,0 +1,43 @@
+<?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>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-examples-brpc</artifactId>
+ <version>2.5.1-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>shenyu-examples-brpc-api</artifactId>
+
+ <build>
+ <finalName>shenyu-examples-brpc-api</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>8</source>
+ <target>8</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-api/src/main/java/org/apache/shenyu/examples/brpc/api/entity/Address.java b/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-api/src/main/java/org/apache/shenyu/examples/brpc/api/entity/Address.java
new file mode 100644
index 000000000..eb45c2795
--- /dev/null
+++ b/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-api/src/main/java/org/apache/shenyu/examples/brpc/api/entity/Address.java
@@ -0,0 +1,26 @@
+/*
+ * 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.brpc.api.entity;
+
+public class Address {
+ private String address;
+
+ public Address(final String address) {
+ this.address = address;
+ }
+}
diff --git a/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-api/src/main/java/org/apache/shenyu/examples/brpc/api/entity/ExtInfo.java b/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-api/src/main/java/org/apache/shenyu/examples/brpc/api/entity/ExtInfo.java
new file mode 100644
index 000000000..01bdd20ca
--- /dev/null
+++ b/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-api/src/main/java/org/apache/shenyu/examples/brpc/api/entity/ExtInfo.java
@@ -0,0 +1,29 @@
+/*
+ * 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.brpc.api.entity;
+
+public class ExtInfo {
+ private String key;
+
+ private String value;
+
+ public ExtInfo(final String key, final String value) {
+ this.key = key;
+ this.value = value;
+ }
+}
diff --git a/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-api/src/main/java/org/apache/shenyu/examples/brpc/api/entity/Gender.java b/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-api/src/main/java/org/apache/shenyu/examples/brpc/api/entity/Gender.java
new file mode 100644
index 000000000..c76b43aba
--- /dev/null
+++ b/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-api/src/main/java/org/apache/shenyu/examples/brpc/api/entity/Gender.java
@@ -0,0 +1,28 @@
+/*
+ * 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.brpc.api.entity;
+
+public enum Gender {
+ MALE("male"), FEMALE("female"), NONE("none");
+
+ private final String name;
+
+ Gender(final String name) {
+ this.name = name;
+ }
+}
diff --git a/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-api/src/main/java/org/apache/shenyu/examples/brpc/api/entity/User.java b/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-api/src/main/java/org/apache/shenyu/examples/brpc/api/entity/User.java
new file mode 100644
index 000000000..f4cc2d17d
--- /dev/null
+++ b/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-api/src/main/java/org/apache/shenyu/examples/brpc/api/entity/User.java
@@ -0,0 +1,141 @@
+/*
+ * 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.brpc.api.entity;
+
+import java.util.List;
+import java.util.Map;
+
+public class User {
+
+ private long userId;
+
+ private String userName;
+
+ private double balance;
+
+ private List<String> tags;
+
+ private Map<String, Address> map;
+
+ private List<ExtInfo> extInfos;
+
+ private Gender gender;
+
+ public User() {
+
+ }
+
+ /**
+ * get user id.
+ *
+ * @return user id
+ */
+ public long getUserId() {
+ return userId;
+ }
+
+ /**
+ * set user id.
+ *
+ * @param userId user id
+ */
+ public void setUserId(final long userId) {
+ this.userId = userId;
+ }
+
+ /**
+ * get user name.
+ *
+ * @return user name
+ */
+ public String getUserName() {
+ return userName;
+ }
+
+ /**
+ * set user name.
+ *
+ * @param userName user name
+ */
+ public void setUserName(final String userName) {
+ this.userName = userName;
+ }
+
+ /**
+ * get balance.
+ *
+ * @return balance.
+ */
+ public double getBalance() {
+ return balance;
+ }
+
+ /**
+ * set balance.
+ *
+ * @param balance balance
+ */
+ public void setBalance(final double balance) {
+ this.balance = balance;
+ }
+
+ /**
+ * get tag list.
+ *
+ * @return list of tag
+ */
+ public List<String> getTags() {
+ return tags;
+ }
+
+ /**
+ * set tag list.
+ *
+ * @param tags tags
+ */
+ public void setTags(final List<String> tags) {
+ this.tags = tags;
+ }
+
+ /**
+ * set ext info list.
+ *
+ * @param extInfos exinfos
+ */
+ public void setExtInfos(final List<ExtInfo> extInfos) {
+ this.extInfos = extInfos;
+ }
+
+ /**
+ * set gender.
+ *
+ * @param gender gender
+ */
+ public void setGender(final Gender gender) {
+ this.gender = gender;
+ }
+
+ /**
+ * set map.
+ *
+ * @param map map
+ */
+ public void setMap(final Map<String, Address> map) {
+ this.map = map;
+ }
+}
diff --git a/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-api/src/main/java/org/apache/shenyu/examples/brpc/api/service/BrpcDemoService.java b/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-api/src/main/java/org/apache/shenyu/examples/brpc/api/service/BrpcDemoService.java
new file mode 100644
index 000000000..88eb97294
--- /dev/null
+++ b/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-api/src/main/java/org/apache/shenyu/examples/brpc/api/service/BrpcDemoService.java
@@ -0,0 +1,62 @@
+/*
+ * 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.brpc.api.service;
+
+import org.apache.shenyu.examples.brpc.api.entity.User;
+
+import java.util.List;
+import java.util.Map;
+
+public interface BrpcDemoService {
+
+ /**
+ * connect.
+ */
+ void connect();
+
+ /**
+ * get user.
+ *
+ * @param userId user id
+ * @return user
+ */
+ User getUser(Long userId);
+
+ /**
+ * get all name.
+ *
+ * @return list of name
+ */
+ List<String> allName();
+
+ /**
+ * get user by id and name.
+ *
+ * @param userId user id
+ * @param name user name
+ * @return user
+ */
+ User getUserByIdAndName(Long userId, String name);
+
+ /**
+ * get user map.
+ * @param userId user id
+ * @return user map
+ */
+ Map<Long, User> userMap(Long userId);
+}
diff --git a/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-service/pom.xml b/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-service/pom.xml
new file mode 100644
index 000000000..a36f44a1d
--- /dev/null
+++ b/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-service/pom.xml
@@ -0,0 +1,52 @@
+<?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>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-examples-brpc</artifactId>
+ <version>2.5.1-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>shenyu-examples-brpc-service</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-spring-boot-starter-client-brpc</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-examples-brpc-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-service/src/main/http/brpc-test-api.http b/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-service/src/main/http/brpc-test-api.http
new file mode 100644
index 000000000..818db857e
--- /dev/null
+++ b/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-service/src/main/http/brpc-test-api.http
@@ -0,0 +1,54 @@
+#
+# 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.
+#
+
+### shengyu getway proxy getUser
+POST http://localhost:9195/brpc/getUser
+Accept: application/json
+Content-Type: application/json
+
+{
+ "userId": 127
+}
+
+### shengyu getway proxy allName
+GET http://localhost:9195/brpc/allName
+Accept: application/json
+Content-Type: application/json
+
+### shengyu getway proxy connect
+GET http://localhost:9195/brpc/connect
+Accept: application/json
+Content-Type: application/json
+
+### shengyu getway proxy getUserByIdAndName
+POST http://localhost:9195/brpc/getUserByIdAndName
+Accept: application/json
+Content-Type: application/json
+
+{
+ "userId": 127,
+ "name": "zst"
+}
+
+### shengyu getway proxy userMap
+POST http://localhost:9195/brpc/userMap
+Accept: application/json
+Content-Type: application/json
+
+{
+ "userId": 127
+}
\ No newline at end of file
diff --git a/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-service/src/main/java/org/apache/shenyu/examples/brpc/service/TestBrpcApplication.java b/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-service/src/main/java/org/apache/shenyu/examples/brpc/service/TestBrpcApplication.java
new file mode 100644
index 000000000..07ace8bda
--- /dev/null
+++ b/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-service/src/main/java/org/apache/shenyu/examples/brpc/service/TestBrpcApplication.java
@@ -0,0 +1,39 @@
+/*
+ * 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.brpc.service;
+
+import com.baidu.cloud.starlight.springcloud.server.annotation.StarlightScan;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+/**
+ * Brpc service starter.
+ */
+@SpringBootApplication
+@StarlightScan
+public class TestBrpcApplication {
+
+ /**
+ * Main Entrance.
+ *
+ * @param args startup arguments
+ */
+ public static void main(final String[] args) {
+ SpringApplication.run(TestBrpcApplication.class, args);
+ }
+}
diff --git a/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-service/src/main/java/org/apache/shenyu/examples/brpc/service/impl/BrpcDemoServiceImpl.java b/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-service/src/main/java/org/apache/shenyu/examples/brpc/service/impl/BrpcDemoServiceImpl.java
new file mode 100644
index 000000000..f9a8a40c6
--- /dev/null
+++ b/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-service/src/main/java/org/apache/shenyu/examples/brpc/service/impl/BrpcDemoServiceImpl.java
@@ -0,0 +1,106 @@
+/*
+ * 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.brpc.service.impl;
+
+import org.apache.shenyu.client.brpc.common.annotation.ShenyuBrpcClient;
+import org.apache.shenyu.client.brpc.common.annotation.ShenyuBrpcService;
+import org.apache.shenyu.examples.brpc.api.entity.Address;
+import org.apache.shenyu.examples.brpc.api.entity.ExtInfo;
+import org.apache.shenyu.examples.brpc.api.entity.Gender;
+import org.apache.shenyu.examples.brpc.api.entity.User;
+import org.apache.shenyu.examples.brpc.api.service.BrpcDemoService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Brpc demo service.
+ */
+@ShenyuBrpcService
+public class BrpcDemoServiceImpl implements BrpcDemoService {
+
+ private static final Logger LOG = LoggerFactory.getLogger(BrpcDemoServiceImpl.class);
+
+ @Override
+ @ShenyuBrpcClient("/getUser")
+ public User getUser(final Long userId) {
+ User user = new User();
+ user.setUserId(userId);
+ user.setUserName("User1");
+ user.setBalance(1000.21d);
+ user.setGender(Gender.MALE);
+ List<String> tags = new LinkedList<>();
+ tags.add("zst");
+ tags.add("127072");
+ user.setTags(tags);
+ List<ExtInfo> extInfos = new LinkedList<>();
+ ExtInfo extInfo = new ExtInfo("hobby", "game");
+ extInfos.add(extInfo);
+ user.setExtInfos(extInfos);
+ user.setMap(Collections.singletonMap("key", new Address("HZ")));
+ return user;
+ }
+
+ @Override
+ @ShenyuBrpcClient(path = "/allName")
+ public List<String> allName() {
+ List<String> users = new LinkedList<>();
+ users.add("zst");
+ users.add("hwj");
+ return users;
+ }
+
+ @Override
+ @ShenyuBrpcClient(path = "/getUserByIdAndName")
+ public User getUserByIdAndName(final Long userId, final String name) {
+ User user = new User();
+ user.setUserId(userId);
+ user.setUserName("name");
+ return user;
+ }
+
+ @Override
+ @ShenyuBrpcClient(path = "/userMap")
+ public Map<Long, User> userMap(final Long userId) {
+ User user = new User();
+ user.setUserId(2L);
+ user.setUserName("u2");
+ user.setBalance(1000.21d);
+ List<String> tags2 = new LinkedList<>();
+ tags2.add("fgh");
+ tags2.add("123123");
+ user.setTags(tags2);
+ List<ExtInfo> extInfos2 = new LinkedList<>();
+ ExtInfo extInfo2 = new ExtInfo("hobby", "learn");
+ extInfos2.add(extInfo2);
+ user.setExtInfos(extInfos2);
+ user.setMap(Collections.singletonMap("Key1", new Address("Beijing")));
+
+ return Collections.singletonMap(2L, user);
+ }
+
+ @Override
+ @ShenyuBrpcClient("/connect")
+ public void connect() {
+ LOG.info("Connect Success");
+ }
+}
diff --git a/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-service/src/main/resources/application.yml b/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-service/src/main/resources/application.yml
new file mode 100644
index 000000000..f3a2dfa39
--- /dev/null
+++ b/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-service/src/main/resources/application.yml
@@ -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.
+#
+server:
+ port: 8011
+ address: 0.0.0.0
+ servlet:
+ context-path: /
+spring:
+ main:
+ allow-bean-definition-overriding: true
+ application:
+ name: brpc-exmaples
+
+shenyu:
+ register:
+ registerType: http #zookeeper #etcd #nacos #consul
+ serverLists: http://localhost:9095 #localhost:2181 #http://localhost:2379 #localhost:8848
+ props:
+ username: admin
+ password: 123456
+ client:
+ brpc:
+ props:
+ contextPath: /brpc
+ ipAndPort: brpc
+ appName: brpc
+ port: 8005
+ host: 127.0.0.1
+
+# starlight
+starlight:
+ server:
+ enable: true
+ port: 8005
diff --git a/shenyu-plugin/shenyu-plugin-brpc/src/main/java/org/apache/shenyu/plugin/brpc/proxy/BrpcProxyService.java b/shenyu-plugin/shenyu-plugin-brpc/src/main/java/org/apache/shenyu/plugin/brpc/proxy/BrpcProxyService.java
index 2c6bdef40..e05ddaf0e 100644
--- a/shenyu-plugin/shenyu-plugin-brpc/src/main/java/org/apache/shenyu/plugin/brpc/proxy/BrpcProxyService.java
+++ b/shenyu-plugin/shenyu-plugin-brpc/src/main/java/org/apache/shenyu/plugin/brpc/proxy/BrpcProxyService.java
@@ -93,14 +93,14 @@ public class BrpcProxyService {
})).onErrorMap(ShenyuException::new);
}
- private Map<String, String> getValue(final MetaData metaData, final Object[] params) {
+ private Object getValue(final MetaData metaData, final Object[] params) {
try {
AsyncGenericService service = ApplicationConfigCache.getInstance().get(metaData.getPath());
if (Objects.isNull(service)) {
ApplicationConfigCache.getInstance().invalidate(metaData.getPath());
service = ApplicationConfigCache.getInstance().initService(metaData);
}
- Map<String, String> result = (Map<String, String>) service.$invokeFuture(metaData.getMethodName(), params).get();
+ Object result = service.$invokeFuture(metaData.getMethodName(), params).get();
return result;
} catch (Exception e) {
LOG.error("Exception caught in BrpcProxyService#genericInvoker.", e);