-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds support for having Pub/Sub handlers that reference a method on a service struct.
- Loading branch information
Showing
16 changed files
with
492 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
run | ||
publish pointer '{"Data": "test"}' | ||
publish non-pointer '{"Data": "test"}' | ||
checklog '{"topic": "pointer", "subscription": "pointer", "event": {"Data": "test"}, "message": "pointer method"}' | ||
checklog '{"topic": "non-pointer", "subscription": "non-pointer", "event": {"Data": "test"}, "message": "non-pointer method"}' | ||
|
||
|
||
-- svc/svc.go -- | ||
package svc | ||
|
||
import ( | ||
"context" | ||
"encore.dev/rlog" | ||
"encore.dev/pubsub" | ||
) | ||
|
||
//encore:service | ||
type Service struct{} | ||
|
||
func (s *Service) PointerMethod(ctx context.Context, event *Event) error { | ||
rlog.Info("pointer method", "event", event) | ||
return nil | ||
} | ||
|
||
func (s Service) NonPointerMethod(ctx context.Context, event *Event) error { | ||
rlog.Info("non-pointer method", "event", event) | ||
return nil | ||
} | ||
|
||
type Event struct { | ||
Data string | ||
} | ||
|
||
var Pointer = pubsub.NewTopic[*Event]("pointer", pubsub.TopicConfig{ | ||
DeliveryGuarantee: pubsub.AtLeastOnce, | ||
}) | ||
|
||
var NonPointer = pubsub.NewTopic[*Event]("non-pointer", pubsub.TopicConfig{ | ||
DeliveryGuarantee: pubsub.AtLeastOnce, | ||
}) | ||
|
||
var _ = pubsub.NewSubscription(Pointer, "pointer", | ||
pubsub.SubscriptionConfig[*Event]{ | ||
Handler: pubsub.MethodHandler((*Service).PointerMethod), | ||
}, | ||
) | ||
|
||
var _ = pubsub.NewSubscription(NonPointer, "non-pointer", | ||
pubsub.SubscriptionConfig[*Event]{ | ||
Handler: pubsub.MethodHandler(Service.NonPointerMethod), | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.