messagebroker

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package messagebroker provides the message broker implementation of the Yorkie.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyAddress is returned when the address is empty.
	ErrEmptyAddress = errors.New("address cannot be empty")

	// ErrEmptyTopic is returned when the topic is empty.
	ErrEmptyTopic = errors.New("topic cannot be empty")

	// ErrInvalidDuration is returned when the duration is invalid.
	ErrInvalidDuration = errors.New("invalid duration")
)

Functions

This section is empty.

Types

type Broker

type Broker interface {
	Produce(ctx context.Context, msg Message) error
	Close() error
}

Broker is an interface for the message broker.

func Ensure

func Ensure(kafkaConf *Config) Broker

Ensure creates a message broker based on the given configuration.

type Config

type Config struct {
	Addresses    string `yaml:"Addresses"`
	Topic        string `yaml:"Topic"`
	WriteTimeout string `yaml:"WriteTimeout"`
}

Config is the configuration for creating a message broker instance.

func (*Config) MustParseWriteTimeout

func (c *Config) MustParseWriteTimeout() time.Duration

MustParseWriteTimeout parses the write timeout and returns the duration.

func (*Config) SplitAddresses

func (c *Config) SplitAddresses() []string

SplitAddresses splits the addresses by comma.

func (*Config) Validate

func (c *Config) Validate() error

Validate validates this config.

type DummyBroker

type DummyBroker struct{}

DummyBroker is a dummy broker that does nothing. It is used when the message broker is not configured.

func (*DummyBroker) Close

func (mb *DummyBroker) Close() error

Close does nothing.

func (*DummyBroker) Produce

func (mb *DummyBroker) Produce(_ context.Context, _ Message) error

Produce does nothing.

type KafkaBroker

type KafkaBroker struct {
	// contains filtered or unexported fields
}

KafkaBroker is a producer for Kafka.

func (*KafkaBroker) Close

func (mb *KafkaBroker) Close() error

Close closes the KafkaProducer.

func (*KafkaBroker) Produce

func (mb *KafkaBroker) Produce(
	ctx context.Context,
	msg Message,
) error

Produce produces a user event to Kafka.

type Message

type Message interface {
	Marshal() ([]byte, error)
}

Message represents a message that can be sent to the message broker.

type UserEventMessage

type UserEventMessage struct {
	ProjectID string                 `json:"project_id"`
	EventType events.ClientEventType `json:"event_type"`
	UserID    string                 `json:"user_id"`
	Timestamp time.Time              `json:"timestamp"`
	UserAgent string                 `json:"user_agent"`
}

UserEventMessage represents a message for user events

func (UserEventMessage) Marshal

func (m UserEventMessage) Marshal() ([]byte, error)

Marshal marshals the user event message to JSON.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