@@ -21,6 +21,12 @@ type HandlersChain []HandlerFunc
21
21
22
22
type OptionFunc func (* Engine )
23
23
24
+ func WithForcedPublicationSource (s string ) OptionFunc {
25
+ return func (e * Engine ) {
26
+ e .forcedPublicationSource = s
27
+ }
28
+ }
29
+
24
30
func WithForcedPublicationFormat (f format.Format ) OptionFunc {
25
31
return func (e * Engine ) {
26
32
e .forcedPublicationFormat = f
@@ -33,12 +39,12 @@ func WithForcedSubscriptionFormat(f format.Format) OptionFunc {
33
39
}
34
40
}
35
41
36
- func New (d Driver , opts ... OptionFunc ) * Engine {
42
+ func New (driver Driver , opts ... OptionFunc ) * Engine {
37
43
engine := & Engine {
38
44
RouterGroup : RouterGroup {
39
45
root : true ,
40
46
},
41
- driver : d ,
47
+ driver : driver ,
42
48
tree : make (subsTree ),
43
49
consumers : make (map [* Consumer ]struct {}),
44
50
subscriptionActiveWorkersMap : make (map [* subscription ]map [* worker ]struct {}),
@@ -68,6 +74,7 @@ type Engine struct {
68
74
RouterGroup
69
75
70
76
driver Driver
77
+ forcedPublicationSource string
71
78
forcedPublicationFormat format.Format
72
79
forcedSubscriptionFormat format.Format
73
80
@@ -126,6 +133,9 @@ func (e *Engine) newContext() *Context {
126
133
}
127
134
128
135
func (e * Engine ) Publish (ctx context.Context , topic string , event event.Event ) error {
136
+ if e .forcedPublicationSource != "" {
137
+ event .SetSource (e .forcedPublicationSource )
138
+ }
129
139
if err := event .Validate (); err != nil {
130
140
return err
131
141
}
0 commit comments