Skip to content
/ cone Public

A generic event consumer with an http.Server-like interface.

Notifications You must be signed in to change notification settings

zapling/cone

Repository files navigation

cone 🗼

The goal of cone is to provide an easy to use event handler implementation that can support a multitude of event backends.


Table of contents


Usage

// Configure handlers
h := cone.NewHandlerMux()
h.HandleFunc("event.subject", func(r cone.Response, e *cone.Event) {
    _ = r.Ack()
})
h.HandleFunc("event.subject2", func(r cone.Response, e *cone.Event) {
    _ = r.Ack()
})

// Setup an event source
s := conetest.NewSource()

// Setup consumer with source and handler
c := cone.New(s, h)

// Start consumer. Processes events from the source and calls your handler.
c.ListenAndConsume()

Middleware

Middleware can be placed around a specific handler.

middleware := func(next cone.Handler) cone.Handler {
    return func(r cone.Response, e *cone.Event) {
        next.Serve(r, e)
    }
}

var handler cone.HandlerFunc = func(r cone.Response, e *cone.Event) {
    _ = r.Ack()
}

h := cone.NewHandlerMux()
h.Handler("event.subject", middleware(handler))

Or the whole mux.

middleware := func(next cone.Handler) cone.Handler {
    return func(r cone.Response, e *cone.Event) {
        next.Serve(r, e)
    }
}

s := conetest.NewSource()
h := cone.NewHandlerMux()
c := cone.New(s, middleware(h))

Todo

  • Event context
  • Event headers
  • Handler middleware
  • Consumer subject wildcard event.*
  • Source benchmark (Jetstream)

About

A generic event consumer with an http.Server-like interface.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages