Code Monkey home page Code Monkey logo

websub-server's Introduction

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("{}"))

websub-server's People

Contributors

tystuyfzand avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

isgasho

websub-server's Issues

Some questions to start using it

Hi and thank you for your great job !

I have some questions about it :

  • Your exemples are very light, is there something to do to have logs when a subscribe or a publish is made ?
  • Is it possible to use a database like MySQL to store the subscribers ?
  • Did you made the 5.3.1 part of the W3C article, where the hub must confirm a subscribe by receiving a GET request with the hub.challenge issued during the subscribe ? I can't make it work.
  • The W3C article is not very clear about the parameters to send for publishing, do you use, in addition to hub.mode=publish, the parameter hub.topic or hub.url?
  • I have an error when a subscribe request is made and a hub.lease_seconds param is send by the subscriber to the hub : 'hub.lease_seconds' expected type 'int', got unconvertible type '[]string', value: '[60]'

Thanks again !

Subscriber/client implemtnatino?

Hi @tystuyfzand ๐Ÿ‘‹

Sorry to reach out to you like this, you seem to have no other contact methods ๐Ÿ˜…

I really like your implementation of WebSub here -- I believe it implements both a Hub and Publisher right?

I'm considering using your package/library, however I cannot find a good implementation of a Subscriber/client -- Do you know of any? Or perhaps would you help me build one? I really like your design principles here ๐Ÿ˜‰

Kind regards

James

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.