github.com/wfusion/gofusion@v1.1.14/common/infra/watermill/docs/content/pubsubs/redisstream.md (about)

     1  +++
     2  title = "Redis Stream"
     3  description = "A fast, open source, in-memory, key-value data store"
     4  date = 2023-02-01T22:30:00+08:00
     5  bref = "A fast, open source, in-memory, key-value data store"
     6  weight = -70
     7  type = "docs"
     8  toc = false
     9  +++
    10  
    11  ### Redis Stream
    12  
    13  Redis is the open source, in-memory data store used by millions of developers. Redis stream is a data structure that acts like an append-only log in Redis. We are providing Pub/Sub implementation based on [redis/go-redis](https://github.com/redis/go-redis).
    14  
    15  ### Installation
    16  
    17      go get github.com/ThreeDotsLabs/watermill-redisstream
    18  
    19  #### Characteristics
    20  
    21  | Feature | Implements | Note |
    22  | ------- | ---------- | ---- |
    23  | ConsumerGroups | yes | |
    24  | ExactlyOnceDelivery | no | |
    25  | GuaranteedOrder | no | |
    26  | Persistent | yes | |
    27  | FanOut | yes | use XREAD to fan out messages when there is no consumer group |
    28  
    29  #### Configuration
    30  {{% render-md %}}
    31  {{% load-snippet-partial file="src-link/watermill-redisstream/pkg/redisstream/publisher.go" first_line_contains="type PublisherConfig struct" last_line_contains="// Publish publishes message to redis stream" %}}
    32  {{% /render-md %}}
    33  
    34  {{% render-md %}}
    35  {{% load-snippet-partial file="src-link/watermill-redisstream/pkg/redisstream/subscriber.go" first_line_contains="type SubscriberConfig struct" last_line_contains="func (s *Subscriber) Subscribe" %}}
    36  {{% /render-md %}}
    37  
    38  ##### Passing `redis.UniversalClient`
    39  
    40  You need to configure and pass your own go-redis client via `Client redis.UniversalClient` in `NewSubscriber` and `NewPublisher`. The client can be either `redis.Client` or `redis.ClusterClient`.
    41  
    42  ##### Publisher
    43  {{% render-md %}}
    44  {{% load-snippet-partial file="src-link/watermill-redisstream/pkg/redisstream/publisher.go" first_line_contains="// NewPublisher" last_line_contains="(*Publisher, error)" padding_after="0" %}}
    45  
    46  Example:
    47  {{% load-snippet-partial file="src-link/_examples/pubsubs/redisstream/main.go" first_line_contains="pubClient := redis.NewClient" last_line_contains="panic(err)" padding_after="1" %}}
    48  
    49  {{% /render-md %}}
    50  
    51  ##### Subscriber
    52  {{% render-md %}}
    53  {{% load-snippet-partial file="src-link/watermill-redisstream/pkg/redisstream/subscriber.go" first_line_contains="// NewSubscriber" last_line_contains="(*Subscriber, error)" padding_after="0" %}}
    54  
    55  Example:
    56  {{% load-snippet-partial file="src-link/_examples/pubsubs/redisstream/main.go" first_line_contains="subClient := redis.NewClient" last_line_contains="panic(err)" padding_after="1" %}}
    57  
    58  #### Publishing
    59  
    60  {{% render-md %}}
    61  {{% load-snippet-partial file="src-link/watermill-redisstream/pkg/redisstream/publisher.go" first_line_contains="// Publish" last_line_contains="func (p *Publisher) Publish" %}}
    62  {{% /render-md %}}
    63  
    64  #### Subscribing
    65  
    66  {{% render-md %}}
    67  {{% load-snippet-partial file="src-link/watermill-redisstream/pkg/redisstream/subscriber.go" first_line_contains="func (s *Subscriber) Subscribe" last_line_contains="func (s *Subscriber) Subscribe" %}}
    68  {{% /render-md %}}
    69  
    70  #### Marshaler
    71  
    72  Watermill's messages cannot be directly sent to Redis - they need to be marshaled. You can implement your marshaler or use default implementation. The default implementation uses [MessagePack](https://msgpack.org/index.html) for efficient serialization.
    73  
    74  {{% render-md %}}
    75  {{% load-snippet-partial file="src-link/watermill-redisstream/pkg/redisstream/marshaller.go" first_line_contains="const UUIDHeaderKey" last_line_contains="type DefaultMarshallerUnmarshaller" padding_after="0" %}}
    76  {{% /render-md %}}