diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 13566b8..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/cmd/mercurius-client/publisher-client/mercurius-client.go b/cmd/mercurius-client/publisher-client/mercurius-client.go index 4c750ec..c25b236 100644 --- a/cmd/mercurius-client/publisher-client/mercurius-client.go +++ b/cmd/mercurius-client/publisher-client/mercurius-client.go @@ -8,6 +8,8 @@ import ( "sync/atomic" "time" + "github.com/google/uuid" + logger2 "github.com/ispiroglu/mercurius/internal/logger" "github.com/ispiroglu/mercurius/pkg/client" "go.uber.org/zap" @@ -23,15 +25,17 @@ var N = 100 * 100 var start time.Time func main() { - c, err := client.NewClient(CLIENT_NAME, ADDR) + id, _ := uuid.NewUUID() + c, err := client.NewClient(id, ADDR) if err != nil { logger.Error("Err", zap.Error(err)) } logger.Info("Published Event") - + var z time.Duration wg := sync.WaitGroup{} wg.Add(N) + uintN := uint64(N) for i := 0; i < N; i++ { go func(w *sync.WaitGroup) { for j := 0; j < 1; j++ { @@ -43,19 +47,19 @@ func main() { start = time.Now() } fmt.Println(x) - if x == 1000*1000 { - z := time.Since(start) - fmt.Println("Execution time: ", z) + if x == uintN { + z = time.Since(start) } fmt.Println(strconv.FormatUint(x, 10)) //time.Sleep(time.Millisecond) } w.Done() }(&wg) - //time.Sleep(200 * time.Second) } wg.Wait() + fmt.Println("Execution time: ", z) + } // package main diff --git a/cmd/mercurius-client/subscriber-client/mercurius-client-sub.go b/cmd/mercurius-client/subscriber-client/mercurius-client-sub.go index 6938ae0..528860d 100644 --- a/cmd/mercurius-client/subscriber-client/mercurius-client-sub.go +++ b/cmd/mercurius-client/subscriber-client/mercurius-client-sub.go @@ -6,6 +6,8 @@ import ( "sync/atomic" "time" + "github.com/google/uuid" + k "github.com/ispiroglu/mercurius/internal/logger" "github.com/ispiroglu/mercurius/pkg/client" "github.com/ispiroglu/mercurius/proto" @@ -15,7 +17,8 @@ import ( const ADDR = "0.0.0.0:9000" const TopicName = "one-to-one" const CLIENT_NAME = "Sample Client" -const N = 100 * 100 * 100 +const subCount = 100 +const N = 100 * 100 * subCount var messageCount = atomic.Uint64{} var start = time.Time{} @@ -24,12 +27,14 @@ var ctx, _ = context.WithCancel(context.Background()) var ch = make(chan struct{}) func main() { - c, err := client.NewClient(CLIENT_NAME, ADDR) - if err != nil { - logger.Error("Err", zap.Error(err)) - } - for i := 0; i < 100; i++ { + + for i := 0; i < subCount; i++ { go func() { + id, _ := uuid.NewUUID() + c, err := client.NewClient(id, ADDR) + if err != nil { + logger.Error("Err", zap.Error(err)) + } if err := c.Subscribe(TopicName, ctx, handler); err != nil { logger.Error("Err", zap.Error(err)) } @@ -45,7 +50,7 @@ func handler(e *proto.Event) error { if x == 1 { start = time.Now() } - fmt.Println(x) + // fmt.Println(string(e.Body)) if x == N { z := time.Since(start) fmt.Println("Execution time: ", z) diff --git a/cmd/mercurius/mercurius.go b/cmd/mercurius/mercurius.go index 7152126..8fb62f0 100644 --- a/cmd/mercurius/mercurius.go +++ b/cmd/mercurius/mercurius.go @@ -3,13 +3,14 @@ package main import ( "net" + "net/http" + "github.com/ispiroglu/mercurius/internal/logger" sv "github.com/ispiroglu/mercurius/internal/server" "github.com/ispiroglu/mercurius/proto" "github.com/prometheus/client_golang/prometheus/promhttp" "go.uber.org/zap" "google.golang.org/grpc" - "net/http" ) const ADDR = "0.0.0.0:9000" diff --git a/internal/broker/broker.go b/internal/broker/broker.go index 44e97b0..58984d5 100644 --- a/internal/broker/broker.go +++ b/internal/broker/broker.go @@ -30,8 +30,6 @@ func NewBroker() *Broker { } func (b *Broker) Publish(event *pb.Event) (*pb.ACK, error) { - //b.logger.Info("Broker received event for publishing", zap.String("Topic", event.Topic)) - t, err := b.findOrInsertTopic(event.Topic) if err != nil { return nil, err @@ -41,9 +39,14 @@ func (b *Broker) Publish(event *pb.Event) (*pb.ACK, error) { return &pb.ACK{}, nil } -func (b *Broker) Subscribe(ctx context.Context, topicName string, sId string, sName string) (*Subscriber, error) { - b.logger.Info("Broker received subscription request", zap.String("Topic", topicName), zap.String("SubscriberID", sId)) +func (b *Broker) Unsubscribe(sub *Subscriber) { + b.TopicRepository.Unsubscribe(sub) + if err := b.SubscriberRepository.Unsubscribe(sub); err != nil { + b.logger.Warn("Failed to unsubscribe subscriber", zap.String("SubscriberID", sub.Id), zap.String("Subscriber Name", sub.Name), zap.Error(err)) + } +} +func (b *Broker) Subscribe(ctx context.Context, topicName string, sId string, sName string) (*Subscriber, error) { t, err := b.findOrInsertTopic(topicName) if err != nil { return nil, err @@ -51,33 +54,23 @@ func (b *Broker) Subscribe(ctx context.Context, topicName string, sId string, sN s, err := t.AddSubscriber(ctx, sId, sName) if err != nil { - b.logger.Error("Broker could not add subscriber to topic", zap.String("Topic", topicName), zap.String("SubscriberID", sId)) //, zap.Error(err)) + b.logger.Error("Broker could not add subscriber to topic", zap.String("Topic", topicName), zap.String("SubscriberID", sId), zap.Error(err)) return nil, err } - go b.SubscriberRepository.addSub(s) return s, nil } -func (b *Broker) Unsubscribe(sub *Subscriber) { - b.logger.Info("Unsubscribing", zap.String("ID", sub.Id), zap.String("Subscriber Name", sub.Name)) - b.TopicRepository.Unsubscribe(sub) - b.SubscriberRepository.Lock() - delete(b.SubscriberRepository.Subscribers, sub.Id) - b.SubscriberRepository.Unlock() -} - func (b *Broker) findOrInsertTopic(topicName string) (*Topic, error) { t, err := b.GetTopic(topicName) if err != nil { - b.logger.Info("Broker cannot found the topic to subscribe", zap.String("Topic", topicName)) //, zap.Error(err)) t, err = b.CreateTopic(topicName) - - st, ok := status.FromError(err) - if !ok && st.Code() != codes.AlreadyExists { - b.logger.Error("Broker cannot create topic", zap.String("Topic", topicName)) //, zap.Error(err), zap.Bool("A", st.Code() != codes.AlreadyExists), zap.String("Code", st.String())) - return nil, err - } else if st.Code() == codes.AlreadyExists { - t, _ = b.GetTopic(topicName) + if err != nil { + st, ok := status.FromError(err) + if !ok && st.Code() != codes.AlreadyExists { + return nil, err + } else if st.Code() == codes.AlreadyExists { + t, _ = b.GetTopic(topicName) + } } } diff --git a/internal/broker/stream_pool.go b/internal/broker/stream_pool.go new file mode 100644 index 0000000..88ba51d --- /dev/null +++ b/internal/broker/stream_pool.go @@ -0,0 +1,37 @@ +package broker + +import ( + "github.com/ispiroglu/mercurius/proto" + "sync" +) + +type StreamPool struct { + SubscriberName string + Streams []*Subscriber + Ch chan *proto.Event + sync.Mutex +} + +func newStreamPool(name string) *StreamPool { + + return &StreamPool{ + SubscriberName: name, + Streams: make([]*Subscriber, 0), + Ch: make(chan *proto.Event), + Mutex: sync.Mutex{}, + } +} + +func (p *StreamPool) AddSubscriber(s *Subscriber) { + p.Lock() + defer p.Unlock() + + p.Streams = append(p.Streams, s) + go s.worker(p.Ch) +} + +func (s *Subscriber) worker(ch chan *proto.Event) { + for e := range ch { + s.EventChannel <- e + } +} diff --git a/internal/broker/subscriber.go b/internal/broker/subscriber.go index 17840b5..dc67dad 100644 --- a/internal/broker/subscriber.go +++ b/internal/broker/subscriber.go @@ -2,21 +2,23 @@ package broker import ( "context" - "sync" - - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" + "fmt" + "sync/atomic" + "time" "github.com/ispiroglu/mercurius/internal/logger" "github.com/ispiroglu/mercurius/proto" "go.uber.org/zap" ) -type SubscriberRepository struct { - sync.RWMutex - logger *zap.Logger - Subscribers map[string]*Subscriber -} +const totalEventCount = 100 * 100 * 100 +const channelSize = 1 + +// const subscriberBulkEventCount = 100 * 100 +const subscriberBulkEventCount = 1 + +var messageCount = atomic.Uint64{} +var _start time.Time type Subscriber struct { logger *zap.Logger @@ -28,52 +30,54 @@ type Subscriber struct { Ctx context.Context } -func (r *SubscriberRepository) Unsubscribe(subscriber *Subscriber) error { - r.Lock() - defer r.Unlock() - - if _, ok := r.Subscribers[subscriber.Id]; !ok { - return status.Error(codes.NotFound, "Cannot found subscriber at repository.") - } - - delete(r.Subscribers, subscriber.Id) - return nil -} - func NewSubscriber(ctx context.Context, sId string, sName string, topicName string) *Subscriber { - eq := make(chan *proto.Event) + // This channel size should be configurable. + eventChannel := make(chan *proto.Event, channelSize) return &Subscriber{ logger: logger.NewLogger(), Id: sId, Name: sName, - EventChannel: eq, - RetryQueue: SubscriberRetryHandler.CreateRetryQueue(sId, eq), + EventChannel: eventChannel, + RetryQueue: SubscriberRetryHandler.CreateRetryQueue(sId, eventChannel), TopicName: topicName, Ctx: ctx, } } -func NewSubscriberRepository() *SubscriberRepository { - return &SubscriberRepository{ - logger: logger.NewLogger(), - Subscribers: map[string]*Subscriber{}, +func (s *Subscriber) HandleBulkEvent(stream proto.Mercurius_SubscribeServer) error { + eventBuffer := make([]*proto.Event, 0, subscriberBulkEventCount) + for { + select { + case <-s.Ctx.Done(): + return nil + case event := <-s.EventChannel: + checkSentEventCount() + eventBuffer = append(eventBuffer, event) + if len(eventBuffer) == subscriberBulkEventCount { + bulkEvent := &proto.BulkEvent{ + EventList: eventBuffer, + } + s.sendEvent(bulkEvent, stream) + eventBuffer = eventBuffer[:0] + } + } } } -func (r *SubscriberRepository) addSubscriber(ctx context.Context, id string, subName string, topicName string) (*Subscriber, error) { - r.Lock() - defer r.Unlock() - if r.Subscribers[id] != nil { - return nil, status.Error(codes.AlreadyExists, "Already Exists") +func (s *Subscriber) sendEvent(bulkEvent *proto.BulkEvent, stream proto.Mercurius_SubscribeServer) { + if err := stream.Send(bulkEvent); err != nil { + s.logger.Error("Error on sending event", zap.String("Error: ", err.Error()), zap.String("SubscriberID", s.Id), zap.String("Subscriber Name", s.Name)) //, zap.Error(err)) + // sub.RetryQueue <- event } - - s := NewSubscriber(ctx, id, subName, topicName) - r.Subscribers[id] = s - return s, nil } -func (r *SubscriberRepository) addSub(s *Subscriber) { - r.Lock() - defer r.Unlock() - r.Subscribers[s.Id] = s +func checkSentEventCount() { + x := messageCount.Add(1) + if x == 1 { + _start = time.Now() + } + if x == totalEventCount { + z := time.Since(_start) + fmt.Println("Total stream send time: ", z) + } } diff --git a/internal/broker/subscriber_repository.go b/internal/broker/subscriber_repository.go new file mode 100644 index 0000000..f95afda --- /dev/null +++ b/internal/broker/subscriber_repository.go @@ -0,0 +1,49 @@ +package broker + +import ( + "context" + "sync" + "sync/atomic" + + "github.com/ispiroglu/mercurius/internal/logger" + "go.uber.org/zap" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +type SubscriberRepository struct { + logger *zap.Logger + StreamPools sync.Map + poolCount atomic.Uint32 +} + +func NewSubscriberRepository() *SubscriberRepository { + return &SubscriberRepository{ + logger: logger.NewLogger(), + StreamPools: sync.Map{}, + } +} + +func (r *SubscriberRepository) Unsubscribe(subscriber *Subscriber) error { + + if _, ok := r.StreamPools.Load(subscriber.Id); !ok { + return status.Error(codes.NotFound, "Cannot found subscriber at repository.") + } + + r.StreamPools.Delete(subscriber.Id) + r.poolCount.Store( + r.poolCount.Load() - 1, + ) + return nil +} + +func (r *SubscriberRepository) addSubscriber(ctx context.Context, id string, subName string, topicName string) (*Subscriber, error) { + + // Handle subName conflict? + s := NewSubscriber(ctx, id, subName, topicName) + pool, _ := r.StreamPools.LoadOrStore(subName, newStreamPool(subName)) + + pool.(*StreamPool).AddSubscriber(s) + r.poolCount.Add(1) + return s, nil +} diff --git a/internal/broker/topic.go b/internal/broker/topic.go index 6e19cab..b9ba02b 100644 --- a/internal/broker/topic.go +++ b/internal/broker/topic.go @@ -4,11 +4,12 @@ import ( "context" "fmt" "sync" + "sync/atomic" + "time" "github.com/ispiroglu/mercurius/internal/logger" - "go.uber.org/zap" - "github.com/ispiroglu/mercurius/proto" + "go.uber.org/zap" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) @@ -21,65 +22,28 @@ type Topic struct { EventChan chan *proto.Event } -type TopicRepository struct { - sync.RWMutex - logger *zap.Logger - Topics map[string]*Topic -} - -type ITopicRepository interface { - GetTopic(string) (*Topic, error) - CreateTopic(string) (*Topic, error) - PublishEvent(*proto.Event) - AddSubscriber(context.Context, string, string) error -} - -func NewTopicRepository() *TopicRepository { - return &TopicRepository{ - logger: logger.NewLogger(), - Topics: map[string]*Topic{}, - } -} - -func (r *TopicRepository) GetTopic(name string) (*Topic, error) { - topic, exist := r.Topics[name] - if !exist { - r.logger.Warn("Could not found topic", zap.String("Topic", name)) - return nil, status.Error(codes.NotFound, "cannot found the topic called:"+name) - } - - return topic, nil -} - -func (r *TopicRepository) CreateTopic(name string) (*Topic, error) { - r.Lock() - defer r.Unlock() - - _, err := r.GetTopic(name) - if err == nil { - r.logger.Warn("Cannot create the topic that already exists", zap.String("Topic", name)) - return nil, status.Error(codes.AlreadyExists, "there is already a topic named:"+name) - } - - r.logger.Info("Creating topic", zap.String("Topic", name)) - createdTopic := newTopic(name) - r.Topics[name] = createdTopic - return createdTopic, nil -} +var publishCount = uint32(100 * 100) +var publish = atomic.Uint32{} +var start time.Time func (t *Topic) PublishEvent(event *proto.Event) { - - if len(t.SubscriberRepository.Subscribers) == 0 { + if t.SubscriberRepository.poolCount.Load() == 0 { t.EventChan <- event } else { - t.SubscriberRepository.Lock() - defer t.SubscriberRepository.Unlock() - for _, s := range t.SubscriberRepository.Subscribers { - //go func(s *Subscriber, event *proto.Event) { - //s.logger.Info("Sending event to subscriber", zap.String("Topic", event.Topic), zap.String("SubscriberID", s.Id), zap.String("Subscriber name", s.Name)) - s.EventChannel <- event - //}(s, event) + publish.Add(1) + + if publish.Load() == uint32(1) { + start = time.Now() + } + + if publish.Load() == publishCount { + fmt.Println("Total Routing Time: ", time.Since(start)) } + + t.SubscriberRepository.StreamPools.Range(func(k any, v interface{}) bool { + v.(*StreamPool).Ch <- event + return true + }) } } @@ -92,30 +56,9 @@ func (t *Topic) AddSubscriber(ctx context.Context, id string, name string) (*Sub return nil, status.Error(codes.AlreadyExists, errorMessage) } - t.logger.Info("Added subscriber", zap.String("Topic", t.Name), zap.String("sId", id), zap.String("sName", name)) - if len(t.SubscriberRepository.Subscribers) == 1 { - // go func() { - if len(t.EventChan) != 0 { - for event := range t.EventChan { - s.logger.Info("Sending event to subscriber", zap.String("TopicName", event.Topic), zap.String("SubscriberID", s.Id), zap.String("Subscriber name", s.Name)) - s.EventChannel <- event - } - } - //}() - } - return s, nil } -func (r *TopicRepository) Unsubscribe(subscriber *Subscriber) { - t := subscriber.TopicName - if err := r.Topics[t].SubscriberRepository.Unsubscribe(subscriber); err == nil { - r.logger.Info("Unsubscription has done", - zap.String("TopicName Name", t), - zap.String("Subscription ID", subscriber.Id)) - } -} - func newTopic(name string) *Topic { return &Topic{ logger: logger.NewLogger(), diff --git a/internal/broker/topic_repository.go b/internal/broker/topic_repository.go new file mode 100644 index 0000000..b1a12d4 --- /dev/null +++ b/internal/broker/topic_repository.go @@ -0,0 +1,55 @@ +package broker + +import ( + "sync" + + "github.com/ispiroglu/mercurius/internal/logger" + "go.uber.org/zap" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +type TopicRepository struct { + logger *zap.Logger + Topics sync.Map +} + +func NewTopicRepository() *TopicRepository { + return &TopicRepository{ + logger: logger.NewLogger(), + Topics: sync.Map{}, + } +} + +func (r *TopicRepository) GetTopic(name string) (*Topic, error) { + topic, exist := r.Topics.Load(name) + if !exist { + // r.logger.Warn("Could not found topic", zap.String("Topic", name)) + return nil, status.Error(codes.NotFound, "cannot found the topic called:"+name) + } + + return topic.(*Topic), nil +} + +func (r *TopicRepository) CreateTopic(name string) (*Topic, error) { + if _, err := r.GetTopic(name); err == nil { + // r.logger.Warn("Cannot create the topic that already exists", zap.String("Topic", name)) + return nil, status.Error(codes.AlreadyExists, "there is already a topic named:"+name) + } + + createdTopic := newTopic(name) + r.Topics.Store(name, createdTopic) + + return createdTopic, nil +} + +func (r *TopicRepository) Unsubscribe(subscriber *Subscriber) { + topic, err := r.GetTopic(subscriber.TopicName) + if err != nil { + panic(err) + } + + if err := topic.SubscriberRepository.Unsubscribe(subscriber); err != nil { + r.logger.Warn("", zap.Error(err)) + } +} diff --git a/internal/server/server.go b/internal/server/server.go index b226b62..0beb52c 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -12,7 +12,8 @@ import ( "go.uber.org/zap" ) -const xz = 100 * 100 * 100 +var eventCount = atomic.Uint64{} +var startTime time.Time type Server struct { logger *zap.Logger @@ -28,12 +29,8 @@ func NewMercuriusServer() *Server { } } -var y = atomic.Uint64{} - func (s *Server) Publish(_ context.Context, event *proto.Event) (*proto.ACK, error) { - if y.Add(1) == 1 { - start = time.Now() - } + checkPublishEventCount() return s.broker.Publish(event) } @@ -45,85 +42,17 @@ func (s *Server) Subscribe(req *proto.SubscribeRequest, stream proto.Mercurius_S return err } - for w := 0; w < 1; w++ { - go consumerTask(stream, sub, s.logger) - } - - cc := make(chan struct{}) - <-cc - - /* for { - - select { - case <-sub.Ctx.Done(): - - broker.SubscriberRetryHandler.RemoveRetryQueue(sub.Id) - go func(sub *broker.Subscriber) { - // s.broker.Unsubscribe(sub) - runtime.GC() - }(sub) - - return nil - case event := <-sub.EventChannel: - - // time.Sleep(4 * time.Second) - go func() { - // Send isleminde kalan var - if err := stream.Send(event); err != nil { - panic("") - s.logger.Error("Error on sending event", zap.String("TopicName", event.Topic), zap.String("SubscriberID", sub.Id), zap.String("Subscriber Name", sub.Name)) //, zap.Error(err)) - s.logger.Info("Sending event to retry queue") - sub.RetryQueue <- event - } - - x := messageCount.Add(1) - - if x == 100*100*100 { - z := time.Since(start) - fmt.Println("Execution time: ", z) - } - }() - } - } */ - - return nil + err = sub.HandleBulkEvent(stream) + return err } -func (s *Server) Retry(_ context.Context, req *proto.RetryRequest) (*proto.ACK, error) { - s.logger.Info("Received retry request") - s.broker.SubscriberRepository.Subscribers[req.SubscriberID].RetryQueue <- req.Event - return &proto.ACK{}, nil -} - -var messageCount = atomic.Uint64{} -var start time.Time - -func consumerTask(stream proto.Mercurius_SubscribeServer, sub *broker.Subscriber, logger *zap.Logger) { - for { - - select { - case <-sub.Ctx.Done(): - - broker.SubscriberRetryHandler.RemoveRetryQueue(sub.Id) - go func(sub *broker.Subscriber) { - // s.broker.Unsubscribe(sub) - }(sub) - - return - case event := <-sub.EventChannel: - go func() { - if err := stream.Send(event); err != nil { - logger.Error("Error on sending event", zap.String("TopicName", event.Topic), zap.String("SubscriberID", sub.Id), zap.String("Subscriber Name", sub.Name)) //, zap.Error(err)) - logger.Info("Sending event to retry queue") - sub.RetryQueue <- event - } - x := messageCount.Add(1) +func checkPublishEventCount() { + if eventCount.Add(1) == 1 { + startTime = time.Now() + } - if x == xz { - z := time.Since(start) - fmt.Println("Execution time: ", z) - } - }() - } + if eventCount.Load() == uint64(100*100) { + elapsedTime := time.Since(startTime) + fmt.Println("Elapsed time since the start of events:", elapsedTime) } } diff --git a/mercurius b/mercurius deleted file mode 100755 index d933601..0000000 Binary files a/mercurius and /dev/null differ diff --git a/pkg/client/client.go b/pkg/client/client.go index 21dd892..2f346f3 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -4,26 +4,29 @@ import ( "context" "errors" "fmt" + "sync/atomic" "github.com/google/uuid" "github.com/ispiroglu/mercurius/internal/logger" "github.com/ispiroglu/mercurius/pkg/serialize" "github.com/ispiroglu/mercurius/proto" - "go.uber.org/zap" + "google.golang.org/protobuf/types/known/timestamppb" ) type Client struct { - Name string - c proto.MercuriusClient - s *serialize.Serializer + id uuid.UUID + c proto.MercuriusClient + s *serialize.Serializer } +const streamPerSubscriber int = 20 + var l = logger.NewLogger() // Where to locate defer conn.Close() -func NewClient(name string, addr string) (*Client, error) { +func NewClient(id uuid.UUID, addr string) (*Client, error) { conn := getConnection(addr) if conn == nil { l.Error("could not Create a connection") @@ -34,34 +37,45 @@ func NewClient(name string, addr string) (*Client, error) { l.Info("Created the client") return &Client{ - c: c, - Name: name, - s: serialize.NewSerializer(), + id: id, + c: c, + s: serialize.NewSerializer(), }, nil } func (client *Client) Subscribe(topicName string, ctx context.Context, fn func(event *proto.Event) error) error { r := client.createSubRequest(topicName) - subStream, err := client.c.Subscribe(ctx, r) - if err != nil { - return err - } + reqCount := atomic.Uint32{} + + for i := 0; i < streamPerSubscriber; i++ { + go func(x int) { - go func() { - for { - e, err := subStream.Recv() + subStream, err := client.c.Subscribe(ctx, r) if err != nil { - // TODO: What if cannot receive? - l.Error("", zap.Error(err)) panic(err) } - err = fn(e) - if err != nil { - _ = client.retry(ctx, e, r.SubscriberID) - } - } - }() + go func() { + for { + bulkEvent, err := subStream.Recv() + fmt.Println("--------------", x, reqCount.Add(1)) + if err != nil { + // TODO: What if cannot receive? + l.Error("", zap.Error(err)) + panic(err) + + } + + go func() { + for _, v := range bulkEvent.EventList { + go fn(v) + } + }() + } + }() + + }(i) + } return nil } @@ -92,9 +106,11 @@ func (client *Client) retry(ctx context.Context, e *proto.Event, subId string) e } func (client *Client) createSubRequest(topicName string) *proto.SubscribeRequest { + subName := fmt.Sprintf("%s", client.id) + fmt.Println(subName) return &proto.SubscribeRequest{ SubscriberID: uuid.NewString(), - SubscriberName: fmt.Sprintf("%s:%s", client.Name, topicName), + SubscriberName: subName, Topic: topicName, CreatedAt: timestamppb.Now(), } diff --git a/pkg/client/grpc_dial.go b/pkg/client/grpc_dial.go index 55973df..52ca829 100644 --- a/pkg/client/grpc_dial.go +++ b/pkg/client/grpc_dial.go @@ -12,7 +12,7 @@ var ( ) func getConnection(addr string) *grpc.ClientConn { - o.Do(func() { + /*.Do(func() { c, err := grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { @@ -20,7 +20,12 @@ func getConnection(addr string) *grpc.ClientConn { } else { conn = c } - }) + })*/ - return conn + c, _ := grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials())) + // c, _ := grpc.Dial(addr, + // grpc.WithTransportCredentials(insecure.NewCredentials()), + // grpc.WithInitialWindowSize(1024*1024), + // grpc.WithInitialConnWindowSize(1024*1024)) + return c } diff --git a/proto/Event.pb.go b/proto/Event.pb.go index f0a2ed6..d68b219 100644 --- a/proto/Event.pb.go +++ b/proto/Event.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.28.1 -// protoc v3.21.12 +// protoc-gen-go v1.31.0 +// protoc v4.24.4 // source: Event.proto package proto @@ -100,6 +100,53 @@ func (x *Event) GetExpiresAt() uint32 { return 0 } +type BulkEvent struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + EventList []*Event `protobuf:"bytes,1,rep,name=eventList,proto3" json:"eventList,omitempty"` +} + +func (x *BulkEvent) Reset() { + *x = BulkEvent{} + if protoimpl.UnsafeEnabled { + mi := &file_Event_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BulkEvent) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BulkEvent) ProtoMessage() {} + +func (x *BulkEvent) ProtoReflect() protoreflect.Message { + mi := &file_Event_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BulkEvent.ProtoReflect.Descriptor instead. +func (*BulkEvent) Descriptor() ([]byte, []int) { + return file_Event_proto_rawDescGZIP(), []int{1} +} + +func (x *BulkEvent) GetEventList() []*Event { + if x != nil { + return x.EventList + } + return nil +} + type SubscribeRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -114,7 +161,7 @@ type SubscribeRequest struct { func (x *SubscribeRequest) Reset() { *x = SubscribeRequest{} if protoimpl.UnsafeEnabled { - mi := &file_Event_proto_msgTypes[1] + mi := &file_Event_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -127,7 +174,7 @@ func (x *SubscribeRequest) String() string { func (*SubscribeRequest) ProtoMessage() {} func (x *SubscribeRequest) ProtoReflect() protoreflect.Message { - mi := &file_Event_proto_msgTypes[1] + mi := &file_Event_proto_msgTypes[2] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -140,7 +187,7 @@ func (x *SubscribeRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use SubscribeRequest.ProtoReflect.Descriptor instead. func (*SubscribeRequest) Descriptor() ([]byte, []int) { - return file_Event_proto_rawDescGZIP(), []int{1} + return file_Event_proto_rawDescGZIP(), []int{2} } func (x *SubscribeRequest) GetSubscriberID() string { @@ -184,7 +231,7 @@ type RetryRequest struct { func (x *RetryRequest) Reset() { *x = RetryRequest{} if protoimpl.UnsafeEnabled { - mi := &file_Event_proto_msgTypes[2] + mi := &file_Event_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -197,7 +244,7 @@ func (x *RetryRequest) String() string { func (*RetryRequest) ProtoMessage() {} func (x *RetryRequest) ProtoReflect() protoreflect.Message { - mi := &file_Event_proto_msgTypes[2] + mi := &file_Event_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -210,7 +257,7 @@ func (x *RetryRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use RetryRequest.ProtoReflect.Descriptor instead. func (*RetryRequest) Descriptor() ([]byte, []int) { - return file_Event_proto_rawDescGZIP(), []int{2} + return file_Event_proto_rawDescGZIP(), []int{3} } func (x *RetryRequest) GetSubscriberID() string { @@ -243,7 +290,7 @@ type ACK struct { func (x *ACK) Reset() { *x = ACK{} if protoimpl.UnsafeEnabled { - mi := &file_Event_proto_msgTypes[3] + mi := &file_Event_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -256,7 +303,7 @@ func (x *ACK) String() string { func (*ACK) ProtoMessage() {} func (x *ACK) ProtoReflect() protoreflect.Message { - mi := &file_Event_proto_msgTypes[3] + mi := &file_Event_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -269,7 +316,7 @@ func (x *ACK) ProtoReflect() protoreflect.Message { // Deprecated: Use ACK.ProtoReflect.Descriptor instead. func (*ACK) Descriptor() ([]byte, []int) { - return file_Event_proto_rawDescGZIP(), []int{3} + return file_Event_proto_rawDescGZIP(), []int{4} } var File_Event_proto protoreflect.FileDescriptor @@ -288,38 +335,41 @@ var file_Event_proto_rawDesc = []byte{ 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x73, 0x41, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x73, 0x41, - 0x74, 0x22, 0xae, 0x01, 0x0a, 0x10, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x22, 0x0a, 0x0c, 0x73, 0x75, 0x62, 0x73, 0x63, 0x72, - 0x69, 0x62, 0x65, 0x72, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x75, - 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x72, 0x49, 0x44, 0x12, 0x26, 0x0a, 0x0e, 0x73, 0x75, - 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x72, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x0e, 0x73, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x72, 0x4e, 0x61, - 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x70, 0x69, 0x63, 0x18, 0x03, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x05, 0x74, 0x6f, 0x70, 0x69, 0x63, 0x12, 0x38, 0x0a, 0x09, 0x63, 0x72, 0x65, 0x61, - 0x74, 0x65, 0x64, 0x41, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, - 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, - 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, - 0x41, 0x74, 0x22, 0x90, 0x01, 0x0a, 0x0c, 0x52, 0x65, 0x74, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x12, 0x22, 0x0a, 0x0c, 0x73, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, - 0x72, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x75, 0x62, 0x73, 0x63, - 0x72, 0x69, 0x62, 0x65, 0x72, 0x49, 0x44, 0x12, 0x22, 0x0a, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x45, - 0x76, 0x65, 0x6e, 0x74, 0x52, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x38, 0x0a, 0x09, 0x63, - 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, - 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, - 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, - 0x74, 0x65, 0x64, 0x41, 0x74, 0x22, 0x05, 0x0a, 0x03, 0x41, 0x43, 0x4b, 0x32, 0x92, 0x01, 0x0a, - 0x09, 0x4d, 0x65, 0x72, 0x63, 0x75, 0x72, 0x69, 0x75, 0x73, 0x12, 0x25, 0x0a, 0x07, 0x50, 0x75, - 0x62, 0x6c, 0x69, 0x73, 0x68, 0x12, 0x0c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x45, 0x76, - 0x65, 0x6e, 0x74, 0x1a, 0x0a, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x41, 0x43, 0x4b, 0x22, - 0x00, 0x12, 0x34, 0x0a, 0x09, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x12, 0x17, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, - 0x45, 0x76, 0x65, 0x6e, 0x74, 0x30, 0x01, 0x12, 0x28, 0x0a, 0x05, 0x52, 0x65, 0x74, 0x72, 0x79, - 0x12, 0x13, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x52, 0x65, 0x74, 0x72, 0x79, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0a, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x41, 0x43, - 0x4b, 0x42, 0x08, 0x5a, 0x06, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, + 0x74, 0x22, 0x37, 0x0a, 0x09, 0x42, 0x75, 0x6c, 0x6b, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x2a, + 0x0a, 0x09, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x4c, 0x69, 0x73, 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, + 0x0b, 0x32, 0x0c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, + 0x09, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x4c, 0x69, 0x73, 0x74, 0x22, 0xae, 0x01, 0x0a, 0x10, 0x53, + 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x22, 0x0a, 0x0c, 0x73, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x72, 0x49, 0x44, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, + 0x72, 0x49, 0x44, 0x12, 0x26, 0x0a, 0x0e, 0x73, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, + 0x72, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x73, 0x75, 0x62, + 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x72, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x74, + 0x6f, 0x70, 0x69, 0x63, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x70, 0x69, + 0x63, 0x12, 0x38, 0x0a, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x18, 0x04, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, + 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x22, 0x90, 0x01, 0x0a, 0x0c, + 0x52, 0x65, 0x74, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x22, 0x0a, 0x0c, + 0x73, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x72, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0c, 0x73, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x72, 0x49, 0x44, + 0x12, 0x22, 0x0a, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x0c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x05, 0x65, + 0x76, 0x65, 0x6e, 0x74, 0x12, 0x38, 0x0a, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x41, + 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, + 0x61, 0x6d, 0x70, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x22, 0x05, + 0x0a, 0x03, 0x41, 0x43, 0x4b, 0x32, 0x96, 0x01, 0x0a, 0x09, 0x4d, 0x65, 0x72, 0x63, 0x75, 0x72, + 0x69, 0x75, 0x73, 0x12, 0x25, 0x0a, 0x07, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x12, 0x0c, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x1a, 0x0a, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x41, 0x43, 0x4b, 0x22, 0x00, 0x12, 0x38, 0x0a, 0x09, 0x53, 0x75, + 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x12, 0x17, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, + 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x10, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x42, 0x75, 0x6c, 0x6b, 0x45, 0x76, 0x65, + 0x6e, 0x74, 0x30, 0x01, 0x12, 0x28, 0x0a, 0x05, 0x52, 0x65, 0x74, 0x72, 0x79, 0x12, 0x13, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x52, 0x65, 0x74, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x0a, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x41, 0x43, 0x4b, 0x42, 0x08, + 0x5a, 0x06, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -334,30 +384,32 @@ func file_Event_proto_rawDescGZIP() []byte { return file_Event_proto_rawDescData } -var file_Event_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_Event_proto_msgTypes = make([]protoimpl.MessageInfo, 5) var file_Event_proto_goTypes = []interface{}{ (*Event)(nil), // 0: proto.Event - (*SubscribeRequest)(nil), // 1: proto.SubscribeRequest - (*RetryRequest)(nil), // 2: proto.RetryRequest - (*ACK)(nil), // 3: proto.ACK - (*timestamppb.Timestamp)(nil), // 4: google.protobuf.Timestamp + (*BulkEvent)(nil), // 1: proto.BulkEvent + (*SubscribeRequest)(nil), // 2: proto.SubscribeRequest + (*RetryRequest)(nil), // 3: proto.RetryRequest + (*ACK)(nil), // 4: proto.ACK + (*timestamppb.Timestamp)(nil), // 5: google.protobuf.Timestamp } var file_Event_proto_depIdxs = []int32{ - 4, // 0: proto.Event.createdAt:type_name -> google.protobuf.Timestamp - 4, // 1: proto.SubscribeRequest.createdAt:type_name -> google.protobuf.Timestamp - 0, // 2: proto.RetryRequest.event:type_name -> proto.Event - 4, // 3: proto.RetryRequest.createdAt:type_name -> google.protobuf.Timestamp - 0, // 4: proto.Mercurius.Publish:input_type -> proto.Event - 1, // 5: proto.Mercurius.Subscribe:input_type -> proto.SubscribeRequest - 2, // 6: proto.Mercurius.Retry:input_type -> proto.RetryRequest - 3, // 7: proto.Mercurius.Publish:output_type -> proto.ACK - 0, // 8: proto.Mercurius.Subscribe:output_type -> proto.Event - 3, // 9: proto.Mercurius.Retry:output_type -> proto.ACK - 7, // [7:10] is the sub-list for method output_type - 4, // [4:7] is the sub-list for method input_type - 4, // [4:4] is the sub-list for extension type_name - 4, // [4:4] is the sub-list for extension extendee - 0, // [0:4] is the sub-list for field type_name + 5, // 0: proto.Event.createdAt:type_name -> google.protobuf.Timestamp + 0, // 1: proto.BulkEvent.eventList:type_name -> proto.Event + 5, // 2: proto.SubscribeRequest.createdAt:type_name -> google.protobuf.Timestamp + 0, // 3: proto.RetryRequest.event:type_name -> proto.Event + 5, // 4: proto.RetryRequest.createdAt:type_name -> google.protobuf.Timestamp + 0, // 5: proto.Mercurius.Publish:input_type -> proto.Event + 2, // 6: proto.Mercurius.Subscribe:input_type -> proto.SubscribeRequest + 3, // 7: proto.Mercurius.Retry:input_type -> proto.RetryRequest + 4, // 8: proto.Mercurius.Publish:output_type -> proto.ACK + 1, // 9: proto.Mercurius.Subscribe:output_type -> proto.BulkEvent + 4, // 10: proto.Mercurius.Retry:output_type -> proto.ACK + 8, // [8:11] is the sub-list for method output_type + 5, // [5:8] is the sub-list for method input_type + 5, // [5:5] is the sub-list for extension type_name + 5, // [5:5] is the sub-list for extension extendee + 0, // [0:5] is the sub-list for field type_name } func init() { file_Event_proto_init() } @@ -379,7 +431,7 @@ func file_Event_proto_init() { } } file_Event_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*SubscribeRequest); i { + switch v := v.(*BulkEvent); i { case 0: return &v.state case 1: @@ -391,7 +443,7 @@ func file_Event_proto_init() { } } file_Event_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*RetryRequest); i { + switch v := v.(*SubscribeRequest); i { case 0: return &v.state case 1: @@ -403,6 +455,18 @@ func file_Event_proto_init() { } } file_Event_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*RetryRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_Event_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ACK); i { case 0: return &v.state @@ -421,7 +485,7 @@ func file_Event_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_Event_proto_rawDesc, NumEnums: 0, - NumMessages: 4, + NumMessages: 5, NumExtensions: 0, NumServices: 1, }, diff --git a/proto/Event.proto b/proto/Event.proto index 8105ad2..a7c140c 100644 --- a/proto/Event.proto +++ b/proto/Event.proto @@ -16,6 +16,10 @@ message Event { uint32 expiresAt = 5; } +message BulkEvent{ + repeated Event eventList = 1; +} + message SubscribeRequest { string subscriberID = 1; string subscriberName = 2; @@ -33,6 +37,6 @@ message ACK {} service Mercurius { rpc Publish (Event) returns (ACK) {}; - rpc Subscribe (SubscribeRequest) returns (stream Event); + rpc Subscribe (SubscribeRequest) returns (stream BulkEvent); rpc Retry (RetryRequest) returns (ACK); } \ No newline at end of file diff --git a/proto/Event_grpc.pb.go b/proto/Event_grpc.pb.go index b22bce9..6820b08 100644 --- a/proto/Event_grpc.pb.go +++ b/proto/Event_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: -// - protoc-gen-go-grpc v1.2.0 -// - protoc v3.21.12 +// - protoc-gen-go-grpc v1.3.0 +// - protoc v4.24.4 // source: Event.proto package proto @@ -18,6 +18,12 @@ import ( // Requires gRPC-Go v1.32.0 or later. const _ = grpc.SupportPackageIsVersion7 +const ( + Mercurius_Publish_FullMethodName = "/proto.Mercurius/Publish" + Mercurius_Subscribe_FullMethodName = "/proto.Mercurius/Subscribe" + Mercurius_Retry_FullMethodName = "/proto.Mercurius/Retry" +) + // MercuriusClient is the client API for Mercurius service. // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. @@ -37,7 +43,7 @@ func NewMercuriusClient(cc grpc.ClientConnInterface) MercuriusClient { func (c *mercuriusClient) Publish(ctx context.Context, in *Event, opts ...grpc.CallOption) (*ACK, error) { out := new(ACK) - err := c.cc.Invoke(ctx, "/proto.Mercurius/Publish", in, out, opts...) + err := c.cc.Invoke(ctx, Mercurius_Publish_FullMethodName, in, out, opts...) if err != nil { return nil, err } @@ -45,7 +51,7 @@ func (c *mercuriusClient) Publish(ctx context.Context, in *Event, opts ...grpc.C } func (c *mercuriusClient) Subscribe(ctx context.Context, in *SubscribeRequest, opts ...grpc.CallOption) (Mercurius_SubscribeClient, error) { - stream, err := c.cc.NewStream(ctx, &Mercurius_ServiceDesc.Streams[0], "/proto.Mercurius/Subscribe", opts...) + stream, err := c.cc.NewStream(ctx, &Mercurius_ServiceDesc.Streams[0], Mercurius_Subscribe_FullMethodName, opts...) if err != nil { return nil, err } @@ -60,7 +66,7 @@ func (c *mercuriusClient) Subscribe(ctx context.Context, in *SubscribeRequest, o } type Mercurius_SubscribeClient interface { - Recv() (*Event, error) + Recv() (*BulkEvent, error) grpc.ClientStream } @@ -68,8 +74,8 @@ type mercuriusSubscribeClient struct { grpc.ClientStream } -func (x *mercuriusSubscribeClient) Recv() (*Event, error) { - m := new(Event) +func (x *mercuriusSubscribeClient) Recv() (*BulkEvent, error) { + m := new(BulkEvent) if err := x.ClientStream.RecvMsg(m); err != nil { return nil, err } @@ -78,7 +84,7 @@ func (x *mercuriusSubscribeClient) Recv() (*Event, error) { func (c *mercuriusClient) Retry(ctx context.Context, in *RetryRequest, opts ...grpc.CallOption) (*ACK, error) { out := new(ACK) - err := c.cc.Invoke(ctx, "/proto.Mercurius/Retry", in, out, opts...) + err := c.cc.Invoke(ctx, Mercurius_Retry_FullMethodName, in, out, opts...) if err != nil { return nil, err } @@ -131,7 +137,7 @@ func _Mercurius_Publish_Handler(srv interface{}, ctx context.Context, dec func(i } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Mercurius/Publish", + FullMethod: Mercurius_Publish_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(MercuriusServer).Publish(ctx, req.(*Event)) @@ -148,7 +154,7 @@ func _Mercurius_Subscribe_Handler(srv interface{}, stream grpc.ServerStream) err } type Mercurius_SubscribeServer interface { - Send(*Event) error + Send(*BulkEvent) error grpc.ServerStream } @@ -156,7 +162,7 @@ type mercuriusSubscribeServer struct { grpc.ServerStream } -func (x *mercuriusSubscribeServer) Send(m *Event) error { +func (x *mercuriusSubscribeServer) Send(m *BulkEvent) error { return x.ServerStream.SendMsg(m) } @@ -170,7 +176,7 @@ func _Mercurius_Retry_Handler(srv interface{}, ctx context.Context, dec func(int } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Mercurius/Retry", + FullMethod: Mercurius_Retry_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(MercuriusServer).Retry(ctx, req.(*RetryRequest))