@@ -26,23 +26,34 @@ func (c *ChipIngressEmitter) Close() error {
2626}
2727
2828func (c * ChipIngressEmitter ) Emit (ctx context.Context , body []byte , attrKVs ... any ) error {
29+ return c .BatchEmit (ctx , Message {
30+ Body : body ,
31+ Attrs : ExtractAttributes (attrKVs ... ),
32+ })
33+ }
2934
30- sourceDomain , entityType , err := ExtractSourceAndType (attrKVs ... )
31- if err != nil {
32- return err
33- }
35+ func (c * ChipIngressEmitter ) BatchEmit (ctx context.Context , messages ... Message ) error {
36+ events := make ([]chipingress.CloudEvent , len (messages ))
37+ for i , msg := range messages {
38+ sourceDomain , entityType , err := ExtractSourceAndType (msg .Attrs )
39+ if err != nil {
40+ return err
41+ }
3442
35- event , err := chipingress .NewEvent (sourceDomain , entityType , body , newAttributes (attrKVs ... ))
36- if err != nil {
37- return err
43+ event , err := chipingress .NewEvent (sourceDomain , entityType , msg .Body , msg .Attrs )
44+ if err != nil {
45+ return err
46+ }
47+
48+ events [i ] = event
3849 }
3950
40- eventPb , err := chipingress .EventToProto ( event )
51+ eventPb , err := chipingress .EventsToBatch ( events )
4152 if err != nil {
4253 return fmt .Errorf ("failed to convert event to proto: %w" , err )
4354 }
4455
45- _ , err = c .client .Publish (ctx , eventPb )
56+ _ , err = c .client .PublishBatch (ctx , eventPb )
4657 if err != nil {
4758 return err
4859 }
@@ -51,10 +62,7 @@ func (c *ChipIngressEmitter) Emit(ctx context.Context, body []byte, attrKVs ...a
5162}
5263
5364// ExtractSourceAndType extracts source domain and entity from the attributes
54- func ExtractSourceAndType (attrKVs ... any ) (string , string , error ) {
55-
56- attributes := newAttributes (attrKVs ... )
57-
65+ func ExtractSourceAndType (attributes Attributes ) (string , string , error ) {
5866 var sourceDomain string
5967 var entityType string
6068
0 commit comments