Documentation
¶
Overview ¶
go-exchange is an in-process message (or event) exchange, for now featuring the publish-subscribe messaging pattern. The interestng part is, however, that callbacks are not registered for exactly matching event topic, but rather event topic prefixes.
Index ¶
- Variables
- type Event
- type EventHandler
- type Exchange
- func (exchange *Exchange) Publish(topic Topic, event Event) error
- func (exchange *Exchange) Subscribe(topicPrefix Topic, handler EventHandler) (Handle, error)
- func (exchange *Exchange) Terminate() error
- func (exchange *Exchange) Unsubscribe(handle Handle) error
- func (exchange *Exchange) Wait() error
- type Handle
- type Topic
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type EventHandler ¶
type Exchange ¶
type Exchange struct {
// contains filtered or unexported fields
}
Exchange is the struct this package is named after, or the other way around.
For now Exchange supports the publish-subscribe messaging pattern. It is based on topics and callbacks can be registered for topic prefixes, not only events that match exactly the chosen topic string.
Exchange is thread-safe.
func (*Exchange) Publish ¶
Publish can be used for inserting the events into the exchange.
This methods triggers all the relevant handlers and runs them in separate goroutines.
func (*Exchange) Subscribe ¶
func (exchange *Exchange) Subscribe(topicPrefix Topic, handler EventHandler) (Handle, error)
Subscribe registers handler to be invoked on any event that matches prefix topicPrefix.
The handlers registered with Subscribe are invoked asynchronously using go when an event matching the relevant prefix is received.
func (*Exchange) Terminate ¶
Terminate manes it impossible to insert any additional events into Exchange. Then it waits for all running handlers to return. Then it returns as well.
func (*Exchange) Unsubscribe ¶
Unsubscribe cancels the event handler represented by handle.