Skip to content

Commit 85cbbf1

Browse files
authored
Enable eventhubs binding to read all message properties (#3615)
Signed-off-by: yaron2 <[email protected]>
1 parent 913ba4c commit 85cbbf1

File tree

5 files changed

+32
-1
lines changed

5 files changed

+32
-1
lines changed

bindings/azure/eventhubs/metadata.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,12 @@ metadata:
161161
description: |
162162
Storage container name.
163163
example: '"myeventhubstoragecontainer"'
164+
- name: getAllMessageProperties
165+
required: false
166+
default: "false"
167+
example: "false"
168+
binding:
169+
input: true
170+
output: false
171+
description: |
172+
When set to true, will retrieve all message properties and include them in the returned event metadata

common/component/azure/eventhubs/eventhubs.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ func (aeh *AzureEventHubs) EventHubName() string {
127127
return aeh.metadata.hubName
128128
}
129129

130+
// GetAllMessageProperties returns a boolean to indicate whether to return all properties for an event hubs message.
131+
func (aeh *AzureEventHubs) GetAllMessageProperties() bool {
132+
return aeh.metadata.GetAllMessageProperties
133+
}
134+
130135
// Publish a batch of messages.
131136
func (aeh *AzureEventHubs) Publish(ctx context.Context, topic string, messages []*azeventhubs.EventData, batchOpts *azeventhubs.EventDataBatchOptions) error {
132137
// Get the producer client
@@ -165,7 +170,7 @@ func (aeh *AzureEventHubs) GetBindingsHandlerFunc(topic string, getAllProperties
165170
return nil, fmt.Errorf("expected 1 message, got %d", len(messages))
166171
}
167172

168-
bindingsMsg, err := NewBindingsReadResponseFromEventData(messages[0], topic, getAllProperties)
173+
bindingsMsg, err := NewBindingsReadResponseFromEventData(messages[0], topic, aeh.GetAllMessageProperties())
169174
if err != nil {
170175
return nil, fmt.Errorf("failed to get bindings read response from azure eventhubs message: %w", err)
171176
}

common/component/azure/eventhubs/metadata.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type AzureEventHubsMetadata struct {
3939
SubscriptionID string `json:"subscriptionID" mapstructure:"subscriptionID"`
4040
ResourceGroupName string `json:"resourceGroupName" mapstructure:"resourceGroupName"`
4141
EnableInOrderMessageDelivery bool `json:"enableInOrderMessageDelivery,string" mapstructure:"enableInOrderMessageDelivery"`
42+
GetAllMessageProperties bool `json:"getAllMessageProperties,string" mapstructure:"getAllMessageProperties"`
4243

4344
// Binding only
4445
EventHub string `json:"eventHub" mapstructure:"eventHub" mdonly:"bindings"`

pubsub/azure/eventhubs/eventhubs.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ func (aeh *AzureEventHubs) Subscribe(ctx context.Context, req pubsub.SubscribeRe
130130

131131
// Check if requireAllProperties is set and is truthy
132132
getAllProperties := utils.IsTruthy(req.Metadata["requireAllProperties"])
133+
if !getAllProperties {
134+
getAllProperties = aeh.GetAllMessageProperties()
135+
}
136+
133137
checkPointFrequencyPerPartition := commonutils.GetIntValFromString(req.Metadata["checkPointFrequencyPerPartition"], impl.DefaultCheckpointFrequencyPerPartition)
134138

135139
pubsubHandler := aeh.GetPubSubHandlerFunc(topic, getAllProperties, handler)
@@ -155,6 +159,9 @@ func (aeh *AzureEventHubs) BulkSubscribe(ctx context.Context, req pubsub.Subscri
155159

156160
// Check if requireAllProperties is set and is truthy
157161
getAllProperties := utils.IsTruthy(req.Metadata["requireAllProperties"])
162+
if !getAllProperties {
163+
getAllProperties = aeh.GetAllMessageProperties()
164+
}
158165
checkPointFrequencyPerPartition := commonutils.GetIntValFromString(req.Metadata["checkPointFrequencyPerPartition"], impl.DefaultCheckpointFrequencyPerPartition)
159166
maxBulkSubCount := commonutils.GetIntValOrDefault(req.BulkSubscribeConfig.MaxMessagesCount, impl.DefaultMaxBulkSubCount)
160167
maxBulkSubAwaitDurationMs := commonutils.GetIntValOrDefault(req.BulkSubscribeConfig.MaxAwaitDurationMs, impl.DefaultMaxBulkSubAwaitDurationMs)

pubsub/azure/eventhubs/metadata.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,12 @@ metadata:
110110
description: |
111111
The name of the Event Hubs Consumer Group to listen on.
112112
example: '"group1"'
113+
- name: getAllMessageProperties
114+
required: false
115+
default: "false"
116+
example: "false"
117+
binding:
118+
input: true
119+
output: false
120+
description: |
121+
When set to true, will retrieve all message properties and include them in the returned event metadata

0 commit comments

Comments
 (0)