Categorygithub.com/manhdaovan/myrpc
modulepackage
0.0.0-20190625135555-3ac6147e4b93
Repository: https://github.com/manhdaovan/myrpc.git
Documentation: pkg.go.dev

# README

Write your own RPC framework, why not?

https://speakerdeck.com/manhdaovan/write-your-own-async-rpc-framework

myRPC

My own asynchronous RPC framework that support message in ANY format.

  • Default message format is JSON. Support protobuf message without any touch.
  • Default message transporter is AWS SQS.

Usage

  • If you use message in JSON format:
    • Define message struct as in example/message/free_message.go
    • Define service that having RPC interfaces and implementation as in example/service/free_service.go
      • The service and methods descriptions part could be auto generate after having message struct and RPC interfaces
    • Register it on server side as in example/cmd/server/main.go
  • If you use message in Protobuf format:
    • Generate message struct and RPC interfaces using protoc as in example/Makefile
    • Define service and method descriptions as in example/service/grpc_service_extend.go, and implement RPC interfaces
      • The service and methods descriptions part could be auto generate after having message struct and RPC interfaces
    • Register it on server side as in example/cmd/server/main.go
  • Or you can create your own message format and use it, by implement your own message encoder/decoder
    • Other steps are similar to above steps

Example

See /example directory source code for more details

What you can custom

  • Message encode/decode function
  • Message sender/receiver/deleter

TODO

  • Auto generate Service code in case of protobuf message
  • Unit test :D

Future work

  • Support synchronous RPC

# Functions

DeleterConfFromYamlFile returns DeleterConf from given yaml conf file.
JSONToRPCMsg converts json in string format to RPCMessage.
NewRPCClient returns new client from config.
NewRPCServer return new RPC server.
NewSQSDeleter returns a SQS client using for deleting message.
NewSQSReceiver returns a SQS client using for receiving message.
NewSQSSender returns a SQS client using for sending messages.
ReceiverConfFromYamlFile returns ReceiverConf from given yaml conf file.
SenderConfFromYamlFile returns DeleterConf from given yaml conf file.

# Variables

DefaultQuitSigs are signals that server listen by default.

# Structs

DeleterConf contains info about config of message receiver.
MethodDescription contains method name and its handler.
QueueConf contains info about message queue.
ReceiverConf contains info about config of message receiver.
RPCClient represents client of this RPC.
RPCMessage represents message of this RPC.
RPCServer is struct of this RPC server.
SenderConf contains info about config of message sender.
ServiceDescription contains all methods and their descriptions.

# Interfaces

MessageDeleter is the interface to delete message from message service.
MessageReceiver is the interface to receive message from message service.
MessageSender is the interface to send a message service.

# Type aliases

MethodDecodeFnc decodes data to output struct for current method.
MethodHandler is a abstract handler of a method.
MethodName is a key for map of methods in a service.
PayloadDecodeFnc decodes bytes into output struct.
PayloadEncodeFnc encodes data to bytes.
ServiceName is a key for map of services in a RPC server.