This is an experimental Pub/Sub implementation that leverages the standard library’sio.Writer and io.Reader interfaces as sources of Publisher and Subscriber, respectively.
Note that these aren’t full-fledged Pub/Subs like Kafka, RabbitMQ, or the likes, but given the ubiquity of implementations of Writer and Reader they may come in handy, for uses like:
Writing messages to file or stdout
Subscribing for data on a file or stdin and packaging it as messages
This is a very bare-bones implementation for now, so no extra features are supported. However, it is still sufficient for applications like a CLI producer/consumer
.
The subscriber may work in two modes – either perform buffered reads of constant size from the io.Reader, or split the byte stream into messages using a delimiter byte.
The reading will continue even if the reads come up empty, but they will not be sent out as messages. The time to wait after an empty read is configured through the PollInterval parameter. As soon as a non-empty input is read, it will be packaged as a message and sent out.
The package comes with some predefined marshal and unmarshal functions, but you might want to write your own marshaler/unmarshaler to work with the specific implementation of io.Writer/io.Reader that you are working with.
For the Publisher/Subscriber implementation itself, the topic has no meaning. It is difficult to interpret the meaning of topic in the general context of io.Writer and io.Reader interfaces.
However, the topic is passed as a parameter to the marshal/unmarshal functions, so the adaptations to particular Writer/Reader implementation may take it into account.