kplclientgo

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

README

kplclientgo

A go client library for kplserver

If ErrPort is set, this library can be used to retrieve any message that kplserver may fail to send to kinesis. You can set a callback function ErrHandler that will be invoked for every message. See the example usage below on how to set these vaiables.

Usage
package main

import (
	"log"
	"github.com/turnerlabs/kplclientgo"
)

func main() {

	//create a client
	kpl := kplclientgo.NewKPLClient("127.0.0.1", "3000")

	// Optionally handle the failed messages
	kpl.ErrPort = "3000"
	kpl.ErrHost = "127.0.0.1"
	
	kpl.ErrHandler = func(data string) {
		log.Print("Could not send the message to kinesis", data)
	}

	//start it up
	err := kpl.Start()
	if err != nil {
		panic(err)
	}

	//send a record
	err = kpl.PutRecord("some data")
	if err != nil {
		panic(err)
	}
}
development

Requires:

  • Go 1.13
  • docker-compose

To run tests

AWS_PROFILE=my-profile KINESIS_STREAM=my-stream ERROR_SOCKET_PORT=3001 go test

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Read added in v0.1.1

func Read(conn net.Conn) (string, error)

Types

type KPLClient

type KPLClient struct {
	Host string
	Port string
	// ErrPort is the optional field, which is provided, will cause a server to start and
	// on this port and retrieve any error.
	// Provide ErrHandler if ErrPort is set.
	ErrPort       string
	ErrHost       string
	ErrHandler    func(data string)
	Started       bool
	Socket        net.Conn
	SocketChannel chan string
}

KPLClient represents a client to the KPL Server

func NewKPLClient

func NewKPLClient(host, port string) *KPLClient

NewKPLClient returns a new KPLClient

func (*KPLClient) PutRecord

func (c *KPLClient) PutRecord(record string) error

PutRecord sends a data record to the KPL server

func (*KPLClient) Start

func (c *KPLClient) Start() error

Start starts up a communication channel to the server

func (*KPLClient) Stop

func (c *KPLClient) Stop()

Stop shutsdown the communication channel to the server

Jump to

Keyboard shortcuts

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