azureeventhubs

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 39 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Azure Event Hubs

Parity grade: B · SDK azure-sdk-for-go/sdk/messaging/azeventhubs/v2@v2.0.2 · last audited 2026-10-20 (e332a0eae)

Coverage

Metric Value
PARITY entries audited 16 (9 ok, 7 partial)
Feature families 5 (4 ok, 1 partial)
Known gaps 4
Deferred items 0
Resource leaks clean
Known gaps
  • Capture, schema registry, application groups, compaction and cluster features are not implemented.
  • Hub names resolve across namespaces by first match.
  • Capture, geo-replication, compaction and application-group features are not implemented: their configuration (captureDescription, retentionDescription.cleanupPolicy, applicationGroups) is ARM state in services/azurearm (rp_eventhub_ops.go passes only partition count and retention to this service), which this service cannot read.
  • Geo-disaster recovery data plane: the alias FQDN does not resolve to the active namespace (AMQP and HTTP carry no namespace, so a client cannot connect through and see it move on failover), the secondary data plane is not read-only while paired (only ARM entity writes are refused), replication is synchronous and covers event hubs and consumer groups only, and the alias is not blocked for namespaces in the same dedicated cluster (clusters are not modelled).

More

Documentation

Overview

Package azureeventhubs emulates Azure Event Hubs: namespaces, event hubs, consumer groups and authorization rules shared with the ARM plane, an AMQP 1.0 data plane (pkgs/amqp1) for the official SDKs, and a small REST/Atom surface, plus a Kafka protocol endpoint (SASL PLAIN over TLS). See PARITY.md.

Index

Constants

View Source
const (
	KeyTypePrimary   = "PrimaryKey"
	KeyTypeSecondary = "SecondaryKey"
)

Key types accepted by RegenerateRuleKey.

View Source
const (
	DefaultNamespace      = "ehemulatorns"
	DefaultKeyName        = "RootManageSharedAccessKey"
	DefaultKeyValue       = "Kq0nF1bPjX5uV9c2yR7wZtHdLsGm3aEoQ8xT4iNvB6w="
	DefaultConsumerGroup  = "$Default"
	DefaultPartitionCount = 4
	MaxPartitionCount     = 1024
	DefaultRetention      = 24 * time.Hour
	MaxRetention          = 90 * 24 * time.Hour
	MaxEventBytes         = 1 << 20
)

Bounds and defaults.

View Source
const (
	RightListen = "Listen"
	RightSend   = "Send"
	RightManage = "Manage"
)

Rights an authorization rule can grant.

View Source
const (
	DefaultPort        = 10005
	DefaultAMQPPort    = 5673
	DefaultAMQPTLSPort = 5674
)

Default ports. The AMQP pair is offset by one from Service Bus's 5672/5671 so both emulators can run side by side.

View Source
const (
	// DefaultKafkaPort is the port of the Kafka endpoint, as on the real service.
	DefaultKafkaPort = 9093
)
View Source
const SelectorFilterCode uint64 = 0x00000468C00000004

SelectorFilterCode is the numeric descriptor of the selector filter.

View Source
const SelectorFilterName = "apache.org:selector-filter:string"

SelectorFilterName is the AMQP filter key Event Hubs receivers use.

Variables

View Source
var (
	ErrNamespaceNotFound     = errors.New("azureeventhubs: namespace not found")
	ErrHubNotFound           = errors.New("azureeventhubs: event hub not found")
	ErrConsumerGroupNotFound = errors.New("azureeventhubs: consumer group not found")
	ErrRuleNotFound          = errors.New("azureeventhubs: authorization rule not found")
	ErrPartitionNotFound     = errors.New("azureeventhubs: partition not found")
	ErrInvalidPartitionCount = errors.New("azureeventhubs: partition count out of range")
	ErrPartitionCountShrink  = errors.New("azureeventhubs: partition count cannot be decreased")
	ErrInvalidRetention      = errors.New("azureeventhubs: invalid retention")
	ErrProtectedEntity       = errors.New("azureeventhubs: entity cannot be deleted")
	ErrInvalidName           = errors.New("azureeventhubs: invalid entity name")
	ErrEventTooLarge         = errors.New("azureeventhubs: event exceeds the maximum size")
	ErrReceiverStolen        = errors.New("azureeventhubs: receiver superseded by a higher epoch")
	ErrTooManyReceivers      = errors.New("azureeventhubs: too many concurrent receivers")
	ErrInvalidSelector       = errors.New("azureeventhubs: invalid selector filter")
	ErrTooManyKafkaGroups    = errors.New("azureeventhubs: too many kafka consumer groups")
	ErrNilAppContext         = errors.New("azureeventhubs: nil app context")
)

Backend errors.

Functions

func ParseConnectionString

func ParseConnectionString(cs string) (string, string, string)

ParseConnectionString extracts the endpoint namespace, key name and key from an Event Hubs connection string.

func SignSAS

func SignSAS(encodedResource string, expiry int64, key string) string

SignSAS computes the SAS signature for an already URL-encoded resource.

Types

type ConfigProvider

type ConfigProvider interface {
	GetAzureEventHubsSettings() Settings
}

ConfigProvider extracts the Event Hubs settings from the AppContext config.

type Handler

type Handler struct {
	Backend *InMemoryBackend

	AMQPCert *tls.Certificate

	Port        int
	AMQPPort    int
	AMQPTLSPort int
	KafkaPort   int
	ValidateSAS bool
	// contains filtered or unexported fields
}

Handler owns the HTTP listener and the AMQP servers of the Event Hubs emulator.

func NewHandler

func NewHandler(backend *InMemoryBackend) *Handler

NewHandler returns a Handler over backend with default ports.

func (*Handler) ExtractOperation

func (h *Handler) ExtractOperation(c *echo.Context) string

ExtractOperation implements service.Service.

func (*Handler) ExtractResource

func (h *Handler) ExtractResource(c *echo.Context) string

ExtractResource implements service.Service.

func (*Handler) GetSupportedOperations

func (h *Handler) GetSupportedOperations() []string

GetSupportedOperations implements service.Service.

func (*Handler) Handler

func (h *Handler) Handler() echo.HandlerFunc

Handler returns the echo handler of the HTTP listener.

func (*Handler) MatchPriority

func (h *Handler) MatchPriority() int

MatchPriority implements service.Registerable.

func (*Handler) Name

func (h *Handler) Name() string

Name implements service.Service.

func (*Handler) Reset

func (h *Handler) Reset()

Reset implements service.Resettable.

func (*Handler) Restore

func (h *Handler) Restore(ctx context.Context, data []byte) error

Restore implements persistence.Persistable by delegating to the backend.

func (*Handler) RouteMatcher

func (h *Handler) RouteMatcher() service.Matcher

RouteMatcher never matches: Event Hubs listens on dedicated ports.

func (*Handler) ServeAMQP

func (h *Handler) ServeAMQP(ln net.Listener, useTLS bool) error

ServeAMQP serves AMQP 1.0 on ln (TLS-wrapped when useTLS) until Shutdown.

func (*Handler) ServeKafka

func (h *Handler) ServeKafka(ctx context.Context, raw net.Listener) error

ServeKafka serves the Kafka protocol over TLS on ln until Shutdown.

func (*Handler) Shutdown

func (h *Handler) Shutdown(ctx context.Context)

Shutdown implements service.Shutdowner.

func (*Handler) Snapshot

func (h *Handler) Snapshot(ctx context.Context) []byte

Snapshot implements persistence.Persistable by delegating to the backend.

func (*Handler) StartWorker

func (h *Handler) StartWorker(ctx context.Context) error

StartWorker binds the HTTP listener and the AMQP listeners.

type HubConfig

type HubConfig struct {
	PartitionCount int           `json:"partitionCount"`
	Retention      time.Duration `json:"retention"`
}

HubConfig is the configurable part of an event hub.

type HubInfo

type HubInfo struct {
	CreatedAt    time.Time
	Name         string
	Namespace    string
	PartitionIDs []string
	Config       HubConfig
}

HubInfo is the exported view of an event hub.

type HubRef

type HubRef struct {
	Namespace string
	Hub       string
}

HubRef addresses an event hub within a namespace.

type InMemoryBackend

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

InMemoryBackend is the Event Hubs state shared by the ARM, REST and AMQP planes.

func NewInMemoryBackend

func NewInMemoryBackend() *InMemoryBackend

NewInMemoryBackend returns an empty backend using the wall clock.

func (*InMemoryBackend) Append

func (b *InMemoryBackend) Append(ref HubRef, pid int, evs []NewEvent) (int, error)

Append stores events in one partition: pid, else the hash of the first event's key, else round-robin. It returns the partition used.

func (*InMemoryBackend) CommitKafkaOffset

func (b *InMemoryBackend) CommitKafkaOffset(ref HubRef, group string, pid int, offset int64) error

CommitKafkaOffset stores a consumer group's committed offset for one partition.

func (*InMemoryBackend) ConsumerGroup

func (b *InMemoryBackend) ConsumerGroup(ref HubRef, name string) (time.Time, error)

ConsumerGroup returns a consumer group's creation time.

func (*InMemoryBackend) CreateConsumerGroup

