1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-07-12 22:41:07 +02:00

Re-add events package (#2761)

* Re-add events package

* run redis as a dep

* remove redis events

* fix: data race on event subscriber

* fix: data race in tests

* fix: store errors

* fix: lint issues

* feat: default stream

* Update file.go

---------

Co-authored-by: Brian Ketelsen <bketelsen@gmail.com>
This commit is contained in:
Asim Aslam
2025-06-18 17:12:02 +01:00
committed by GitHub
parent dd0944bf68
commit 7e1bba2baf
17 changed files with 1621 additions and 32 deletions

View File

@ -23,6 +23,7 @@ import (
"go-micro.dev/v5/debug/profile/http"
"go-micro.dev/v5/debug/profile/pprof"
"go-micro.dev/v5/debug/trace"
"go-micro.dev/v5/events"
"go-micro.dev/v5/logger"
mprofile "go-micro.dev/v5/profile"
"go-micro.dev/v5/registry"
@ -293,6 +294,7 @@ var (
DefaultCaches = map[string]func(...cache.Option) cache.Cache{
"redis": redis.NewRedisCache,
}
DefaultStreams = map[string]func(...events.Option) (events.Stream, error){}
)
func init() {
@ -313,6 +315,7 @@ func newCmd(opts ...Option) Cmd {
DebugProfile: &profile.DefaultProfile,
Config: &config.DefaultConfig,
Cache: &cache.DefaultCache,
Stream: &events.DefaultStream,
Brokers: DefaultBrokers,
Clients: DefaultClients,
@ -376,7 +379,10 @@ func (c *cmd) Before(ctx *cli.Context) error {
if profileName != "" {
switch profileName {
case "local":
imported := mprofile.LocalProfile()
imported, ierr := mprofile.LocalProfile()
if ierr != nil {
return fmt.Errorf("failed to load local profile: %v", ierr)
}
*c.opts.Registry = imported.Registry
registry.DefaultRegistry = imported.Registry
*c.opts.Broker = imported.Broker
@ -386,7 +392,10 @@ func (c *cmd) Before(ctx *cli.Context) error {
*c.opts.Transport = imported.Transport
transport.DefaultTransport = imported.Transport
case "nats":
imported := mprofile.NatsProfile()
imported, ierr := mprofile.NatsProfile()
if ierr != nil {
return fmt.Errorf("failed to load nats profile: %v", ierr)
}
// Set the registry
sopts, clopts := c.setRegistry(imported.Registry)
serverOpts = append(serverOpts, sopts...)
@ -407,6 +416,11 @@ func (c *cmd) Before(ctx *cli.Context) error {
serverOpts = append(serverOpts, sopts...)
clientOpts = append(clientOpts, clopts...)
// Set the stream
sopts, clopts = c.setStream(imported.Stream)
serverOpts = append(serverOpts, sopts...)
clientOpts = append(clientOpts, clopts...)
// Add more profiles as needed
default:
return fmt.Errorf("unsupported profile: %s", profileName)
@ -701,6 +715,17 @@ func (c *cmd) setRegistry(r registry.Registry) ([]server.Option, []client.Option
registry.DefaultRegistry = *c.opts.Registry
return serverOpts, clientOpts
}
func (c *cmd) setStream(s events.Stream) ([]server.Option, []client.Option) {
var serverOpts []server.Option
var clientOpts []client.Option
*c.opts.Stream = s
// TODO: do server and client need a Stream?
// serverOpts = append(serverOpts, server.Registry(*c.opts.Registry))
// clientOpts = append(clientOpts, client.Registry(*c.opts.Registry))
events.DefaultStream = *c.opts.Stream
return serverOpts, clientOpts
}
func (c *cmd) setBroker(b broker.Broker) ([]server.Option, []client.Option) {
var serverOpts []server.Option