mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-03-03 14:57:22 -05:00
Merge pull request #4138 from wkloucek/graph-optional-events
make graph service events optional
This commit is contained in:
@@ -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
|
||||
@@ -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."`
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user