Skip to content

Commit

Permalink
marshaled proto messages before publishing them to redis pub sub
Browse files Browse the repository at this point in the history
  • Loading branch information
0xluk committed Oct 29, 2024
1 parent ccad938 commit 2960102
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions pubsub/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/pkg/errors"
qubicpb "github.com/qubic/go-qubic/proto/v1"
"github.com/redis/go-redis/v9"
"google.golang.org/protobuf/encoding/protojson"
"strconv"
"time"
)
Expand Down Expand Up @@ -49,7 +50,12 @@ func (ps *RedisPubSub) PublishTickEvents(ctx context.Context, tickEvents *qubicp
}

func (ps *RedisPubSub) publishAllTickEvents(ctx context.Context, tickEvents *qubicpb.TickEvents) error {
err := ps.rdb.Publish(ctx, "tickevents", tickEvents).Err()
data, err := protojson.Marshal(tickEvents)
if err != nil {
return errors.Wrap(err, "marshalling tick events")
}

err = ps.rdb.Publish(ctx, "tickevents", data).Err()
if err != nil {
return errors.Wrap(err, "publishing tick events")
}
Expand All @@ -60,7 +66,12 @@ func (ps *RedisPubSub) publishAllTickEvents(ctx context.Context, tickEvents *qub
func (ps *RedisPubSub) publishTxEventsByType(ctx context.Context, txEvents *qubicpb.TransactionEvents) error {
for _, event := range txEvents.Events {
channelName := "eventsbytype" + strconv.FormatInt(int64(event.EventType), 10)
err := ps.rdb.Publish(ctx, channelName, event).Err()
data, err := protojson.Marshal(event)
if err != nil {
return errors.Wrapf(err, "marshalling data for event with type: %d id: %d", event.EventType, event.Header.EventId)
}

err = ps.rdb.Publish(ctx, channelName, data).Err()
if err != nil {
return errors.Wrapf(err, "publishing event with type: %d id: %d", event.EventType, event.Header.EventId)
}
Expand Down

0 comments on commit 2960102

Please sign in to comment.