Skip to content

tystuyfzand/websub-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go WebSub Server

A Go implementation of a WebSub server. It has been tested to pass every WebSub Rocks! Hub test.

See examples/main.go for a basic example which uses boltdb and a simple publisher.

Importing:

go get meow.tf/websub

Features

  • Acts as a package to allow implementation using your favorite HTTP router (See Hub.ServeHTTP, as well as each Handle method for implementation in other routers that aren't stdlib compliant)
  • Allows publishing of events directly from the hub, for use with custom implementations (such as a bridge for services that don't support hubs)
  • Supports secrets and sha1, sha256, sha384, sha512 validation
  • Supports Content-Type forwarding.
  • Supports external workers to scale past what a single server can do (See Workers)

Stores

Specific stores can be implemented/used to store subscriptions and call them.

If you'd like to implement your own store, the following interface can be implemented:

// Store defines an interface for stores to implement for data storage.
type Store interface {
	// All returns all subscriptions for the specified topic.
	All(topic string) ([]model.Subscription, error)

	// For returns the subscriptions for the specified callback
	For(callback string) ([]model.Subscription, error)

	// Add saves/adds a subscription to the store.
	Add(sub model.Subscription) error

	// Get retrieves a subscription given a topic and callback.
	Get(topic, callback string) (*model.Subscription, error)

	// Remove removes a subscription from the store.
	Remove(sub model.Subscription) error
}

Memory

A memory-backed store. This store is cleared when the application is restarted.

Bolt

A boltdb/bbolt backed store which persists to disk.

Workers

This hub system uses Workers to implement a system that can be infinitely scaled by adding other nodes/servers and workers which can pull off a queue.

By default, the worker pool is a basic channel + goroutine handler that goes through each request.

type Worker interface {
    Add(f PublishJob)
    Start()
    Stop()
}

When implementing workers, pay attention to the fields. ContentType is used to say what the body content type is (required by the specification), and if subscription.secret is set it MUST be used to generate an X-Hub-Signature header.

Using it with your own Publisher

If you wish to bypass the included hub.mode=publish handler, you can use the Publish function to publish your own data.

For example, if you're taking an event off some kind of queue/event subscriber:

hub.Publish("https://example.com", "application/json", []byte("{}"))

About

Go library for the WebSub protocol, allowing you to run your own scalable WebSub Hub

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages