Documentation ¶
Overview ¶
Package eventhub provides functionality for interacting with Azure Event Hubs.
Index ¶
- Constants
- func ApplyComponentInfo(span *trace.Span)
- type BaseEntityDescription
- type Event
- type EventBatch
- type Handler
- type Hub
- func NewHub(namespace, name string, tokenProvider auth.TokenProvider, opts ...HubOption) (*Hub, error)
- func NewHubFromConnectionString(connStr string, opts ...HubOption) (*Hub, error)
- func NewHubFromEnvironment(opts ...HubOption) (*Hub, error)
- func NewHubWithNamespaceNameAndEnvironment(namespace, name string, opts ...HubOption) (*Hub, error)
- func (h *Hub) Close(ctx context.Context) error
- func (h *Hub) GetPartitionInformation(ctx context.Context, partitionID string) (*HubPartitionRuntimeInformation, error)
- func (h *Hub) GetRuntimeInformation(ctx context.Context) (*HubRuntimeInformation, error)
- func (h *Hub) Receive(ctx context.Context, partitionID string, handler Handler, ...) (*ListenerHandle, error)
- func (h *Hub) Send(ctx context.Context, event *Event, opts ...SendOption) error
- func (h *Hub) SendBatch(ctx context.Context, batch *EventBatch, opts ...SendOption) error
- type HubDescription
- type HubEntity
- type HubManagementOption
- type HubManager
- func (hm *HubManager) Delete(ctx context.Context, name string) error
- func (em HubManager) Execute(ctx context.Context, method string, entityPath string, body io.Reader) (*http.Response, error)
- func (hm *HubManager) Get(ctx context.Context, name string) (*HubEntity, error)
- func (hm *HubManager) List(ctx context.Context) ([]*HubEntity, error)
- func (em HubManager) Post(ctx context.Context, entityPath string, body []byte) (*http.Response, error)
- func (hm *HubManager) Put(ctx context.Context, name string, opts ...HubManagementOption) (*HubEntity, error)
- type HubOption
- type HubPartitionRuntimeInformation
- type HubRuntimeInformation
- type ListenerHandle
- type Manager
- type PartitionedReceiver
- type ReceiveOption
- func ReceiveFromTimestamp(t time.Time) ReceiveOption
- func ReceiveWithConsumerGroup(consumerGroup string) ReceiveOption
- func ReceiveWithEpoch(epoch int64) ReceiveOption
- func ReceiveWithLatestOffset() ReceiveOption
- func ReceiveWithPrefetchCount(prefetch uint32) ReceiveOption
- func ReceiveWithStartingOffset(offset string) ReceiveOption
- type SendOption
- type Sender
Constants ¶
const (
// DefaultConsumerGroup is the default name for a event stream consumer group
DefaultConsumerGroup = "$Default"
)
const (
// MsftVendor is the Microsoft vendor identifier
MsftVendor = "com.microsoft"
)
const (
// Version is the semantic version number
Version = "1.1.2"
)
Variables ¶
This section is empty.
Functions ¶
func ApplyComponentInfo ¶ added in v0.2.0
ApplyComponentInfo applies eventhub library and network info to the span
Types ¶
type BaseEntityDescription ¶ added in v1.0.0
type BaseEntityDescription struct { InstanceMetadataSchema *string `xml:"xmlns:i,attr,omitempty"` ServiceBusSchema *string `xml:"xmlns,attr,omitempty"` }
BaseEntityDescription provides common fields which are part of Queues, Topics and Subscriptions
type Event ¶
type Event struct { Data []byte PartitionKey *string Properties map[string]interface{} ID string // contains filtered or unexported fields }
Event is an Event Hubs message to be sent or received
func NewEventFromString ¶
NewEventFromString builds an Event from a string message
func (*Event) GetCheckpoint ¶
func (e *Event) GetCheckpoint() persist.Checkpoint
GetCheckpoint returns the checkpoint information on the Event
type EventBatch ¶
type EventBatch struct { Events []*Event PartitionKey *string Properties map[string]interface{} ID string }
EventBatch is a batch of Event Hubs messages to be sent
func NewEventBatch ¶
func NewEventBatch(events []*Event) *EventBatch
NewEventBatch builds an EventBatch from an array of Events
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub provides the ability to send and receive Event Hub messages
func NewHub ¶
func NewHub(namespace, name string, tokenProvider auth.TokenProvider, opts ...HubOption) (*Hub, error)
NewHub creates a new Event Hub client for sending and receiving messages
func NewHubFromConnectionString ¶ added in v1.0.0
NewHubFromConnectionString creates a new Event Hub client for sending and receiving messages from a connection string formatted like the following:
Endpoint=sb://namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=superSecret1234=;EntityPath=hubName
func NewHubFromEnvironment ¶
NewHubFromEnvironment creates a new Event Hub client for sending and receiving messages from environment variables
Expected Environment Variables:
- "EVENTHUB_NAMESPACE" the namespace of the Event Hub instance
- "EVENTHUB_NAME" the name of the Event Hub instance
This method depends on NewHubWithNamespaceNameAndEnvironment which will attempt to build a token provider from environment variables. If unable to build a AAD Token Provider it will fall back to a SAS token provider. If neither can be built, it will return error.
SAS TokenProvider environment variables:
There are two sets of environment variables which can produce a SAS TokenProvider
Expected Environment Variables: - "EVENTHUB_NAMESPACE" the namespace of the Event Hub instance - "EVENTHUB_KEY_NAME" the name of the Event Hub key - "EVENTHUB_KEY_VALUE" the secret for the Event Hub key named in "EVENTHUB_KEY_NAME"
Expected Environment Variable: - "EVENTHUB_CONNECTION_STRING" connection string from the Azure portal
AAD TokenProvider environment variables:
client Credentials: attempt to authenticate with a Service Principal via "AZURE_TENANT_ID", "AZURE_CLIENT_ID" and "AZURE_CLIENT_SECRET"
client Certificate: attempt to authenticate with a Service Principal via "AZURE_TENANT_ID", "AZURE_CLIENT_ID", "AZURE_CERTIFICATE_PATH" and "AZURE_CERTIFICATE_PASSWORD"
Managed Service Identity (MSI): attempt to authenticate via MSI
The Azure Environment used can be specified using the name of the Azure Environment set in the AZURE_ENVIRONMENT var.
func NewHubWithNamespaceNameAndEnvironment ¶
NewHubWithNamespaceNameAndEnvironment creates a new Event Hub client for sending and receiving messages from environment variables with supplied namespace and name which will attempt to build a token provider from environment variables. If unable to build a AAD Token Provider it will fall back to a SAS token provider. If neither can be built, it will return error.
SAS TokenProvider environment variables:
There are two sets of environment variables which can produce a SAS TokenProvider
Expected Environment Variables: - "EVENTHUB_KEY_NAME" the name of the Event Hub key - "EVENTHUB_KEY_VALUE" the secret for the Event Hub key named in "EVENTHUB_KEY_NAME"
Expected Environment Variable: - "EVENTHUB_CONNECTION_STRING" connection string from the Azure portal
AAD TokenProvider environment variables:
client Credentials: attempt to authenticate with a Service Principal via "AZURE_TENANT_ID", "AZURE_CLIENT_ID" and "AZURE_CLIENT_SECRET"
client Certificate: attempt to authenticate with a Service Principal via "AZURE_TENANT_ID", "AZURE_CLIENT_ID", "AZURE_CERTIFICATE_PATH" and "AZURE_CERTIFICATE_PASSWORD"
Managed Service Identity (MSI): attempt to authenticate via MSI on the default local MSI internally addressable IP and port. See: adal.GetMSIVMEndpoint()
The Azure Environment used can be specified using the name of the Azure Environment set in the AZURE_ENVIRONMENT var.
func (*Hub) GetPartitionInformation ¶
func (h *Hub) GetPartitionInformation(ctx context.Context, partitionID string) (*HubPartitionRuntimeInformation, error)
GetPartitionInformation fetches runtime information about a specific partition from the Event Hub management node
func (*Hub) GetRuntimeInformation ¶
func (h *Hub) GetRuntimeInformation(ctx context.Context) (*HubRuntimeInformation, error)
GetRuntimeInformation fetches runtime information from the Event Hub management node
func (*Hub) Receive ¶
func (h *Hub) Receive(ctx context.Context, partitionID string, handler Handler, opts ...ReceiveOption) (*ListenerHandle, error)
Receive subscribes for messages sent to the provided entityPath.
The context passed into Receive is only used to limit the amount of time the caller will wait for the Receive method to connect to the Event Hub. The context passed in does not control the lifetime of Receive after connection.
If Receive encounters an initial error setting up the connection, an error will be returned.
If Receive starts successfully, a *ListenerHandle and a nil error will be returned. The ListenerHandle exposes methods which will help manage the life span of the receiver.
ListenerHandle.Close(ctx) closes the receiver ¶
ListenerHandle.Done() signals the consumer when the receiver has stopped ¶
ListenerHandle.Err() provides the last error the listener encountered and was unable to recover from
func (*Hub) Send ¶
Send sends an event to the Event Hub
Send will retry sending the message for as long as the context allows
func (*Hub) SendBatch ¶
func (h *Hub) SendBatch(ctx context.Context, batch *EventBatch, opts ...SendOption) error
SendBatch sends an EventBatch to the Event Hub
SendBatch will retry sending the message for as long as the context allows
type HubDescription ¶ added in v1.0.0
type HubDescription struct { XMLName xml.Name `xml:"EventHubDescription"` MessageRetentionInDays *int32 `xml:"MessageRetentionInDays,omitempty"` SizeInBytes *int64 `xml:"SizeInBytes,omitempty"` Status *eventhub.EntityStatus `xml:"Status,omitempty"` CreatedAt *date.Time `xml:"CreatedAt,omitempty"` UpdatedAt *date.Time `xml:"UpdatedAt,omitempty"` PartitionCount *int32 `xml:"PartitionCount,omitempty"` PartitionIDs *[]string `xml:"PartitionIds>string,omitempty"` EntityAvailabilityStatus *string `xml:"EntityAvailabilityStatus,omitempty"` BaseEntityDescription }
HubDescription is the content type for Event Hub management requests
type HubEntity ¶ added in v1.0.0
type HubEntity struct { *HubDescription Name string }
HubEntity is the Azure Event Hub description of a Hub for management activities
type HubManagementOption ¶ added in v1.0.0
type HubManagementOption func(description *HubDescription) error
HubManagementOption provides structure for configuring new Event Hubs
func HubWithMessageRetentionInDays ¶ added in v1.0.0
func HubWithMessageRetentionInDays(days int32) HubManagementOption
HubWithMessageRetentionInDays configures an Event Hub to retain messages for that number of days
func HubWithPartitionCount ¶ added in v1.0.0
func HubWithPartitionCount(count int32) HubManagementOption
HubWithPartitionCount configures an Event Hub to have the specified number of partitions. More partitions == more throughput
type HubManager ¶ added in v1.0.0
type HubManager struct {
// contains filtered or unexported fields
}
HubManager provides CRUD functionality for Event Hubs
func NewHubManagerFromAzureEnvironment ¶ added in v1.0.0
func NewHubManagerFromAzureEnvironment(namespace string, tokenProvider auth.TokenProvider, env azure.Environment) (*HubManager, error)
NewHubManagerFromAzureEnvironment builds a HubManager from a Event Hub name, SAS or AAD token provider and Azure Environment
func NewHubManagerFromConnectionString ¶ added in v1.0.0
func NewHubManagerFromConnectionString(connStr string) (*HubManager, error)
NewHubManagerFromConnectionString builds a HubManager from an Event Hub connection string
func (*HubManager) Delete ¶ added in v1.0.0
func (hm *HubManager) Delete(ctx context.Context, name string) error
Delete deletes an Event Hub entity by name
func (HubManager) Execute ¶ added in v1.0.0
func (em HubManager) Execute(ctx context.Context, method string, entityPath string, body io.Reader) (*http.Response, error)
Execute performs an HTTP request given a http method, path and body
func (*HubManager) List ¶ added in v1.0.0
func (hm *HubManager) List(ctx context.Context) ([]*HubEntity, error)
List fetches all of the Hub for an Event Hubs Namespace
func (HubManager) Post ¶ added in v1.0.0
func (em HubManager) Post(ctx context.Context, entityPath string, body []byte) (*http.Response, error)
Post performs an HTTP POST for a given entity path and body
func (*HubManager) Put ¶ added in v1.0.0
func (hm *HubManager) Put(ctx context.Context, name string, opts ...HubManagementOption) (*HubEntity, error)
Put creates or updates an Event Hubs Hub
type HubOption ¶
HubOption provides structure for configuring new Event Hub clients. For building new Event Hubs, see HubManagementOption.
func HubWithEnvironment ¶
func HubWithEnvironment(env azure.Environment) HubOption
HubWithEnvironment configures the Hub to use the specified environment.
By default, the Hub instance will use Azure US Public cloud environment
func HubWithOffsetPersistence ¶
func HubWithOffsetPersistence(offsetPersister persist.CheckpointPersister) HubOption
HubWithOffsetPersistence configures the Hub instance to read and write offsets so that if a Hub is interrupted, it can resume after the last consumed event.
func HubWithPartitionedSender ¶
HubWithPartitionedSender configures the Hub instance to send to a specific event Hub partition
func HubWithUserAgent ¶
HubWithUserAgent configures the Hub to append the given string to the user agent sent to the server
This option can be specified multiple times to add additional segments.
Max user agent length is specified by the const maxUserAgentLen.
type HubPartitionRuntimeInformation ¶ added in v1.0.0
type HubPartitionRuntimeInformation struct { HubPath string `mapstructure:"name"` PartitionID string `mapstructure:"partition"` BeginningSequenceNumber int64 `mapstructure:"begin_sequence_number"` LastSequenceNumber int64 `mapstructure:"last_enqueued_sequence_number"` LastEnqueuedOffset string `mapstructure:"last_enqueued_offset"` LastEnqueuedTimeUtc time.Time `mapstructure:"last_enqueued_time_utc"` }
HubPartitionRuntimeInformation provides management node information about a given Event Hub partition
type HubRuntimeInformation ¶ added in v1.0.0
type HubRuntimeInformation struct { Path string `mapstructure:"name"` CreatedAt time.Time `mapstructure:"created_at"` PartitionCount int `mapstructure:"partition_count"` PartitionIDs []string `mapstructure:"partition_ids"` }
HubRuntimeInformation provides management node information about a given Event Hub instance
type ListenerHandle ¶
type ListenerHandle struct {
// contains filtered or unexported fields
}
ListenerHandle provides the ability to close or listen to the close of a Receiver
func (*ListenerHandle) Close ¶
func (lc *ListenerHandle) Close(ctx context.Context) error
Close will close the listener
func (*ListenerHandle) Done ¶
func (lc *ListenerHandle) Done() <-chan struct{}
Done will close the channel when the listener has stopped
func (*ListenerHandle) Err ¶
func (lc *ListenerHandle) Err() error
Err will return the last error encountered
type Manager ¶
type Manager interface { GetRuntimeInformation(context.Context) (HubRuntimeInformation, error) GetPartitionInformation(context.Context, string) (HubPartitionRuntimeInformation, error) }
Manager provides the ability to query management node information about a node
type PartitionedReceiver ¶
type PartitionedReceiver interface {
Receive(ctx context.Context, partitionID string, handler Handler, opts ...ReceiveOption) (ListenerHandle, error)
}
PartitionedReceiver provides the ability to receive messages from a given partition
type ReceiveOption ¶
type ReceiveOption func(receiver *receiver) error
ReceiveOption provides a structure for configuring receivers
func ReceiveFromTimestamp ¶ added in v1.1.0
func ReceiveFromTimestamp(t time.Time) ReceiveOption
ReceiveFromTimestamp configures the receiver to start receiving from a specific point in time in the event stream
func ReceiveWithConsumerGroup ¶
func ReceiveWithConsumerGroup(consumerGroup string) ReceiveOption
ReceiveWithConsumerGroup configures the receiver to listen to a specific consumer group
func ReceiveWithEpoch ¶
func ReceiveWithEpoch(epoch int64) ReceiveOption
ReceiveWithEpoch configures the receiver to use an epoch. Specifying an epoch for a receiver will cause any receiver with a lower epoch value to be disconnected from the message broker. If a receiver attempts to start with a lower epoch than the broker currently knows for a given partition, the broker will respond with an error on initiation of the receive request.
Ownership enforcement: Once you created an epoch based receiver, you cannot create a non-epoch receiver to the same consumer group / partition combo until all receivers to the combo are closed.
Ownership stealing: If a receiver with higher epoch value is created for a consumer group / partition combo, any older epoch receiver to that combo will be force closed.
func ReceiveWithLatestOffset ¶
func ReceiveWithLatestOffset() ReceiveOption
ReceiveWithLatestOffset configures the receiver to start at a given position in the event stream
func ReceiveWithPrefetchCount ¶
func ReceiveWithPrefetchCount(prefetch uint32) ReceiveOption
ReceiveWithPrefetchCount configures the receiver to attempt to fetch as many messages as the prefetch amount
func ReceiveWithStartingOffset ¶
func ReceiveWithStartingOffset(offset string) ReceiveOption
ReceiveWithStartingOffset configures the receiver to start at a given position in the event stream
type SendOption ¶
SendOption provides a way to customize a message on sending
func SendWithMessageID ¶
func SendWithMessageID(messageID string) SendOption
SendWithMessageID configures the message with a message ID
type Sender ¶
type Sender interface { Send(ctx context.Context, event *Event, opts ...SendOption) error SendBatch(ctx context.Context, batch *EventBatch, opts ...SendOption) error }
Sender provides the ability to send a messages
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
_examples
|
|
Package atom contains base data structures for use in the Azure Event Hubs management HTTP API
|
Package atom contains base data structures for use in the Azure Event Hubs management HTTP API |
Package eph provides functionality for balancing load of Event Hub receivers through scheduling receivers across processes and machines.
|
Package eph provides functionality for balancing load of Event Hub receivers through scheduling receivers across processes and machines. |
internal
|
|
test
Package test is an internal package to handle common test setup
|
Package test is an internal package to handle common test setup |
Package storage provides implementations for Checkpointer and Leaser from package eph for persisting leases and checkpoints for the Event Processor Host using Azure Storage as a durable store.
|
Package storage provides implementations for Checkpointer and Leaser from package eph for persisting leases and checkpoints for the Event Processor Host using Azure Storage as a durable store. |