@@ -416,20 +416,23 @@ func (s *Server) AddBulkTopicEventHandler(sub *common.Subscription, fn common.Bu
416
416
return
417
417
}
418
418
419
- entriesInterface , ok := ins ["entries" ].([]interface {})
419
+ entriesInterface , ok := ins ["entries" ].([]interface {})
420
420
if ! ok {
421
421
// Handle the error or return an error response
422
422
http .Error (w , "Entries format error" , PubSubHandlerDropStatusCode )
423
423
return
424
424
}
425
425
426
+ statuses := make ([]BulkSubscribeResponseEntry , 0 , len (entriesInterface ))
427
+
426
428
var messages []common.BulkTopic
427
429
for _ , entry := range entriesInterface {
428
430
itemMap , ok := entry .(map [string ]interface {})
429
431
if ! ok {
430
432
http .Error (w , "Entry format error" , PubSubHandlerDropStatusCode )
431
433
return
432
434
}
435
+
433
436
itemJSON , err := json .Marshal (itemMap ["event" ])
434
437
if err != nil {
435
438
http .Error (w , err .Error (), PubSubHandlerDropStatusCode )
@@ -443,6 +446,7 @@ func (s *Server) AddBulkTopicEventHandler(sub *common.Subscription, fn common.Bu
443
446
}
444
447
data , rawData := item .getData ()
445
448
449
+
446
450
if item .PubsubName == "" {
447
451
item .PubsubName = sub .PubsubName
448
452
}
@@ -451,6 +455,11 @@ func (s *Server) AddBulkTopicEventHandler(sub *common.Subscription, fn common.Bu
451
455
item .Topic = sub .Topic
452
456
}
453
457
458
+ statuses = append (statuses , BulkSubscribeResponseEntry {
459
+ entryId : item .EntryID ,
460
+ status : SubscriptionResponseStatusSuccess ,
461
+ },
462
+ )
454
463
455
464
newItem := common.BulkTopic {
456
465
ContentType : item .ContentType ,
@@ -473,11 +482,17 @@ func (s *Server) AddBulkTopicEventHandler(sub *common.Subscription, fn common.Bu
473
482
474
483
messages = append (messages , newItem )
475
484
}
476
-
485
+ resp := BulkSubscribeResponse {
486
+ statuses : statuses ,
487
+ }
488
+ responseJSON , err := json .Marshal (resp )
489
+ if err != nil {
490
+ http .Error (w , err .Error (), PubSubHandlerDropStatusCode )
491
+ return
492
+ }
477
493
w .Header ().Add ("Content-Type" , "application/json" )
478
- w .WriteHeader ( http . StatusOK )
494
+ w .Write ( responseJSON )
479
495
480
- // execute user handler
481
496
retry , err := fn (r .Context (), messages )
482
497
if err == nil {
483
498
writeStatus (w , common .SubscriptionResponseStatusSuccess )
@@ -488,7 +503,6 @@ func (s *Server) AddBulkTopicEventHandler(sub *common.Subscription, fn common.Bu
488
503
writeStatus (w , common .SubscriptionResponseStatusRetry )
489
504
return
490
505
}
491
-
492
506
writeStatus (w , common .SubscriptionResponseStatusDrop )
493
507
})))
494
508
0 commit comments