diff --git a/.chloggen/eventhubreceiver-allow-consumer-group-in-configuration.yaml b/.chloggen/eventhubreceiver-allow-consumer-group-in-configuration.yaml new file mode 100644 index 000000000000..bc9a24894d38 --- /dev/null +++ b/.chloggen/eventhubreceiver-allow-consumer-group-in-configuration.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: azureevenhubreceiver + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Allow the Consumer Group to be set in the Configuration. + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [28633] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] diff --git a/receiver/azureeventhubreceiver/README.md b/receiver/azureeventhubreceiver/README.md index 18bce791caf2..f2c056eae603 100644 --- a/receiver/azureeventhubreceiver/README.md +++ b/receiver/azureeventhubreceiver/README.md @@ -26,6 +26,9 @@ Event Hub, transforms them, and pushes them through the collector pipeline. ### connection (Required) A string describing the connection to an Azure event hub. +### group (Optional) +The Consumer Group to read from. If empty will default to the default Consumer Group $Default + ### partition (Optional) The partition to watch. If empty, it will watch explicitly all partitions. @@ -49,6 +52,7 @@ receivers: azureeventhub: connection: Endpoint=sb://namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=superSecret1234=;EntityPath=hubName partition: foo + group: bar offset: "1234-5566" format: "azure" ``` diff --git a/receiver/azureeventhubreceiver/config.go b/receiver/azureeventhubreceiver/config.go index ac55f2d836fe..9ccb99205fc8 100644 --- a/receiver/azureeventhubreceiver/config.go +++ b/receiver/azureeventhubreceiver/config.go @@ -25,11 +25,12 @@ var ( ) type Config struct { - Connection string `mapstructure:"connection"` - Partition string `mapstructure:"partition"` - Offset string `mapstructure:"offset"` - StorageID *component.ID `mapstructure:"storage"` - Format string `mapstructure:"format"` + Connection string `mapstructure:"connection"` + Partition string `mapstructure:"partition"` + Offset string `mapstructure:"offset"` + StorageID *component.ID `mapstructure:"storage"` + Format string `mapstructure:"format"` + ConsumerGroup string `mapstructure:"group"` } func isValidFormat(format string) bool { diff --git a/receiver/azureeventhubreceiver/eventhubhandler.go b/receiver/azureeventhubreceiver/eventhubhandler.go index e928e3d9dc05..dc25fecaf6b1 100644 --- a/receiver/azureeventhubreceiver/eventhubhandler.go +++ b/receiver/azureeventhubreceiver/eventhubhandler.go @@ -131,12 +131,18 @@ func (h *eventhubHandler) run(ctx context.Context, host component.Host) error { func (h *eventhubHandler) setUpOnePartition(ctx context.Context, partitionID string, applyOffset bool) error { - offsetOption := eventhub.ReceiveWithLatestOffset() + receiverOptions := []eventhub.ReceiveOption{} if applyOffset && h.config.Offset != "" { - offsetOption = eventhub.ReceiveWithStartingOffset(h.config.Offset) + receiverOptions = append(receiverOptions, eventhub.ReceiveWithStartingOffset(h.config.Offset)) + } else { + receiverOptions = append(receiverOptions, eventhub.ReceiveWithLatestOffset()) + } + + if h.config.ConsumerGroup != "" { + receiverOptions = append(receiverOptions, eventhub.ReceiveWithConsumerGroup(h.config.ConsumerGroup)) } - handle, err := h.hub.Receive(ctx, partitionID, h.newMessageHandler, offsetOption) + handle, err := h.hub.Receive(ctx, partitionID, h.newMessageHandler, receiverOptions...) if err != nil { return err }