func (b *InMemoryBackend) CreateConsumerGroup(ref HubRef, name string) (time.Time, error)

CreateConsumerGroup creates a consumer group (idempotent).

func (*InMemoryBackend) CreateHub

func (b *InMemoryBackend) CreateHub(ref HubRef, cfg HubConfig) (HubInfo, error)

CreateHub creates or updates an event hub; the partition count may only grow.

func (*InMemoryBackend) DeleteConsumerGroup

func (b *InMemoryBackend) DeleteConsumerGroup(ref HubRef, name string) error

DeleteConsumerGroup removes a consumer group; $Default is protected.

func (*InMemoryBackend) DeleteHub

func (b *InMemoryBackend) DeleteHub(ref HubRef) error

DeleteHub removes an event hub and disconnects its receivers.

func (*InMemoryBackend) DeleteNamespace

func (b *InMemoryBackend) DeleteNamespace(name string) error

DeleteNamespace removes a namespace and everything in it.

func (*InMemoryBackend) DeleteRule

func (b *InMemoryBackend) DeleteRule(nsName, hubName, name string) error

DeleteRule removes an authorization rule; the namespace root rule is protected.

func (*InMemoryBackend) EnsureNamespace

func (b *InMemoryBackend) EnsureNamespace(name string) error

EnsureNamespace creates the namespace (with its root rule) if absent.

func (*InMemoryBackend) GetRule

func (b *InMemoryBackend) GetRule(nsName, hubName, name string) (Rule, error)

GetRule returns an authorization rule including its keys.

func (*InMemoryBackend) Hub

func (b *InMemoryBackend) Hub(ref HubRef) (HubInfo, error)

Hub returns an event hub's description.

func (*InMemoryBackend) HubCount

func (b *InMemoryBackend) HubCount() int

HubCount returns the number of hubs across namespaces.

func (*InMemoryBackend) HubNames

func (b *InMemoryBackend) HubNames(ns string) []string

HubNames lists the hubs a Kafka client can see: those of ns, or of every namespace (first match wins) when ns is empty.

func (*InMemoryBackend) KafkaCommitted

func (b *InMemoryBackend) KafkaCommitted(ref HubRef, group string) (map[int]int64, error)

KafkaCommitted lists the partitions of a hub with a committed offset for the group.

func (*InMemoryBackend) KafkaOffset

func (b *InMemoryBackend) KafkaOffset(ref HubRef, group string, pid int) (int64, error)

KafkaOffset returns a group's committed offset for a partition, or -1 when none was committed.

func (*InMemoryBackend) ListConsumerGroups

func (b *InMemoryBackend) ListConsumerGroups(ref HubRef) ([]string, error)

ListConsumerGroups returns the hub's consumer group names, sorted.

func (*InMemoryBackend) ListHubs

func (b *InMemoryBackend) ListHubs(nsName string) ([]HubInfo, error)

ListHubs returns the namespace's event hubs sorted by name.

func (*InMemoryBackend) ListRules

func (b *InMemoryBackend) ListRules(nsName string) ([]RuleScope, error)

ListRules returns the authorization rules of a namespace and its hubs, sorted by scope and name.

func (*InMemoryBackend) NamespaceExists

func (b *InMemoryBackend) NamespaceExists(name string) bool

NamespaceExists reports whether the namespace exists.

func (*InMemoryBackend) NamespaceNames

func (b *InMemoryBackend) NamespaceNames() []string

NamespaceNames returns the namespace names sorted.

func (*InMemoryBackend) Next

func (b *InMemoryBackend) Next(
	ctx context.Context, ref HubRef, pid int, cursor int64, stop <-chan struct{},
) (*event, error)

Next blocks until the partition holds an event at or after cursor, ctx ends, or stop closes (ErrReceiverStolen is reported through the caller).

func (*InMemoryBackend) PartitionInfo

func (b *InMemoryBackend) PartitionInfo(ref HubRef, pid int) (PartitionInfo, error)

PartitionInfo returns a partition's runtime state after retention.

func (*InMemoryBackend) PlainAuthorized

func (b *InMemoryBackend) PlainAuthorized(user, password string) bool

PlainAuthorized reports whether a SASL PLAIN user/password pair is a rule key.

func (*InMemoryBackend) PutRule

func (b *InMemoryBackend) PutRule(nsName, hubName, name string, rights []string) (Rule, error)

PutRule creates or updates an authorization rule scoped to the namespace or, when hubName is set, to one event hub; keys survive updates.

func (*InMemoryBackend) RegenerateRuleKey

func (b *InMemoryBackend) RegenerateRuleKey(nsName, hubName, name, keyType, key string) (Rule, error)

