Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add more params to dapr pubsub subscription #58

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,11 @@ type SyncRequest struct {
}

type Input struct {
Uri string `json:"uri,omitempty"`
ComponentName string `json:"componentName"`
ComponentType string `json:"componentType"`
Metadata map[string]string `json:"metadata,omitempty"`
Uri string `json:"uri,omitempty"`
ComponentName string `json:"componentName"`
ComponentType string `json:"componentType"`
Metadata map[string]string `json:"metadata,omitempty"`
PubSubRoutingRule *PubSubRoutingRule `json:"pubSubRoutingRule,omitempty"`
}

// GetType will be called after the context has been parsed correctly,
Expand Down Expand Up @@ -331,6 +332,12 @@ type TracingProvider struct {
OapServer string `json:"oapServer" yaml:"oapServer"`
}

type PubSubRoutingRule struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not define the router, match, and priority directly into the input?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I think it is more clear to group router, match, priority to the one struct PubSubRoutingRule, other than put them directly into the input

considering every prop. Uri, ComponentName, ComponentType, Metadata maybe different for different trigger,
of input in function context

type Input struct {
	Uri               string             `json:"uri,omitempty"`
	ComponentName     string             `json:"componentName"`
	ComponentType     string             `json:"componentType"`
	Metadata          map[string]string  `json:"metadata,omitempty"`
}

Route string `json:"route"`
Match string `json:"match"`
Priority int `json:"priority"`
}

type ResponseWriterWrapper struct {
http.ResponseWriter
statusCode int
Expand Down
5 changes: 5 additions & 0 deletions runtime/async/async.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ func (r *Runtime) RegisterOpenFunction(
PubsubName: input.ComponentName,
Topic: input.Uri,
}
if input.PubSubRoutingRule != nil && input.PubSubRoutingRule.Match != "" {
sub.Route = input.PubSubRoutingRule.Route
sub.Match = input.PubSubRoutingRule.Match
sub.Priority = input.PubSubRoutingRule.Priority
}
funcErr = r.handler.AddTopicEventHandler(sub, func(c context.Context, e *dapr.TopicEvent) (retry bool, err error) {
rm := runtime.NewRuntimeManager(ctx, prePlugins, postPlugins)
rm.FuncContext.SetEvent(name, e)
Expand Down