Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Feature Registrations in One App Module #17

Open
natersgonnanate opened this issue Oct 20, 2020 · 1 comment
Open

Multiple Feature Registrations in One App Module #17

natersgonnanate opened this issue Oct 20, 2020 · 1 comment

Comments

@natersgonnanate
Copy link

Hi, I'm running into an issue registering the EventStoreModule within each domain module of my application. Events are publishing to Event Store, but regardless of module is publishing the event, the stream name is always the first module that's imported in the app.module.ts.

Users Domain Module:

@Module({
    imports: [
        CqrsModule,
        EventStoreModule.registerFeature({
            type: 'event-store',
            featureStreamName: '$svc-identity-user',
            eventHandlers: {
                UserCreatedEvent: (user: UserCreatedPayload) => new UserCreatedEvent(user),
            },
            subscriptions: []
        }),
        MongooseModule.forFeature([{ name: UserDto.name, schema: UserSchema }], connectionName),
        forwardRef(() => AuthModule),
    ],
    providers: [
        UserResolver,
        ...QueryHandlers,
        ...CommandHandlers,
        UsersService,
    ],
    exports: [
        UsersService,
    ],
})
export class UsersModule { }

Organizations Domain Module

@Module({
  imports: [
    CqrsModule,
    EventStoreModule.registerFeature({
      type: 'event-store',
      featureStreamName: '$svc-identity-organization',
      eventHandlers: {
        OrganizationCreatedEvent: (payload: OrganizationCreatedPayload) => new OrganizationCreatedEvent(payload),
        OrganizationUpdatedEvent: (payload: OrganizationUpdatedPayload) => new OrganizationUpdatedEvent(payload),
      },
      subscriptions: []
    }),
    MongooseModule.forFeature([{ name: OrganizationDto.name, schema: OrganizationSchema }], connectionName),
    UsersModule,
  ],
  providers: [
    OrganizationsResolver,
    ...QueryHandlers,
    ...CommandHandlers,
    OrganizationsService
  ],
  exports: [
    OrganizationsService
  ],
})
export class OrganizationsModule { }

App Module

const modules = [
  UsersModule,
  OrganizationsModule,
  AuthModule,
  PluginsModule,
];

const graphQlConfig = GraphQLModule.forRoot({
  include: [...modules],
  debug: process.env.ENVIRONMENT === 'local',
  playground: process.env.ENVIRONMENT === 'local',
  autoSchemaFile: true,
  context: ({ req }) => ({ req }),
});

@Module({
  imports: [
    MongooseModule.forRoot(connString, {
      connectionName: connectionName,
      dbName: dbName,
      useNewUrlParser: true,
      useUnifiedTopology: true,
      readPreference: ReadPreference.SECONDARY_PREFERRED,
    }),
    EventStoreModule.register({
      type: 'event-store',
      tcpEndpoint: {
        host: process.env.EVENT_STORE_HOSTNAME,
        port: +process.env.EVENT_STORE_PORT,
      },
      options: {
        maxRetries: 10,
        maxReconnections: 10,
        reconnectionDelay: 1000,
        heartbeatInterval: 5000,
        heartbeatTimeout: 1000,
        defaultUserCredentials: {
          password: process.env.EVENT_STORE_PASSWORD,
          username: process.env.EVENT_STORE_USERNAME,
        },
      },
    }),
    ...modules,
    graphQlConfig,
  ],
  providers: [
    AuthStartResolver,
    AuthCompleteResolver,
    GlobalExceptionFilter,
  ],
})
export class AppModule {
  async onModuleInit() { }
}

Regardless of the type of event that occurs, everything is being published to Event Store in the $svc-identity-user stream, but if I were to change the orders of the modules imported within the AppModule so that the OrganizationsModule was imported first then everything would publish to the $svc-identity-organization stream.

I may be misunderstanding the feature registrations and/or eventHandlers within each registration but ideally I'll be able to publish different streams per microservice, and similarly then subscribe to those different streams within my other microservices (as well as register and publish events the same way in those microservices). Any guidance would be greatly appreciated.

@artalat
Copy link

artalat commented Feb 7, 2022

Running into this issue myself, did you ever find a work around to this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants