12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package subscriber
- import (
- "context"
- "fmt"
- "git.nspix.com/golang/micro/bus"
- "reflect"
- )
- type Memory struct {
- Id string
- topic string
- cb bus.HandleFunc
- }
- func (sub *Memory) ID() string {
- return sub.Id
- }
- func (sub *Memory) HasTopic(topic string) bool {
- return sub.topic == topic || sub.topic == "ALL"
- }
- func (sub *Memory) OnAttach() (err error) {
- return
- }
- func (sub *Memory) Process(ctx context.Context, e *bus.Event) (err error) {
- if sub.cb != nil {
- err = sub.cb(ctx, e)
- }
- return
- }
- func (sub *Memory) OnDetach() (err error) {
- return
- }
- func NewMemorySubscriber(topic string, cb bus.HandleFunc) *Memory {
- id := topic + ":" + fmt.Sprint(reflect.ValueOf(cb).Pointer())
- return &Memory{
- Id: id,
- topic: topic,
- cb: cb,
- }
- }
|