pubsub

package
v0.0.0-...-f83813f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WebsocketReadTimeout  = 30 * time.Second
	WebsocketWriteTimeout = 10 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Delegate

type Delegate interface {
	Accept(r *http.Request) (channelName string, err error)
	OnRedisSubscribe(r *http.Request) error
}

type HTTPHandler

type HTTPHandler struct {
	RedisHub      RedisHub
	Delegate      Delegate
	LoggerFactory *log.Factory
	OriginMatcher WebsocketOriginMatcher
}

HTTPHandler receives incoming websocket messages and delegates them to the delegate. For each websocket connection, a redis pubsub connection is established. Every message from the redis pubsub connection is forwarded to the websocket connection verbatim.

func (*HTTPHandler) ServeHTTP

func (h *HTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Publisher

type Publisher struct {
	RedisPool RedisPool
}

func (*Publisher) Publish

func (p *Publisher) Publish(ctx context.Context, channelName string, data []byte) error

type RedisHub

type RedisHub interface {
	Subscribe(channelName string) (chan *redis.Message, func())
}

type RedisPool

type RedisPool interface {
	Get() *redis.Client
}

type WebsocketOriginMatcher

type WebsocketOriginMatcher interface {
	MatchOrigin(origin string) bool
}

type WebsocketOutgoingMessage

type WebsocketOutgoingMessage struct {
	MessageType websocket.MessageType
	Data        []byte
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL