@nestjs/common#INestMicroservice TypeScript Examples

The following examples show how to use @nestjs/common#INestMicroservice. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: nest-factory.d.ts    From nest-jaeger with MIT License 6 votes vote down vote up
/**
     * Creates an instance of NestMicroservice.
     *
     * @param module Entry (root) application module class
     * @param options Optional microservice configuration
     *
     * @returns A promise that, when resolved,
     * contains a reference to the NestMicroservice instance.
     */
    createMicroservice<T extends object>(module: any, options?: NestMicroserviceOptions & T): Promise<INestMicroservice>;
Example #2
Source File: nest-application.d.ts    From nest-jaeger with MIT License 5 votes vote down vote up
connectMicroservice<T extends object>(microserviceOptions: T, hybridAppOptions?: NestHybridApplicationOptions): INestMicroservice;
Example #3
Source File: nest-application.d.ts    From nest-jaeger with MIT License 5 votes vote down vote up
getMicroservices(): INestMicroservice[];
Example #4
Source File: app-async.e2e-spec.ts    From nestjs-kafka with The Unlicense 5 votes vote down vote up
describe('AppModule Async (e2e)', () => {
    let app: INestMicroservice;
    let controller: TestConsumer;

    beforeAll(async () => {
        jest.setTimeout(10000);

        await Utils.schemaRegistrySetup();
        
        const moduleFixture: TestingModule = await Test.createTestingModule({
            imports: [AppModule]
        }).compile();

        app = moduleFixture.createNestMicroservice({});
        app.enableShutdownHooks();
        await app.listenAsync();

        controller = await app.resolve(TestConsumer);
        controller.messages = [];
    });

    afterAll(async () => {
        await app.close();
    });

    beforeEach(async () => {
        await Utils.sleep(2000);

        controller = await app.resolve(TestConsumer);
        controller.messages = [];
    });

    it('We can SEND and ACCEPT AVRO messages', async () => {
        await Utils.sleep(2000);

        await controller.sendMessage({ messages });

        let count = 0;
        while (controller.messages.length < messages.length && count < 4) {
            await Utils.sleep(1000);
            count++;
        }

        expect(controller.messages.length).toBe(messages.length);
        expect(controller.messages.find((x) => x.id == messages[0].value.id)).toBeDefined();
        expect(controller.messages.find((x) => x.id == messages[1].value.id)).toBeDefined();
    });
});
Example #5
Source File: app-sync.e2e-spec.ts    From nestjs-kafka with The Unlicense 5 votes vote down vote up
describe('AppModule Sync (e2e)', () => {
    let app: INestMicroservice;
    let controller: TestConsumer;

    beforeAll(async () => {
        jest.setTimeout(10000);

        await Utils.schemaRegistrySetup();

        const moduleFixture: TestingModule = await Test.createTestingModule({
            imports: [AppModule]
        }).compile();

        app = moduleFixture.createNestMicroservice({});
        app.enableShutdownHooks();
        await app.listenAsync();
    });

    afterAll(async () => {
        await app.close();
    });

    beforeEach(async () => {
        await Utils.sleep(2000);

        controller = await app.resolve(TestConsumer);
        controller.messages = [];
    });

    it('We can SEND and ACCEPT AVRO messages', async () => {
        await Utils.sleep(2000);

        await controller.sendMessage({ messages });

        let count = 0;
        while (controller.messages.length < messages.length && count < 4) {
            await Utils.sleep(1000);
            count++;
        }

        expect(controller.messages.length).toBe(messages.length);
        expect(controller.messages.find((x) => x.id == messages[0].value.id)).toBeDefined();
        expect(controller.messages.find((x) => x.id == messages[1].value.id)).toBeDefined();
    });
});