If you are beginning your journey with Senzing, please start with Senzing Quick Start guides.
You are in the Senzing Garage where projects are "tinkered" on. Although this GitHub repository may help you understand an approach to using Senzing, it's not considered to be "production ready" and is not considered to be part of the Senzing product. Heck, it may not even be appropriate for your application of Senzing!
Implements the Observer software design pattern.
Examples of using go-observing
can be seen in main.go.
As an example, a null object, ObserverNull, shows how an observer is used in the Observer software design pattern. It is an example only. Any code wishing to observe, would write their own code which adheres to the Observer interface.
In addition to local, "in-process", observation,
the go-observer
repository also supports a gRPC-based aggregator of observer messages.
The following image shows flow of messages.
The Subject notifies local Observers. One of the Observers "repeats" the message by sending it via gRPC to a GrpcServer that embeds a Subject. That Subject notifies remote Observers.
To create a GrpcServer, a Subject is created with Observers and wrapped with a GrpcServer. Example:
package main
import (
"context"
"github.com/senzing-garage/go-observing/grpcserver"
"github.com/senzing-garage/go-observing/observer"
"github.com/senzing-garage/go-observing/subject"
)
func main() {
ctx := context.TODO()
// Create a Subject.
aSubject := &subject.SubjectImpl{}
// Register Observer(s) with the Subject.
anObserver1 := &observer.ObserverNull{
Id: "Observer 1",
}
err = aSubject.RegisterObserver(ctx, anObserver1)
if err != nil {
fmt.Print(err)
}
// Start gRPC service with an embedded Subject.
aGrpcServer := &grpcserver.GrpcServerImpl{
Port: 8260,
Subject: aSubject,
}
aGrpcServer.Serve(ctx)
A working GrpcServer can be seen in main.go.
The ObserverGrpc is an Observer that sends messages to a GrpcServer.