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.
|
// Events combines the configuration options for the event bus.
|
||||||
type Events struct {
|
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."`
|
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"
|
svc "github.com/owncloud/ocis/v2/services/graph/pkg/service/v0"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"go-micro.dev/v4"
|
"go-micro.dev/v4"
|
||||||
|
"go-micro.dev/v4/events"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server initializes the http service and server.
|
// Server initializes the http service and server.
|
||||||
@@ -28,15 +29,20 @@ func Server(opts ...Option) (http.Service, error) {
|
|||||||
http.Flags(options.Flags...),
|
http.Flags(options.Flags...),
|
||||||
)
|
)
|
||||||
|
|
||||||
publisher, err := server.NewNatsStream(
|
var publisher events.Stream
|
||||||
natsjs.Address(options.Config.Events.Endpoint),
|
|
||||||
natsjs.ClusterID(options.Config.Events.Cluster),
|
if options.Config.Events.Endpoint != "" {
|
||||||
)
|
var err error
|
||||||
if err != nil {
|
publisher, err = server.NewNatsStream(
|
||||||
options.Logger.Error().
|
natsjs.Address(options.Config.Events.Endpoint),
|
||||||
Err(err).
|
natsjs.ClusterID(options.Config.Events.Cluster),
|
||||||
Msg("Error initializing events publisher")
|
)
|
||||||
return http.Service{}, errors.Wrap(err, "could not initialize events publisher")
|
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(
|
handle := svc.NewService(
|
||||||
|
|||||||
@@ -91,10 +91,12 @@ func (g Graph) GetGatewayClient() GatewayClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g Graph) publishEvent(ev interface{}) {
|
func (g Graph) publishEvent(ev interface{}) {
|
||||||
if err := events.Publish(g.eventsPublisher, ev); err != nil {
|
if g.eventsPublisher != nil {
|
||||||
g.logger.Error().
|
if err := events.Publish(g.eventsPublisher, ev); err != nil {
|
||||||
Err(err).
|
g.logger.Error().
|
||||||
Msg("could not publish user created event")
|
Err(err).
|
||||||
|
Msg("could not publish user created event")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user