diff --git a/changelog/unreleased/feature-optional-events-in-graph-service.md b/changelog/unreleased/feature-optional-events-in-graph-service.md new file mode 100644 index 0000000000..9c34e0301b --- /dev/null +++ b/changelog/unreleased/feature-optional-events-in-graph-service.md @@ -0,0 +1,8 @@ +Enhancement: Optional events in graph service + +We've changed the graph service so that you also can start it without any +event bus. +Therefore you need to set `GRAPH_EVENTS_ENDPOINT` to an empty string. +The graph API will not emit any events in this case. + +https://github.com/owncloud/ocis/pull/55555 diff --git a/services/graph/pkg/config/config.go b/services/graph/pkg/config/config.go index 67b38229c7..d121cb6a98 100644 --- a/services/graph/pkg/config/config.go +++ b/services/graph/pkg/config/config.go @@ -69,6 +69,6 @@ type Identity struct { // Events combines the configuration options for the event bus. type Events struct { - Endpoint string `yaml:"endpoint" env:"GRAPH_EVENTS_ENDPOINT" desc:"The address of the streaming service."` + Endpoint string `yaml:"endpoint" env:"GRAPH_EVENTS_ENDPOINT" desc:"The address of the streaming service. Set to a empty string to disable emitting events."` Cluster string `yaml:"cluster" env:"GRAPH_EVENTS_CLUSTER" desc:"The clusterID of the streaming service. Mandatory when using the NATS service."` } diff --git a/services/graph/pkg/server/http/server.go b/services/graph/pkg/server/http/server.go index 5ffb9ae08b..8a3a22b784 100644 --- a/services/graph/pkg/server/http/server.go +++ b/services/graph/pkg/server/http/server.go @@ -12,6 +12,7 @@ import ( svc "github.com/owncloud/ocis/v2/services/graph/pkg/service/v0" "github.com/pkg/errors" "go-micro.dev/v4" + "go-micro.dev/v4/events" ) // Server initializes the http service and server. @@ -28,15 +29,20 @@ func Server(opts ...Option) (http.Service, error) { http.Flags(options.Flags...), ) - publisher, err := server.NewNatsStream( - natsjs.Address(options.Config.Events.Endpoint), - natsjs.ClusterID(options.Config.Events.Cluster), - ) - if err != nil { - options.Logger.Error(). - Err(err). - Msg("Error initializing events publisher") - return http.Service{}, errors.Wrap(err, "could not initialize events publisher") + var publisher events.Stream + + if options.Config.Events.Endpoint != "" { + var err error + publisher, err = server.NewNatsStream( + natsjs.Address(options.Config.Events.Endpoint), + natsjs.ClusterID(options.Config.Events.Cluster), + ) + if err != nil { + options.Logger.Error(). + Err(err). + Msg("Error initializing events publisher") + return http.Service{}, errors.Wrap(err, "could not initialize events publisher") + } } handle := svc.NewService( diff --git a/services/graph/pkg/service/v0/graph.go b/services/graph/pkg/service/v0/graph.go index 6853754a5c..2f1c98d8dc 100644 --- a/services/graph/pkg/service/v0/graph.go +++ b/services/graph/pkg/service/v0/graph.go @@ -91,10 +91,12 @@ func (g Graph) GetGatewayClient() GatewayClient { } func (g Graph) publishEvent(ev interface{}) { - if err := events.Publish(g.eventsPublisher, ev); err != nil { - g.logger.Error(). - Err(err). - Msg("could not publish user created event") + if g.eventsPublisher != nil { + if err := events.Publish(g.eventsPublisher, ev); err != nil { + g.logger.Error(). + Err(err). + Msg("could not publish user created event") + } } }