Multi-terminal front-end system

Project source code address

In our work, we often encounter the development of different front-end systems for APP, H5, and Outside API, often the same business logic needs to develop three forms of API, why do we need to do this? They are just message formats, encryption and decryption requirements, different session formats, and so on.

Therefore, this multi-terminal front-end system is developed to encapsulate the common processes in the above scenarios using microkernel mode and open part of them with interfaces.

The open source frameworks used are as follows: SpringBoot for integration, Netty for web server, Hystrix for fuse, Redis for distributed session, and JMX for dynamic configuration. The framework does the bare minimum, leaving the rest to its future users.

By the way: There are two roles for consumers, secondary developers of the framework and concrete business logic developers.

Secondary developers need to focus on the general process of open interface, they are: net. Multi. Terminal. BFF. Core

Specific business logic developers need to be concerned with the following path, they are: net. Multi. Terminal. BFF. Service, net. Multi. Terminal. BFF) model

The.net. Multi. Terminal. BFF. The model is a business model, they are: request, response, the session context and the client

The first three are shallow and obvious, but what is the client context? We will define different terminals as different clients, and give it a permanent ID, it USES the personalized implementation class is written in multi – terminal – BFF/SRC/main/resources/client – setting. The json

[
  {
    "clientId": "1",
    "serializerName":"AppMsgSerializer",
    "apiCodecName":"EmptyApiCodec",
    "sessionInjectorName":"AppSessionInjector",
    "rspContentType":"text/plain;charset=UTF-8"
  },
  {
    "clientId": "2",
    "serializerName":"FormJsonMsgSerializer",
    "apiCodecName":"EmptyApiCodec",
    "sessionInjectorName":"WebSessionInjector",
    "rspContentType":"application/json;charset=UTF-8"
  },
  {
    "clientId": "3",
    "serializerName":"DoubleJsonMsgSerializer",
    "apiCodecName":"EmptyApiCodec",
    "sessionInjectorName":"WebSessionInjector",
    "rspContentType":"application/json;charset=UTF-8"
  }
]

Content is as follows, it is very easy to understand, as long as you carefully look at the net. This class. Multi terminal. BFF. Web. HttpApiHanler yes, it describes the whole request, processing, the process.

How does it work?

Operating environment:

Docker runtime environment or installed Redis database JDK8 compile runtime environment Maven compile environment
  1. The deployment environment

    Download the source code

    git clone https://github.com/mudiyouyou/multi-terminal-bff.git

    Docker installs and runs Redis. Locally installed Redis please ignore

    docker pull redis

    docker run -d -p 6379:6379 -v /Users/apple/apps/docker/redis:/data --name redis redis

    Note: Modify the path after -v to the native path
  2. Install dependencies

    cd multi-terminal-bff

    mvn compile -Dmaven.test.skip=true
  3. There is a Redis configuration in application-dev.properties if your environment uses a different IP and PORT
  4. To run the program

    mvn exec:java -Dexec.mainClass=net.multi.terminal.bff.MutliTerminalBff
  5. The test interface

    curl -X POST http://localhost:8082/api/clientId/2/apiName/Count -d 'a=1'

    return

    {" count ": 1," respCode ":" 00000 ", "respDesc" : "success"}

    Note: The default port is 8082. The default internally provides a counter business interface for testing, using sessions (REDIS) to store the current counter value. Json config file client-setting.json set clientId:2 using Form submission to return JSON, empty encryption and decryption implementation, the use of cookie to save the Form of SessionID

How do I develop an interface

  1. In.net. Multi. Terminal. BFF. Service under the new interface module, such as: test
  2. In the package.net. Multi. Terminal. BFF. Service. Test the new interface classes, such as: TestService
  3. The code structure is as follows:
Public class TestService {@IgnoreAuth} public class TestService {@IgnoreAuth} public class TestService {@IgnoreAuth} public class TestService {@IgnoreAuth} Public ApiRsp test(ApiReq) {return MsgCode.e_00000.getRsp ();}} public ApiRsp test(ApiReq); // You can use the MsgCode message code class to generate APIRSP, or you can use the MsgCode message code class to generate APIRSP.}}

More details are in the code. If you have any new extensions on this release, please contribute.