# README
pushpull
Package proto contains protocol buffer code to populate
Table of Content
HOW TO USE
Client
Use in your Go project
Push
package main
import (
"context"
"fmt"
"os"
"time"
"google.golang.org/grpc"
"google.golang.org/grpc/keepalive"
"github.com/vardius/pushpull/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 := proto.NewPushPullClient(conn)
client.Push(ctx, &proto.PushRequest{
Topic: "my-topic",
Payload: []byte("Hello you!"),
})
}
Pull
package main
import (
"context"
"fmt"
"os"
"time"
"google.golang.org/grpc"
"google.golang.org/grpc/keepalive"
"github.com/vardius/pushpull/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 := proto.NewPushPullClient(conn)
stream, err := client.Pull(ctx, &proto.PullRequest{
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())
}
}
Protocol Buffers
Generating client and server code
To generate the gRPC client and server interfaces from pushpull.proto
service definition.
Use the protocol buffer compiler protoc with a special gRPC Go plugin. For more info read
From this directory run:
$ make build
Running this command generates the following files in this directory:
pushpull.pb.go
This contains:
All the protocol buffer code to populate, serialize, and retrieve our request and response message types An interface type (or stub) for clients to call with the methods defined in the services. An interface type for servers to implement, also with the methods defined in the services.
# Functions
No description provided by the author
No description provided by the author
# Structs
PullRequest is passed when listing for new event in queue.
PullResponse object.
PushRequest is passed when pushing to the queue.
UnimplementedPushPullServer can be embedded to have forward compatible implementations.
# Interfaces
No description provided by the author
No description provided by the author
PushPullClient is the client API for PushPull service.
PushPullServer is the server API for PushPull service.