vardius / go-api-boilerplate

Go Server/API boilerplate using best practices DDD CQRS ES gRPC
https://go-api-boilerplate.local
MIT License
917 stars 135 forks source link

External gRPC client - subscribe to events #85

Closed mar1n3r0 closed 3 years ago

mar1n3r0 commented 3 years ago

Is it possible that we can connect an external gRPC client and subscribe it to event types the same way internal event handlers are subscribed via the eventbus ?

I saw the example with authClient being called from user event handler but this is injected and used from the service container.

https://github.com/vardius/go-api-boilerplate/blob/master/cmd/user/internal/application/eventhandler/when_user_access_token_was_requested.go

if _, err := authClient.DispatchTokenCommand(identity.ContextWithIdentity(ctx, &i), &proto.DispatchAuthCommandRequest{
            Name:    createTokenCommandName,
            Payload: nil,
        }); err != nil {
            return apperrors.Wrap(err)
        }

https://github.com/vardius/go-api-boilerplate/blob/9eb29c7fde062c9e99ec7dfcb36b8c536b1e2e8c/cmd/user/internal/domain/init.go#L65

if err := container.EventBus.Subscribe(ctx, user.AccessTokenWasRequestedType, eventhandler.WhenUserAccessTokenWasRequested(cfg, jwt.SigningMethodHS512, container.Authenticator, container.UserPersistenceRepository, container.AuthClient)); err != nil {
        return apperrors.Wrap(err)
    }

Can we connect to external client in place where container.AuthClient is ?

mar1n3r0 commented 3 years ago

Got it, it can be injected in the service container.