messaging

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2025 License: MIT Imports: 2 Imported by: 1

README

Things-Kit Messaging

Messaging Interface Abstraction for Things-Kit

This module defines the messaging abstraction for Things-Kit applications. It contains only interfaces, no implementation.

Installation

go get github.com/things-kit/things-kit-messaging

Purpose

The things-kit-messaging package defines the contracts for message handling in distributed systems. This allows applications to program against stable interfaces while being free to choose any messaging backend (Kafka, RabbitMQ, NATS, SQS, etc.).

Interfaces

Message
type Message interface {
    Topic() string
    Key() []byte
    Value() []byte
    Headers() map[string]string
    Timestamp() time.Time
}
Handler
type Handler interface {
    Handle(ctx context.Context, msg Message) error
    Topic() string
}
Consumer
type Consumer interface {
    RegisterHandler(handler Handler)
    Start(ctx context.Context) error
    Stop(ctx context.Context) error
}
Producer
type Producer interface {
    Produce(ctx context.Context, msg Message) error
    Close() error
}

Available Implementations

things-kit-kafka

The things-kit-kafka module provides a Kafka-based implementation.

License

MIT License - see LICENSE file for details

Documentation

Overview

Package messaging defines framework-level interfaces for message consumers. This abstraction allows different messaging implementations (Kafka, RabbitMQ, etc.) to be used interchangeably.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Consumer

type Consumer interface {
	// Start begins consuming messages from the message queue.
	// This should be non-blocking and return immediately after the consumer starts.
	// The implementation should start a goroutine for actual message consumption.
	Start(ctx context.Context) error

	// Stop gracefully shuts down the message consumer.
	// It should wait for in-flight message processing to complete within the context deadline.
	Stop(ctx context.Context) error
}

Consumer defines the interface for message consumers. Implementations manage the lifecycle of consuming messages from a message queue. The consumer is responsible for fetching messages and delegating to a Handler.

type Handler

type Handler interface {
	Handle(ctx context.Context, msg Message) error
}

Handler defines the interface for handling incoming messages. Implementations should process the message and return an error if processing fails.

type Message

type Message struct {
	Key       []byte
	Value     []byte
	Topic     string
	Timestamp time.Time
}

Message represents a generic message from a messaging system.

type Producer

type Producer interface {
	// Publish sends a message to the specified topic.
	// The key can be used for partitioning in systems like Kafka.
	Publish(ctx context.Context, topic string, key []byte, value []byte) error

	// PublishBatch sends multiple messages to the specified topic efficiently.
	// Returns an error if any message fails to publish.
	PublishBatch(ctx context.Context, topic string, messages []Message) error

	// Close closes the producer and releases resources.
	Close() error
}

Producer defines the interface for message producers. Implementations publish messages to a message queue or topic.

Jump to

Keyboard shortcuts

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