pst

package
v0.0.0-...-8886d92 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHandlers

func NewHandlers(r *Repository)

NewHandlers sets the repository for the handlers

func StartPubSubFakeServer

func StartPubSubFakeServer(port int) (*grpc.ClientConn, *pstest.Server, error)

StartPubSubFakeServer startup a fake server for pub sub

Types

type Message

type Message struct {
	ServiceName string    `json:"service_name"`
	Payload     string    `json:"payload"`
	Severity    string    `json:"severity"`
	Timestamp   time.Time `json:"timestamp"`
}

Message holds the message structure

type PubSubServer

type PubSubServer struct {
	Conn *grpc.ClientConn
}

PubSubServer Holds ClientConnection for pstest

type PublisherServiceConfig

type PublisherServiceConfig struct {
	Frequency time.Duration
	PerBatch  uint
}

PublisherServiceConfig holds the publisher configuration for service workers

type Repository

type Repository struct {
	App *config.AppConfig
}

Repository holds App config

var Repo *Repository

func NewRepo

func NewRepo(a *config.AppConfig) *Repository

NewRepo initialise and return Repository Type Which holds AppConfig

func (*Repository) CreateSubscription

func (repo *Repository) CreateSubscription(ctx context.Context, subID string, topicName string, c *pubsub.Client) (*pubsub.Subscription, error)

CreateSubscription creates a subscription for a given client on a topic

func (*Repository) CreateTopic

func (repo *Repository) CreateTopic(ctx context.Context, topic string, c *pubsub.Client) error

CreateTopic receives the message from pub sub

func (*Repository) GenerateARandomMessage

func (repo *Repository) GenerateARandomMessage(serviceNames []string) *Message

GenerateARandomMessage for the pub sub

func (*Repository) GenerateRandomMessages

func (repo *Repository) GenerateRandomMessages(n uint, serviceNames []string) []Message

GenerateRandomMessages for the pub sub it creates multiple messages as slice

func (*Repository) GenerateServicesPool

func (repo *Repository) GenerateServicesPool(n uint) []string

GenerateServicesPool generate some service name for this exercise This function generates "Service-name:1" "Service-name:2"...

func (*Repository) GetPayLoad

func (repo *Repository) GetPayLoad() string

GetPayLoad generates payload as a paragraph. Word count and Sentence count can be adjusted in env Do not set higher values, it will generate very long paragraphs. it can be problematic for SQL inserts and performance

func (*Repository) GetRandomServiceName

func (repo *Repository) GetRandomServiceName(s []string) string

GetRandomServiceName generates random service name for the message this function generates random string only

func (*Repository) GetRandomSeverity

func (repo *Repository) GetRandomSeverity(min, max int) Severity

GetRandomSeverity generates random severity between the range

func (*Repository) InitPubSubProcess

func (repo *Repository) InitPubSubProcess(publishers, serviceNamePoolSize uint, logs chan<- lmslogging.Log, w *sync.WaitGroup, serviceConfig PublisherServiceConfig)

InitPubSubProcess will initialise pub/sub Create a topic from env variable Initialise and run Publishers Fake services concurrently.

func (*Repository) NewPubSubClient

func (repo *Repository) NewPubSubClient(ctx context.Context, projectID string) (*pubsub.Client, error)

NewPubSubClient creates a new client connection for pub/sub

func (*Repository) PublishBulkMessage

func (repo *Repository) PublishBulkMessage(topic string, msg []Message, c *pubsub.Client, msgConfig PublisherServiceConfig) error

PublishBulkMessage publishes a message to given topic

func (*Repository) SeverityToString

func (repo *Repository) SeverityToString(s Severity) string

SeverityToString converts severity to string

type Severity

type Severity int
const (
	Debug Severity = iota
	Info
	Warn
	Error
	Fatal
)

Jump to

Keyboard shortcuts

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