Skip to content

ostcar/topic

Repository files navigation

Topic

Actions Status PkgGoDev

Package topic is an in-process pubsub system where new values can be pulled instead of being pushed.

The idea of pulling updates is inspired by Kafka or Redis-Streams. A subscriber does not have to register or unsubscribe to a topic and can take as long as it needs to process the messages.

How to use topic

A topic can be created with: top := topic.New[string]().

To publish one or more values, use: top.Publish("info1", "info2").

To receive values for the first time use: id, values, err := top.Receive(ctx, 0). The first value is a numeric id, it is needed for the next call of top.Receive(). The second argument is a list of all values that were published by this topic.

To receive newer values, use id, values, err = top.Receive(ctx, id). It returns all values that were published after the given id.

A topic is safe for concurrent use.

Run tests

Contributions are welcome. Please make sure that the tests are running with:

go test

Who is using topic

Topic was built for OpenSlides and is used in production for the Autoupdate-Service for many years without any problems.

About

A golang in process sub/pub system inspired by Kafka or redis streams

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages