types

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2025 License: GPL-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package types provides core type definitions for the GoBroke message broker system.

Package types provides core type definitions for the GoBroke message broker system. It defines the fundamental data structures and interfaces that form the basis of message routing, processing, and state management within the system.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logic

type Logic interface {
	// RunLogic processes a message and returns an error if processing fails.
	RunLogic(Message) error

	// Type returns the LogicType that determines how this handler processes messages.
	Type() LogicType

	// Name returns a unique identifier for this logic handler.
	Name() LogicName
}

Logic defines the interface that all logic handlers must implement. Logic handlers are responsible for processing messages within the GoBroke system.

type LogicName added in v0.0.2

type LogicName string

LogicName represents the name of the logic handler

type LogicType

type LogicType int

LogicType represents the execution mode of a logic handler.

const (
	// DISPATCHED indicates the logic handler runs in a new goroutine for each message.
	DISPATCHED LogicType = iota

	// WORKER indicates the logic handler processes messages sequentially.
	WORKER

	// PASSIVE indicates the logic handler only observes messages without processing.
	PASSIVE
)

type Message

type Message struct {
	// ToClient is a slice of client recipients for this message
	ToClient []*clients.Client

	// ToLogic is a slice of logic handlers that should process this message
	ToLogic []LogicName

	// FromClient identifies the client that originated this message, if any
	FromClient *clients.Client

	// FromLogic identifies the logic handler that originated this message, if any
	FromLogic LogicName

	// MessageRaw contains the raw message payload as bytes
	MessageRaw []byte

	// Metadata holds additional key-value pairs associated with the message
	Metadata map[string]any

	// UUID uniquely identifies this message instance
	UUID string

	// State is used for middleware to reject or accept a message
	State MessageState

	// Tags is used for middlware to be able to add tags to the message
	Tags map[string]interface{}

	SentQuickly bool

	FromRedis bool
}

Message represents a communication unit within the GoBroke system. It encapsulates all information needed for message routing and processing, including sender and recipient information, payload data, and processing state. Messages can be created using the functions in the message package.

func (*Message) Accept added in v0.0.2

func (m *Message) Accept()

Accept marks the message as accepted for further processing. This is typically used by middleware to explicitly allow a message to continue through the processing pipeline.

func (*Message) AddTag added in v0.0.2

func (m *Message) AddTag(tag string, value interface{})

AddTag associates a key-value pair with the message. Tags can be used by middleware and logic handlers to attach arbitrary data to messages for processing or tracking purposes.

Parameters:

  • tag: The key for the tag
  • value: The value to associate with the tag

func (*Message) GetTag added in v0.0.2

func (m *Message) GetTag(tag string, value interface{}) (interface{}, error)

GetTag retrieves the value associated with a tag. If the tag doesn't exist, it returns an error.

Parameters:

  • tag: The key for the tag to retrieve
  • value: Placeholder parameter (unused)

Returns:

  • interface{}: The value associated with the tag
  • error: ErrorTagDoesNotExist if the tag is not found

func (*Message) Reject added in v0.0.2

func (m *Message) Reject()

Reject marks the message as rejected, preventing further processing. This is typically used by middleware to filter out unwanted messages or implement access control.

type MessageState added in v0.0.2

type MessageState int

MessageState represents the processing state of a message within the system. It is used by middleware to control message flow and handling.

const (
	// ACCEPTED indicates the message should continue through the processing pipeline.
	// This is the default state for new messages.
	ACCEPTED MessageState = iota

	// REJECTED indicates the message should be dropped from the processing pipeline.
	// Middleware can set this state to prevent further message processing.
	REJECTED
)

Jump to

Keyboard shortcuts

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