proto

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2020 License: MIT Imports: 8 Imported by: 4

README

pushpull

license

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.

Documentation

Overview

Package proto contains protocol buffers for gRPC pushpull event ingestion and delivery system.

Using gRPC client

## Push example:

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.PublishRequest{
		Topic:   "my-topic",
		Payload: []byte("Hello you!"),
	})
}

## Pull example:

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.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())
	}
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterPushPullServer

func RegisterPushPullServer(s *grpc.Server, srv PushPullServer)

Types

type PullRequest

type PullRequest struct {
	Topic                string   `protobuf:"bytes,1,opt,name=topic,proto3" json:"topic,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

PullRequest is passed when listing for new event in queue

func (*PullRequest) Descriptor

func (*PullRequest) Descriptor() ([]byte, []int)

func (*PullRequest) GetTopic

func (m *PullRequest) GetTopic() string

func (*PullRequest) ProtoMessage

func (*PullRequest) ProtoMessage()

func (*PullRequest) Reset

func (m *PullRequest) Reset()

func (*PullRequest) String

func (m *PullRequest) String() string

func (*PullRequest) XXX_DiscardUnknown

func (m *PullRequest) XXX_DiscardUnknown()

func (*PullRequest) XXX_Marshal

func (m *PullRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*PullRequest) XXX_Merge

func (m *PullRequest) XXX_Merge(src proto.Message)

func (*PullRequest) XXX_Size

func (m *PullRequest) XXX_Size() int

func (*PullRequest) XXX_Unmarshal

func (m *PullRequest) XXX_Unmarshal(b []byte) error

type PullResponse

type PullResponse struct {
	Payload              []byte   `protobuf:"bytes,1,opt,name=payload,proto3" json:"payload,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

PullResponse object

func (*PullResponse) Descriptor

func (*PullResponse) Descriptor() ([]byte, []int)

func (*PullResponse) GetPayload

func (m *PullResponse) GetPayload() []byte

func (*PullResponse) ProtoMessage

func (*PullResponse) ProtoMessage()

func (*PullResponse) Reset

func (m *PullResponse) Reset()

func (*PullResponse) String

func (m *PullResponse) String() string

func (*PullResponse) XXX_DiscardUnknown

func (m *PullResponse) XXX_DiscardUnknown()

func (*PullResponse) XXX_Marshal

func (m *PullResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*PullResponse) XXX_Merge

func (m *PullResponse) XXX_Merge(src proto.Message)

func (*PullResponse) XXX_Size

func (m *PullResponse) XXX_Size() int

func (*PullResponse) XXX_Unmarshal

func (m *PullResponse) XXX_Unmarshal(b []byte) error

type PushPullClient

type PushPullClient interface {
	Push(ctx context.Context, in *PushRequest, opts ...grpc.CallOption) (*empty.Empty, error)
	Pull(ctx context.Context, in *PullRequest, opts ...grpc.CallOption) (PushPull_PullClient, error)
}

PushPullClient is the client API for PushPull service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.

func NewPushPullClient

func NewPushPullClient(cc grpc.ClientConnInterface) PushPullClient

type PushPullServer

type PushPullServer interface {
	Push(context.Context, *PushRequest) (*empty.Empty, error)
	Pull(*PullRequest, PushPull_PullServer) error
}

PushPullServer is the server API for PushPull service.

type PushPull_PullClient

type PushPull_PullClient interface {
	Recv() (*PullResponse, error)
	grpc.ClientStream
}

type PushPull_PullServer

type PushPull_PullServer interface {
	Send(*PullResponse) error
	grpc.ServerStream
}

type PushRequest

type PushRequest struct {
	Topic                string   `protobuf:"bytes,1,opt,name=topic,proto3" json:"topic,omitempty"`
	Payload              []byte   `protobuf:"bytes,2,opt,name=payload,proto3" json:"payload,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

PushRequest is passed when pushing to the queue

func (*PushRequest) Descriptor

func (*PushRequest) Descriptor() ([]byte, []int)

func (*PushRequest) GetPayload

func (m *PushRequest) GetPayload() []byte

func (*PushRequest) GetTopic

func (m *PushRequest) GetTopic() string

func (*PushRequest) ProtoMessage

func (*PushRequest) ProtoMessage()

func (*PushRequest) Reset

func (m *PushRequest) Reset()

func (*PushRequest) String

func (m *PushRequest) String() string

func (*PushRequest) XXX_DiscardUnknown

func (m *PushRequest) XXX_DiscardUnknown()

func (*PushRequest) XXX_Marshal

func (m *PushRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*PushRequest) XXX_Merge

func (m *PushRequest) XXX_Merge(src proto.Message)

func (*PushRequest) XXX_Size

func (m *PushRequest) XXX_Size() int

func (*PushRequest) XXX_Unmarshal

func (m *PushRequest) XXX_Unmarshal(b []byte) error

type UnimplementedPushPullServer

type UnimplementedPushPullServer struct {
}

UnimplementedPushPullServer can be embedded to have forward compatible implementations.

func (*UnimplementedPushPullServer) Pull

func (*UnimplementedPushPullServer) Push

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL