mirror of https://github.com/hashicorp/consul
2.2 KiB
2.2 KiB
Adding a new topic to streaming
This document is a guide for adding a new streaming topic.
- 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. - Add a
FromChanges
function to the list of change functions in agent/consul/state.processDBChanges. TheFromChanges
function should examine the list ofChanges
and return a list of events that subscriptions would need to update their view. - 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.
- Add a new
Payload
type, similar to agent/consul/state.EventPayloadCheckServiceNode. This type will be used in thePayload
field of the event. - Create the protobuf for the payload, and add the
Payload
type to theoneof
in proto/pbsubscrube/subscribe.proto Event.Payload. This may require creating other protobuf types as well, to encode anything in the payload. Runmake proto
to generate the Go code from the protobuf. - 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. - Add a new cache-type that uses agent/submatview.Materializer similar to agent/cache-types/streaming_health_services.go.