Skip to content

gojekfarm/ziggurat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

author
github-actions
May 19, 2021
b44bb1e · May 19, 2021
Mar 29, 2021
May 19, 2021
May 2, 2021
May 14, 2021
Apr 21, 2021
Mar 30, 2021
May 19, 2021
Apr 18, 2021
Nov 6, 2020
May 19, 2021
Feb 23, 2021
May 19, 2021
Mar 29, 2021
Apr 9, 2021
Apr 22, 2021
Oct 22, 2020
Nov 3, 2020
Apr 18, 2021
Apr 24, 2021
May 19, 2021
May 19, 2021
Apr 18, 2021
Apr 13, 2021
Oct 2, 2020
Mar 11, 2021
Nov 6, 2020
Apr 13, 2021
Apr 13, 2021
May 19, 2021
Apr 24, 2021

Repository files navigation

Ziggurat Golang

Stream Processing made easy

Install the ziggurat CLI

go get -v -u github.com/gojekfarm/ziggurat/cmd/...
go install github.com/gojekfarm/ziggurat/cmd/...                                                                                                                                                     

How to use

create a new app using the new command

ziggurat new <app_name>

Main file

package main

import (
	"context"

	"github.com/gojekfarm/ziggurat/mw/event"

	"github.com/gojekfarm/ziggurat/mw/prometheus"
	"github.com/gojekfarm/ziggurat/mw/statsd"

	"github.com/gojekfarm/ziggurat"
	"github.com/gojekfarm/ziggurat/kafka"
	"github.com/gojekfarm/ziggurat/logger"
	"github.com/gojekfarm/ziggurat/router"
)

func main() {
	var zig ziggurat.Ziggurat
	jsonLogger := logger.NewJSONLogger(logger.LevelInfo)
	ctx := context.Background()

	kafkaStreams := kafka.Streams{
		StreamConfig: kafka.StreamConfig{
			{
				BootstrapServers: "localhost:9092",
				OriginTopics:     "plain-text-log",
				ConsumerGroupID:  "plain_text_consumer",
				ConsumerCount:    1,
				RouteGroup:       "plain-text-log",
			},
			{
				BootstrapServers: "localhost:9092",
				OriginTopics:     "json-log",
				ConsumerGroupID:  "json_consumer",
				ConsumerCount:    1,
				RouteGroup:       "json-log",
			},
		},
		Logger: jsonLogger,
	}

	r := router.New()

	r.HandleFunc("plain-text-log", func(ctx context.Context, event *ziggurat.Event) error {
		return nil
	})

	r.HandleFunc("json-log", func(ctx context.Context, event *ziggurat.Event) error {
		return ziggurat.Retry
	})

	handler := r.Compose(event.Logger(jsonLogger))

	if runErr := zig.Run(ctx, &kafkaStreams, handler); runErr != nil {
		jsonLogger.Error("could not start streams", runErr)
	}

}

Concepts

  • There are 2 main interfaces that your structs can implement to plug into the Ziggurat library

Streamer interface

package ziggurat

import "context"

type Streamer interface {
	Stream(ctx context.Context, handler Handler) error
}

// Any type can implement the Streamer interface to stream data from any source

Handler interface

package ziggurat

import "context"

type Handler interface {
	Handle(ctx context.Context, event *Event) error
}

// The Handler interface is very similar to the http.Handler interface
// The default router shipped with Ziggurat also implements the Handler interface