This document is intended to help the Brpc
service access the Apache ShenYu
gateway. The Apache ShenYu
gateway uses the Brpc
plugin to handle Brpc
service.
Before the connection, start shenyu-admin
correctly, start Brpc
plugin, and add related dependencies on the gateway and Brpc
application client. Refer to the previous Quick start with Brpc .
For details about client access configuration, see Application Client Access Config .
For details about data synchronization configurations, see Data Synchronization Config .
Add the following dependencies to the gateway's pom.xml
file:
<!-- apache shenyu brpc plugin --> <dependency> <groupId>org.apache.shenyu</groupId> <artifactId>shenyu-spring-boot-starter-plugin-brpc</artifactId> <version>${project.version}</version> </dependency>
Please refer to: shenyu-examples-brpc
Brpc
, add the following dependencies:<dependency> <groupId>org.apache.shenyu</groupId> <artifactId>shenyu-spring-boot-starter-client-brpc</artifactId> <version>${shenyu.version}</version> </dependency>
application.yaml
configuration file: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: ${starlight.server.port} # starlight starlight: server: enable: true port: 8005
@ShenyuBrpcClient
annotation to the method of Brpc
service interface implementation class, start your service provider, after successful registration, go to PluginList -> rpc proxy -> brpc in the background management system, you will see automatic registration of selectors and rules information.Example:
@ShenyuBrpcService public class BrpcDemoServiceImpl implements BrpcDemoService { @Override @ShenyuBrpcClient("/connect") public void connect() { LOG.info("Connect Success"); } }
You can request your Brpc
service by Http. The Apache ShenYu
gateway needs to have a route prefix which is the contextPath
configured by the access gateway. For example: http://localhost:9195/brpc/connect
.