Today is the last day to experience the Soul gateway proxy service, currently also supports Tars proxy Tencent

First, preparation

1. Start ZK

With the experience of acting for SpringCloud, in fact, the company mainly uses the Spring family bucket framework to build the micro service. It can run quickly after using SpringCloud, but SOFA is not used, let me see see.

Looking at the SOFA service example code configuration file in soul-Example, SOFA is ZooKeeper to rely on a registry like Dubbo and SpringCloud

Com: alipay: sofa: RPC: registry - address: zookeeper: / / 127.0.0.1:2181 bolt - port: 8888Copy the code

2. Open SOFA plug-in

With previous experience, the plugin should be opened in two places, one is in the soul-admin background; The other is that the Soul-Bootstrap gateway service relies on the SOFA plug-in.

Perform the curl http://localhost:9195/sofa/findById\? Id \=1 returns null.

Here comes another place to mention pr ^_^!! When the soul-Bootstrap gateway service does not rely on the SOFA plugin, no error is reported and no error log is printed. The interface returns nothing. This is not scientific and the experience is not good.

SoulWebHandler#execute = SoulWebHandler#execute = SoulWebHandler#execute = SoulWebHandler#execute = SoulWebHandler#execute = soulwebhandler

The gateway does not have SOFA plug-in, but the access request can be processed, where is it processed?

  1. In the first plug-in, GlobalPlugin, metadata is written to the backend management system in the context of generating soulContext based on the request path.

  1. The soulContext has tagged the request with rpcType = SOFA, and Divide has tagged the request with rpcType = HTTP.

DividePlugin# skip method

 @Override
    public Boolean skip(final ServerWebExchange exchange) {
        final SoulContext soulContext = exchange.getAttribute(Constants.CONTEXT);
        return! Objects.equals(Objects.requireNonNull(soulContext).getRpcType(), RpcTypeEnum.HTTP.getName()); }Copy the code

The SofaPlugin plugin is not loaded in, so the request traffic is processed by the plugin, and nothing is done.

Experience the SOFA

Console opens SOFA plugin, adds SOFA plugin dependencies to soul-bootstrap, and restarts. See the official document: dromara.org/zh-cn/docs/…

Basically, zK client, SOFA plugin, SOFA official dependency, zK client prior to experience Dubbo has been added.

<dependency> <groupId>org.dromara</groupId> <artifactId>soul-spring-boot-starter-plugin-sofa</artifactId> <version>${last.version}</version> </dependency> <dependency> <groupId>com.alipay.sofa</groupId> < artifactId > sofa xml-rpc -all < / artifactId > < version > 5.7.6 < / version > < / dependency > < the dependency > < the groupId > org. Apache. Curator < / groupId > < artifactId > curator - client < / artifactId > < version > 4.0.1 < / version > < / dependency > < the dependency > < groupId > org. Apache. Curator < / groupId > < artifactId > curator - framework < / artifactId > < version > 4.0.1 < / version > </dependency> <dependency> <groupId>org.apache.curator</groupId> <artifactId>curator-recipes</artifactId> The < version > 4.0.1 < / version > < / dependency >Copy the code

Start the soul – the sofa example in example, execute the curl http://localhost:9195/sofa/findAll results {” code “: 200, the” message “:” Access to success!” ,”data”:{“name”:”hello world Soul Sofa , findAll”,”id”:”278174738″}}