RegenerateRuleKey replaces one of a rule's keys with key, or a fresh random key when key is empty; tokens signed with the old value stop validating.

func (*InMemoryBackend) RegisterReceiver

func (b *InMemoryBackend) RegisterReceiver(
	ref HubRef,
	cg string,
	pid int,
	name string,
	epoch *int64,
) (*ReceiverReg, error)

RegisterReceiver admits a receiver to a partition of a consumer group, applying epoch (owner level) arbitration.

func (*InMemoryBackend) Reset

func (b *InMemoryBackend) Reset()

Reset drops all state and disconnects every receiver.

func (*InMemoryBackend) Resolve

func (b *InMemoryBackend) Resolve(ref HubRef, pid int, sel Selector) (int64, error)

Resolve turns a selector into the first sequence number a receiver should get.

func (*InMemoryBackend) ResolveHub

func (b *InMemoryBackend) ResolveHub(name string) (HubRef, bool)

ResolveHub finds the namespace owning a hub of the given name; AMQP addresses carry no namespace, so the first namespace by name wins.

func (*InMemoryBackend) Restore

func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error

Restore implements persistence.Persistable.

func (*InMemoryBackend) RuleRights

func (b *InMemoryBackend) RuleRights(ns, name, key string) ([]string, string, bool)

RuleRights validates a shared-access key pair and returns the rights and hub scope of the rule it belongs to. The scope is empty for a namespace-level rule. A non-empty ns restricts the lookup to that namespace.

func (*InMemoryBackend) Snapshot

func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte

Snapshot implements persistence.Persistable.

func (*InMemoryBackend) Sweep

func (b *InMemoryBackend) Sweep(now time.Time) int

Sweep applies retention to every hub; it returns the number of hubs visited.

func (*InMemoryBackend) UnregisterReceiver

func (b *InMemoryBackend) UnregisterReceiver(reg *ReceiverReg)

UnregisterReceiver removes a receiver registration.

type NewEvent

type NewEvent struct {
	Key string
	Raw []byte
}

NewEvent is one event to append: the encoded AMQP message minus the broker-owned annotations, and its partition key.

type PartitionInfo

type PartitionInfo struct {
	LastEnqueuedTime time.Time
	Hub              string
	Partition        string
	BeginSequence    int64
	LastSequence     int64
	LastOffset       int64
	Empty            bool
}

PartitionInfo is the runtime state of one partition.

type Provider

type Provider struct{}

Provider implements service.Provider for Azure Event Hubs.

func (*Provider) Init

Init builds the backend and handler; ports are bound by Handler.StartWorker.

func (*Provider) Name

func (p *Provider) Name() string

Name returns the service provider name.

type ReceiverReg

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

ReceiverReg is a partition receiver attached to a consumer group; kicked closes when a newer epoch takes over.

func (*ReceiverReg) Kicked

func (r *ReceiverReg) Kicked() <-chan struct{}

Kicked is closed when a higher-epoch receiver supersedes this one.

func (*ReceiverReg) Reason

func (r *ReceiverReg) Reason() string

Reason describes why the receiver was disconnected; valid once Kicked is closed.

type Rule

type Rule struct {
	Name         string
	PrimaryKey   string
	SecondaryKey string
	Rights       []string
}

Rule is the exported view of an authorization rule.

type RuleScope

type RuleScope struct {
	Hub  string
	Rule Rule
}

RuleScope is an authorization rule with the hub it is scoped to ("" for the namespace).

type Selector

type Selector struct {
	Value     int64
	Kind      selectorKind
	Latest    bool
	Inclusive bool
}

Selector is a parsed start position (offset, sequence number or enqueued time).

func ParseSelector

func ParseSelector(expr string) (Selector, error)

ParseSelector parses an `amqp.annotation.x-opt-* > 'v'` filter expression; the .NET SDKs send the value unquoted.

type Settings

type Settings struct {
	Port int `` //nolint:lll // config struct tags are intentionally verbose
	/* 194-byte string literal not displayed */
	AMQPPort int `` //nolint:lll // config struct tags are intentionally verbose
	/* 166-byte string literal not displayed */
	AMQPTLSPort int `` //nolint:lll // config struct tags are intentionally verbose
	/* 173-byte string literal not displayed */
	KafkaPort int `` //nolint:lll // config struct tags are intentionally verbose
	/* 191-byte string literal not displayed */
	ValidateSAS bool `` //nolint:lll // config struct tags are intentionally verbose
	/* 189-byte string literal not displayed */
}

Settings is the Kong-embedded configuration of the Event Hubs emulator.

func DefaultSettings

func DefaultSettings() Settings

DefaultSettings returns the settings used when no ConfigProvider exists.

Jump to

Keyboard shortcuts

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