journal

package
v0.18.3 Latest Latest
Warning

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

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

Documentation

Overview

Package journal contains the journal service. This service is responsible for storing events from the event store to a journal log repository. It is also responsible for providing a REST API to query events.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientSubscription added in v0.17.0

type ClientSubscription struct {
	ID           string `json:"id" db:"id"`
	SubscriberID string `json:"subscriber_id" db:"subscriber_id"`
	ChannelID    string `json:"channel_id" db:"channel_id"`
	Subtopic     string `json:"subtopic" db:"subtopic"`
	ClientID     string `json:"client_id" db:"client_id"`
}

type ClientTelemetry added in v0.17.0

type ClientTelemetry struct {
	ClientID         string    `json:"client_id"`
	DomainID         string    `json:"domain_id"`
	Subscriptions    uint64    `json:"subscriptions"`
	InboundMessages  uint64    `json:"inbound_messages"`
	OutboundMessages uint64    `json:"outbound_messages"`
	FirstSeen        time.Time `json:"first_seen"`
	LastSeen         time.Time `json:"last_seen"`
}

type EntityType

type EntityType uint8
const (
	UserEntity EntityType = iota
	GroupEntity
	ClientEntity
	ChannelEntity
)

func ToEntityType

func ToEntityType(entityType string) (EntityType, error)

ToEntityType converts string value to a valid entity type.

func (EntityType) Query

func (e EntityType) Query() string

Query returns the SQL condition for the entity type.

func (EntityType) String

func (e EntityType) String() string

String converts entity type to string literal.

type Journal

type Journal struct {
	ID         string         `json:"id,omitempty" db:"id"`
	Domain     string         `json:"domain,omitempty" db:"domain"`
	Operation  string         `json:"operation,omitempty" db:"operation,omitempty"`
	OccurredAt time.Time      `json:"occurred_at,omitempty" db:"occurred_at,omitempty"`
	Attributes map[string]any `json:"attributes,omitempty" db:"attributes,omitempty"` // This is extra information about the journal for example client_id, user_id, group_id etc.
	Metadata   map[string]any `json:"metadata,omitempty" db:"metadata,omitempty"`     // This is decoded metadata from the journal.
}

Journal represents an event journal that occurred in the system.

type JournalsPage

type JournalsPage struct {
	Total    uint64    `json:"total"`
	Offset   uint64    `json:"offset"`
	Limit    uint64    `json:"limit"`
	Journals []Journal `json:"journals"`
}

JournalsPage represents a page of journals.

func (JournalsPage) MarshalJSON

func (page JournalsPage) MarshalJSON() ([]byte, error)

type Page

type Page struct {
	Offset         uint64     `json:"offset" db:"offset"`
	Limit          uint64     `json:"limit" db:"limit"`
	Operation      string     `json:"operation,omitempty" db:"operation,omitempty"`
	From           time.Time  `json:"from,omitempty" db:"from,omitempty"`
	To             time.Time  `json:"to,omitempty" db:"to,omitempty"`
	WithAttributes bool       `json:"with_attributes,omitempty"`
	WithMetadata   bool       `json:"with_metadata,omitempty"`
	EntityID       string     `json:"entity_id,omitempty" db:"entity_id,omitempty"`
	EntityType     EntityType `json:"entity_type,omitempty" db:"entity_type,omitempty"`
	Direction      string     `json:"direction,omitempty"`
}

Page is used to filter journals.

type Repository

type Repository interface {
	// Save persists the journal to a database.
	Save(ctx context.Context, journal Journal) error

	// RetrieveAll retrieves all journals from the database with the given page.
	RetrieveAll(ctx context.Context, page Page) (JournalsPage, error)

	// SaveClientTelemetry persists telemetry data for a client to the database.
	SaveClientTelemetry(ctx context.Context, ct ClientTelemetry) error

	// RetrieveClientTelemetry retrieves telemetry data for a client from the database.
	RetrieveClientTelemetry(ctx context.Context, clientID, domainID string) (ClientTelemetry, error)

	// DeleteClientTelemetry removes telemetry data for a client from the database.
	DeleteClientTelemetry(ctx context.Context, clientID, domainID string) error

	// AddSubscription adds a subscription to the client telemetry.
	AddSubscription(ctx context.Context, sub ClientSubscription) error

	// CountSubscriptions returns the number of subscriptions for a client.
	CountSubscriptions(ctx context.Context, clientID string) (uint64, error)

	// RemoveSubscription removes a subscription from the client telemetry.
	RemoveSubscription(ctx context.Context, subscriberID string) error

	// IncrementInboundMessages increments the inbound messages count for a client.
	IncrementInboundMessages(ctx context.Context, ct ClientTelemetry) error

	// IncrementOutboundMessages increments the outbound messages count for a client.
	IncrementOutboundMessages(ctx context.Context, channelID, subtopic string) error
}

Repository provides access to the journal log database.

type Service

type Service interface {
	// Save saves the journal to the database.
	Save(ctx context.Context, journal Journal) error

	// RetrieveAll retrieves all journals from the database with the given page.
	RetrieveAll(ctx context.Context, session smqauthn.Session, page Page) (JournalsPage, error)

	// RetrieveClientTelemetry retrieves telemetry data for a client.
	RetrieveClientTelemetry(ctx context.Context, session smqauthn.Session, clientID string) (ClientTelemetry, error)
}

Service provides access to the journal log service.

func NewService

func NewService(idp supermq.IDProvider, repository Repository) Service

Directories

Path Synopsis
Package api contains API-related concerns: endpoint definitions, middlewares and all resource representations.
Package api contains API-related concerns: endpoint definitions, middlewares and all resource representations.
Package events provides the event consumer for the journal service.
Package events provides the event consumer for the journal service.
Package middleware provides tracing, logging and metrics middleware for SuperMQ Journal service.
Package middleware provides tracing, logging and metrics middleware for SuperMQ Journal service.
Package mocks contains mocks for testing purposes.
Package mocks contains mocks for testing purposes.
Package postgres provides a postgres implementation of the journal log repository.
Package postgres provides a postgres implementation of the journal log repository.

Jump to

Keyboard shortcuts

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