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. The Kafka endpoint is not implemented. See PARITY.md.
Index ¶
- Constants
- Variables
- func SignSAS(encodedResource string, expiry int64, key string) string
- type ConfigProvider
- type Handler
- func (h *Handler) ExtractOperation(c *echo.Context) string
- func (h *Handler) ExtractResource(c *echo.Context) string
- func (h *Handler) GetSupportedOperations() []string
- func (h *Handler) Handler() echo.HandlerFunc
- func (h *Handler) MatchPriority() int
- func (h *Handler) Name() string
- func (h *Handler) Reset()
- func (h *Handler) Restore(ctx context.Context, data []byte) error
- func (h *Handler) RouteMatcher() service.Matcher
- func (h *Handler) ServeAMQP(ln net.Listener, useTLS bool) error
- func (h *Handler) Shutdown(ctx context.Context)
- func (h *Handler) Snapshot(ctx context.Context) []byte
- func (h *Handler) StartWorker(ctx context.Context) error
- type HubConfig
- type HubInfo
- type HubRef
- type InMemoryBackend
- func (b *InMemoryBackend) Append(ref HubRef, pid int, evs []NewEvent) (int, error)
- func (b *InMemoryBackend) ConsumerGroup(ref HubRef, name string) (time.Time, error)
- func (b *InMemoryBackend) CreateConsumerGroup(ref HubRef, name string) (time.Time, error)
- func (b *InMemoryBackend) CreateHub(ref HubRef, cfg HubConfig) (HubInfo, error)
- func (b *InMemoryBackend) DeleteConsumerGroup(ref HubRef, name string) error
- func (b *InMemoryBackend) DeleteHub(ref HubRef) error
- func (b *InMemoryBackend) DeleteNamespace(name string) error
- func (b *InMemoryBackend) DeleteRule(nsName, hubName, name string) error
- func (b *InMemoryBackend) EnsureNamespace(name string) error
- func (b *InMemoryBackend) GetRule(nsName, hubName, name string) (Rule, error)
- func (b *InMemoryBackend) Hub(ref HubRef) (HubInfo, error)
- func (b *InMemoryBackend) HubCount() int
- func (b *InMemoryBackend) ListConsumerGroups(ref HubRef) ([]string, error)
- func (b *InMemoryBackend) ListHubs(nsName string) ([]HubInfo, error)
- func (b *InMemoryBackend) NamespaceExists(name string) bool
- func (b *InMemoryBackend) NamespaceNames() []string
- func (b *InMemoryBackend) Next(ctx context.Context, ref HubRef, pid int, cursor int64, stop <-chan struct{}) (*event, error)
- func (b *InMemoryBackend) PartitionInfo(ref HubRef, pid int) (PartitionInfo, error)
- func (b *InMemoryBackend) PlainAuthorized(user, password string) bool
- func (b *InMemoryBackend) PutRule(nsName, hubName, name string, rights []string) (Rule, error)
- func (b *InMemoryBackend) RegisterReceiver(ref HubRef, cg string, pid int, name string, epoch *int64) (*ReceiverReg, error)
- func (b *InMemoryBackend) Reset()
- func (b *InMemoryBackend) Resolve(ref HubRef, pid int, sel Selector) (int64, error)
- func (b *InMemoryBackend) ResolveHub(name string) (HubRef, bool)
- func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
- func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
- func (b *InMemoryBackend) Sweep(now time.Time) int
- func (b *InMemoryBackend) UnregisterReceiver(reg *ReceiverReg)
- type NewEvent
- type PartitionInfo
- type Provider
- type ReceiverReg
- type Rule
- type Selector
- type Settings
Constants ¶
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.
const ( RightListen = "Listen" RightSend = "Send" RightManage = "Manage" )
Rights an authorization rule can grant.
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.
const SelectorFilterCode uint64 = 0x00000468C00000004
SelectorFilterCode is the numeric descriptor of the selector filter.
const SelectorFilterName = "apache.org:selector-filter:string"
SelectorFilterName is the AMQP filter key Event Hubs receivers use.
Variables ¶
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") ErrNilAppContext = errors.New("azureeventhubs: nil app context") )
Backend errors.
Functions ¶
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
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 ¶
ExtractOperation implements service.Service.
func (*Handler) ExtractResource ¶
ExtractResource implements service.Service.
func (*Handler) GetSupportedOperations ¶
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 ¶
MatchPriority implements service.Registerable.
func (*Handler) RouteMatcher ¶
RouteMatcher never matches: Event Hubs listens on dedicated ports.
func (*Handler) ServeAMQP ¶
ServeAMQP serves AMQP 1.0 on ln (TLS-wrapped when useTLS) until Shutdown.
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 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 ¶
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) ConsumerGroup ¶
ConsumerGroup returns a consumer group's creation time.
func (*InMemoryBackend) CreateConsumerGroup ¶
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) 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) 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) 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 ¶
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) 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 ¶
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 ¶
func (p *Provider) Init(ctx *service.AppContext) (service.Registerable, error)
Init builds the backend and handler; ports are bound by Handler.StartWorker.
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 Selector ¶
Selector is a parsed start position (offset, sequence number or enqueued time).
func ParseSelector ¶
ParseSelector parses an `amqp.annotation.x-opt-* > 'v'` filter expression.
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 */
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.