https://github.com/natata/linkage
linkage is a job stream service based on server streaming gRPC.
https://github.com/natata/linkage
go golang grpc message-queue streaming
Last synced: 9 months ago
JSON representation
linkage is a job stream service based on server streaming gRPC.
- Host: GitHub
- URL: https://github.com/natata/linkage
- Owner: Natata
- Created: 2018-06-14T16:20:40.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-08-20T10:17:12.000Z (almost 8 years ago)
- Last Synced: 2025-05-23T00:35:09.154Z (about 1 year ago)
- Topics: go, golang, grpc, message-queue, streaming
- Language: Go
- Homepage:
- Size: 2.76 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Linkage
Linkage is a job stream service based on server streaming gRPC.
One incoming stream and multiple outcome stream.
# Install
go get github.com/Natata/linkage
# How to use
1. Define yourself engine
Define an engine which implement engine interface.
Engine interface defined in engine.go, look like below:
```
type Engine interface {
// Start starts the engine, jobs would send to the engine throught the inbound channel
Start(inbound <-chan *Job) error
// Register register an output destination, results generated by engine would send to the outbound channel
// the signal is used to notify down stream or service is closing
Register(sig chan Signal) (<-chan *Job, error)
}
```
2. Initial linkage service
Iniital linkage with
- address: listen incoming message
- engine: engine implement
- grpc server options: if this service need credentials or other grpc server supported options
- codeAssert: except credential, you can use codeAssert to tell client if it the right service connected
- dial info: infomation of remote service this service will connect. Leave nil if this service not connect to any service.
- waiting function: the waiting mechanism to retry to ask job frmo remote service.
```
addr := ":8081"
engine := &MyEngine{}
codeAssert := func(code linkage.Code) bool {
return true
}
di := &linkage.DialInfo{
ConnCode: "yo",
Addr: ":8080",
Opts: []grpc.DialOption{grpc.WithInsecure()},
MaxAttempt: 2,
}
srv, err := linkage.InitLinkage(addr, engine, []grpc.ServerOption{}, codeAssert, di, nil)
```
3. Run it
```
err := srv.Run()
```
example/ have full examples.
run ```go run example/rome/main.go``` and ```go run example/road/main.go``` in order to see what happened :)