Brpc Proxy
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 Brpc plugin in gateway#
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>- Restart your gateway service.
Brpc service access gateway#
Please refer to: shenyu-examples-brpc
- In the microservice built by
Brpc, add the following dependencies:
<dependency> <groupId>org.apache.shenyu</groupId> <artifactId>shenyu-spring-boot-starter-client-brpc</artifactId> <version>${shenyu.version}</version> </dependency>- Add the following configuration to the
application.yamlconfiguration 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: 8005 host: 127.0.0.1
# starlightstarlight: server: enable: true port: 8005- Add
@ShenyuBrpcClientannotation to the method ofBrpcservice 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:
@ShenyuBrpcServicepublic class BrpcDemoServiceImpl implements BrpcDemoService { @Override @ShenyuBrpcClient("/connect") public void connect() { LOG.info("Connect Success"); }}User Request#
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 .