Vardius - pubsub

pubsub - gRPC message-oriented middleware on top of message-bus, event ingestion and delivery system.
Table of Content
ABOUT
Contributors:
Want to contribute ? Feel free to send pull requests!
Have problems, bugs, feature ideas?
We are using the github issue tracker to manage them.
HOW TO USE
- GoDoc
- Examples
Docker
How to use this image
Starting a pubsub instance:
docker run --name my-pubsub -e QUEUE_BUFFER_SIZE=100 -d vardius/pubsub:tag
Environment Variables
HOST
This is optional variable, sets gRPC server host value. Default to 0.0.0.0
PORT
This is optional variable, sets gRPC server port value. Default to 9090
QUEUE_BUFFER_SIZE
This is optional variable, sets message bus queue buffer size. Default to number of CPUs`
Makefile
version Show version
docker-build Build given container. Example: `make docker-build`
docker-run Run container on given port. Example: `make docker-run PORT=3000`
docker-stop Stop docker container. Example: `make docker-stop`
docker-rm Stop and then remove docker container. Example: `make docker-rm`
docker-publish Docker publish. Example: `make docker-publish REGISTRY=https://your-registry.com`
docker-tag Tag current container. Example: `make docker-tag REGISTRY=https://your-registry.com`
docker-release Docker release - build, tag and push the container. Example: `make docker-release REGISTRY=https://your-registry.com`
Client
Use in your Go project
Publish
package main
import (
"context"
"fmt"
"os"
"time"
"google.golang.org/grpc"
"google.golang.org/grpc/keepalive"
pubsub_proto "github.com/vardius/pubsub/proto"
)
func main() {
host:= "0.0.0.0"
port:= 9090
ctx := context.Background()
opts := []grpc.DialOption{
grpc.WithInsecure(),
grpc.WithKeepaliveParams(keepalive.ClientParameters{
Time: 10 * time.Second, // send pings every 10 seconds if there is no activity
Timeout: 20 * time.Second, // wait 20 second for ping ack before considering the connection dead
PermitWithoutStream: true, // send pings even without active streams
}),
}
conn, err := grpc.DialContext(ctx, fmt.Sprintf("%s:%d", host, port), opts...)
if err != nil {
os.Exit(1)
}
defer conn.Close()
client := pubsub_proto.NewMessageBusClient(pubsubConn)
client.Publish(ctx, &pubsub_proto.PublishRequest{
Topic: "my-topic",
Payload: []byte("Hello you!"),
})
}
Subscribe
package main
import (
"context"
"fmt"
"os"
"time"
"google.golang.org/grpc"
"google.golang.org/grpc/keepalive"
pubsub_proto "github.com/vardius/pubsub/proto"
)
func main() {
host:= "0.0.0.0"
port:= 9090
ctx := context.Background()
opts := []grpc.DialOption{
grpc.WithInsecure(),
grpc.WithKeepaliveParams(keepalive.ClientParameters{
Time: 10 * time.Second, // send pings every 10 seconds if there is no activity
Timeout: 20 * time.Second, // wait 20 second for ping ack before considering the connection dead
PermitWithoutStream: true, // send pings even without active streams
}),
}
conn, err := grpc.DialContext(ctx, fmt.Sprintf("%s:%d", host, port), opts...)
if err != nil {
os.Exit(1)
}
defer conn.Close()
client := pubsub_proto.NewMessageBusClient(pubsubConn)
stream, err := client.Subscribe(ctx, &pubsub_proto.SubscribeRequest{
Topic: "my-topic",
})
if err != nil {
os.Exit(1)
}
for {
resp, err := stream.Recv()
if err != nil {
os.Exit(1) // stream closed or error
}
fmt.Println(resp.GetPayload())
}
}
License
This package is released under the MIT license. See the complete license in the package:
LICENSE