pubsub

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2020 License: MIT Imports: 0 Imported by: 0

README

package pubsub

package pubsub provides a set of interfaces for publishing and subscribing events with pubsub interface.

Usage

Basic

import (
	"github.com/mo-work/mo-kit/pubsub/kafka"
	"github.com/mo-work/mo-kit/pubsub"
)

func main() {
  kp, err := kafka.NewProducer(kafkaBrokers, "mo-test-producer")
	if err != nil {
		fmt.Println("Error connecting to Kafka")
		panic(err)
	}

	userID := "foo_bar_user_id_xxxx"

	kp.SendEvent(&pubsub.Event{
		Topic: "foo,
		Key:   "bar",
		Properties: pubsub.Properties{
			UserID:    userID,
			EventType: "foo_bar",
		},
	})
}


With new optional error handling callback

import (
	"log"

	"github.com/mo-work/mo-kit/pubsub/kafka"
	"github.com/mo-work/mo-kit/pubsub"
)

func errorHandler(err error) {
	log.Print(err)
}

func main() {

	kc, err := kafka.NewConsumer(some, required, parameters, errorHandler)
	if err != nil {
		log.Print("Error configuring Kafka consumer")
		return
	}

	// ...
}


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Topic      string     `json:"topic"`
	Key        string     `json:"key"`
	Properties Properties `json:"properties"`
}

Event describes a Mo common event structure

type Producer

type Producer interface {
	SendMessage(string, string, string) error
	SendEvent(*Event) error
}

Producer provides an interface to publish events

type Properties

type Properties struct {
	Version         int                    `json:"version"`
	UserID          string                 `validate:"required" json:"user_id"`
	SessionID       int64                  `json:"session_id,omitempty"`
	EventType       string                 `validate:"required" json:"event_type"`
	Time            int64                  `json:"time"`
	Platform        string                 `json:"platform"`
	EventProperties map[string]interface{} `json:"event_properties,omitempty"`
	UserProperties  map[string]interface{} `json:"user_properties,omitempty"`
}

Properties describes basic attributes of Mo event object

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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