vardius/go-api-boilerplate

External gRPC client - subscribe to events

mar1n3r0 opened this issue · 1 comments

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 ?

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