open-consul/contributing/rpc/streaming/adding-a-topic.md
Daniel Nephin d313219e85 contributing: start an outline for more docs
Add diagrams for rpc routing and acl entity relationship
contributing: create directory structure for new docs
WIP diagram for catalog entities
Add overview diagram

Co-Authored-By: Kelly Devlin <kdevlin@hashicorp.com>
2021-07-05 18:25:00 -04:00

2.2 KiB

Adding a new topic to streaming

This document is a guide for adding a new streaming topic.

  1. Add the name of the topic to the proto/pbsubscribe/subscribe.proto Topic enum. Run make proto to generate the Go code from the protobuf.
  2. Add a FromChanges function to the list of change functions in agent/consul/state.processDBChanges. The FromChanges function should examine the list of Changes and return a list of events that subscriptions would need to update their view.
  3. Add a snapshot function to agent/consul/state.newSnapshotHandlers. The snapshot function should produce a set of events to create the initial state of the view. Generally these are all "create" events.
  4. Add a new Payload type, similar to agent/consul/state.EventPayloadCheckServiceNode. This type will be used in the Payload field of the event.
  5. Create the protobuf for the payload, and add the Payload type to the oneof in proto/pbsubscrube/subscribe.proto Event.Payload. This may require creating other protobuf types as well, to encode anything in the payload. Run make proto to generate the Go code from the protobuf.
  6. Add another case to agent/rpc/subscribe.setPayload to convert from the Payload type in state, to the protobuf type. This may require either writing or generating a function to convert between the types.
  7. Add a new cache-type that uses agent/submatview.Materializer similar to agent/cache-types/streaming_health_services.go.