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

     1  +++
     2  title = "Firestore Pub/Sub"
     3  description = "A scalable document database from Google"
     4  date = 2021-07-29T15:30:00+02:00
     5  bref = "A scalable document database from Google"
     6  weight = -20
     7  type = "docs"
     8  toc = false
     9  +++
    10  
    11  ### Firestore Pub/Sub
    12  
    13  Cloud Firestore is a cloud-hosted, NoSQL database from Google.
    14  
    15  This Pub/Sub comes with two publishers. To publish messages in a transaction
    16  use the `TransactionalPublisher`. If you do not want to publish messages in
    17  transaction use the normal `Publisher`.
    18  
    19  Using Firestore as a Pub/Sub instead of using a dedicated Pub/Sub system can be
    20  useful to publish messages in transaction while at the same time saving other
    21  data in Firestore. Thanks to that the data and the messages can be consistently
    22  persisted. If the messages and the data weren't being published transactionally
    23  you could end up in situations where messages were emitted even though the data
    24  wasn't saved or messages weren't emitted even though the data was saved. After
    25  transactionally publishing messages in Firestore you can then subscribe to them
    26  and relay them to a different Pub/Sub system.
    27  
    28  Godoc: <https://pkg.go.dev/github.com/ThreeDotsLabs/watermill-firestore>
    29  
    30  Firestore documentation: <https://firebase.google.com/docs/firestore/>
    31  
    32  ### Installation
    33  
    34      go get github.com/ThreeDotsLabs/watermill-firestore
    35  
    36  #### Characteristics
    37  
    38  | Feature             | Implements | Note |
    39  | -------             | ---------- | ---- |
    40  | ConsumerGroups      | yes        |      |
    41  | ExactlyOnceDelivery | no         |      |
    42  | GuaranteedOrder     | no         |      |
    43  | Persistent          | yes        |      |
    44  
    45  #### Configuration
    46  
    47  ##### Publisher configuration
    48  
    49  {{% render-md %}}
    50  {{% load-snippet-partial file="src-link/watermill-firestore/pkg/firestore/publisher.go" first_line_contains="type PublisherConfig struct {" last_line_equals="}" %}}
    51  {{% /render-md %}}
    52  
    53  ##### Subscriber configuration
    54  
    55  {{% render-md %}}
    56  {{% load-snippet-partial file="src-link/watermill-firestore/pkg/firestore/subscriber.go" first_line_contains="type SubscriberConfig struct {" last_line_equals="}" %}}
    57  {{% /render-md %}}
    58  
    59  ##### Subscription name
    60  
    61  To receive messages published to a topic, you must create a subscription to
    62  that topic. Only messages published to the topic after the subscription is
    63  created will be received by the subscribers.
    64  
    65  A topic can have multiple subscriptions, but a given subscription belongs to a
    66  single topic.
    67  
    68  In Watermill, the subscription is created automatically during calling
    69  `Subscribe()`. Subscription name is generated by function passed to
    70  `SubscriberConfig.GenerateSubscriptionName`. By default, it is just the topic
    71  name with a suffix `_sub` appended to it.
    72  
    73  If you want to consume messages from a topic with multiple subscribers
    74  processing the incoming messages in a different way, you should use a custom
    75  function to generate unique subscription names for each subscriber.
    76  
    77  #### Marshaler
    78  
    79  Watermill's messages cannot be stored directly in Firestore. The marshaler is
    80  responsible for converting them to a type which can be stored by Firestore.
    81  The default implementation should be enough for most applications so it is
    82  unlikely that you need to implement your own marshaler.
    83  
    84  {{% render-md %}}
    85  {{% load-snippet-partial file="src-link/watermill-firestore/pkg/firestore/marshaler.go" first_line_contains="// Marshaler" last_line_equals="}" padding_after="0" %}}
    86  {{% /render-md %}}
    87  
    88