Gome high-performance matching engine microservice

Gome high-performance matching engine microservice

  • Use Golang for calculations, gRPC for services, ProtoBuf for data exchange, RabbitMQ for queues, and Redis for caches to achieve high-performance matching engine microservices

rely

Quick start

  1. Use docker to deploy the running environment with one click , enter the gome container,docker exec -it gome bash

  2. Enter the api interface definition directory and generate the gRPC interface definition file: cd /go/src/gome/api && protoc --go_out=plugins=grpc:. *.proto

  3. Enter the project directory, copy and modify the configuration: cd /go/src/gome && copy config.example.yaml config.yaml

  4. Start the gRPC server:go run main.go

  5. Start the script to match the consumption of RabbitMQ queue:, go run match.go symbolsymbol is the name of the transaction pair, such as btc2usdt, symbol should be consistent with the call of the client

  6. Consumer startup script match results RabbitMQ queue: go run match_notice.go symbol.

Description

  • Gome directory description:

    api, RPC interface definition directory, using ProtoBuf 3 version

    engine, the matching engine realizes the logical catalog

    grpc, gRPC service script

    redis, redis client

    utils, tool script directory

    main.go entry file

    match.go matchmaking script

    match_notice.go match result consumption script

    test.go test script, the command is as follows:

      1. 下单:`go run test.go doOrder`
      2. 撤单:`go run test.go delOrder`
      3. 获取交易对深度:`go run test.go getDepth symbol transaction`
      4. 查看命令帮助:`go run test.go help`
    
  • Gome will use the symbol name as the order queue, the matching engine will consume this queue, and the matching result will be pushed to notice:+symbol as the name queue, such as notice:btc2usdt

  • At present, only the data is printed when consuming the transaction result queue, and there is no other function. The user can consume this queue by himself to implement subsequent logic, such as updating the database, notifying the user, etc., gome will add the address push function according to the configuration in the future, so that the user Only need to configure the receiving address to receive the results and then process

  • This project is based on my previous PHP project, replacing the queue with RabbitMQ, Redis only serves as a cache, and then uses Golang and gRPC to achieve microservices

  • gome concrete realization of ideas and data structure design can be viewed based on Laravel of matching services project

  • This project does not need to rely on other environments. After running the environment with docker, other projects can be connected and called, such as:

    • PHP client , composer installation, out of the box
  • In the OrderRequest of the api, uuid (user ID) and oid (order ID) should be unique in the system. In other words, the two should not be duplicated in the system. I defined the string type, which is convenient for the primary key to be non-incremental. Database usage

to sum up

  1. If you use the docker environment, you need to enter the gome container to perform the corresponding operation, or use Supervisor to automatically start the relevant script when the container is started

  2. Enter the rabbitmq container,, docker exec -it rabbitmq bashview the existing queue:, rabbitmqctl list_queuesdelete the queue:rabbitmqctl delete_queue queuename

Guess you like

Origin blog.csdn.net/sting_bo/article/details/113762406