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

feat(microservices): errors thrown during eachMessage execution should be passed to kafkajs #9293

Closed
wants to merge 53 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
5b24f81
feat(microservices): add commit offset to kafka context
davidschuette Mar 4, 2022
77b7bd6
feat(microservices): dont catch errors thrown by kafka event handling
davidschuette Mar 4, 2022
c229a75
fix(microservices): fix import path
davidschuette Mar 4, 2022
b91803c
feat(microservices): add consumer getter to kafka context
davidschuette Mar 7, 2022
0b93404
refactor(microservices): simplify function call
davidschuette Mar 10, 2022
37d83ee
test(microservices): add tests for kafka-rpc-proxy
davidschuette Mar 10, 2022
50cfa23
chore(deps-dev): bump @nestjs/graphql from 10.0.3 to 10.0.4
dependabot[bot] Feb 21, 2022
d0a22ae
docs(websockets): update GatewayMetadata pingTimeout default value to…
yevgeniypak Feb 21, 2022
06a4b0b
docs(websockets): add numeric separators to numeric literals
yevgeniypak Feb 22, 2022
61272da
chore(deps): update dependency @babel/cli to v7.17.6
renovate-bot Feb 22, 2022
8cf980c
chore(deps-dev): bump mongoose from 6.2.2 to 6.2.3
dependabot[bot] Feb 22, 2022
d454c7f
chore(deps): update dependency @nestjs/schematics to v8.0.7
renovate-bot Feb 28, 2022
9a89f50
chore(deps): bump url-parse from 1.5.6 to 1.5.10
dependabot[bot] Feb 28, 2022
14b55f8
feat(microservices): Add options param to serializer
guiruiz Feb 15, 2022
838adbb
fix(common): Providing typing for optional error handling in middleware
brian-pinwheel Feb 23, 2022
1b2b69b
feat(common): extend streamable-file header support
davidschuette Feb 21, 2022
02d1766
feat(common): add length header to streamable-file
davidschuette Feb 23, 2022
d54f539
feat(core): support optional dependencies in factory providers
kamilmysliwiec Feb 18, 2022
63285c6
fix(core): fix optional factory provider condition
kamilmysliwiec Feb 21, 2022
ac81c2f
test(): add more tests around optional factory dependency
kamilmysliwiec Feb 21, 2022
05d3eb3
feat(common): add abstract type to catch decorator
jeean Feb 16, 2022
d4cadfa
fix(core): use class refs as keys (container)
micalevisk Feb 28, 2022
560b95c
test(integration): add tests for self-injections providers
micalevisk Feb 28, 2022
55ca49c
feat(common): Add custom versioning support
adworacz Nov 16, 2021
58aa164
chore(): minor formatting changes
kamilmysliwiec Mar 1, 2022
05b63ac
fix(microservices): remove options object from packets (rmq and mqtt)
kamilmysliwiec Mar 1, 2022
1e4b970
fix(microservices): mqtt shared subscription support
tensoar Sep 22, 2021
69b9363
test(microservices): change mqtt docker image
tensoar Jan 2, 2022
f187eed
test(microservices): Open websocket in mosquitto
tensoar Jan 2, 2022
fb8f5e4
fix(core): address compilation errors
kamilmysliwiec Mar 1, 2022
20409a0
refactor(microservices): move tcp socket logic to an abstract class
jeanbmar Jan 30, 2022
9e76e72
feat(microservices): allow use of custom tcp sockets
jeanbmar Jan 30, 2022
71381cb
chore(@nestjs) publish v8.4.0 release
kamilmysliwiec Mar 1, 2022
0093ad2
chore(): update package.json and readmes
kamilmysliwiec Mar 1, 2022
2b7564e
fix(gateways): add the socket.io types dependency
capitantrueno Feb 24, 2022
417af63
fix(gateways): add the socket.io dependency
capitantrueno Feb 24, 2022
ce31cfe
sample(23-code-first): add missing directive declaration
kamilmysliwiec Mar 3, 2022
22ac987
chore: add .devcontainer to gitignore
Mar 5, 2022
eb1abb1
chore(deps): update dependency @nestjs/schematics to v8.0.8
renovate-bot Mar 8, 2022
89a2dc7
chore(deps): update dependency mysql to v8.0.28
renovate-bot Mar 14, 2022
365532e
chore(deps): update dependency @types/node to v16.11.26
renovate-bot Mar 14, 2022
38f08ca
fix(core): use context module for nested transient providers
kamilmysliwiec Mar 11, 2022
f08ed93
feat: allow custom log formatters
Mar 10, 2022
50c54d7
refactor: extract colorize
Mar 11, 2022
b7ea263
feat: extract protected method for pid
Mar 11, 2022
aeb3158
fix(microservices): tcp client parallel connections issue
kamilmysliwiec Mar 7, 2022
8fca491
feat(common): do not use color in CLI if not supported
jonahsnider Mar 1, 2022
f4b6eea
fix(common): fix condition
jonahsnider Mar 1, 2022
a79ac03
style(common): format
jonahsnider Mar 1, 2022
3f59c09
style(common): format
jonahsnider Mar 2, 2022
2fb8bf8
fix(core): apply global middleware to routes excluded from prefix
kamilmysliwiec Mar 14, 2022
75eb3f0
chore(@nestjs) publish v8.4.1 release
kamilmysliwiec Mar 14, 2022
a09572e
fix(microservices): fix handling of errors when using observables
davidschuette May 1, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ node_modules/
/.idea
/.awcache
/.vscode
/.devcontainer
*.code-workspace

# bundle
Expand Down
6 changes: 4 additions & 2 deletions integration/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ services:
restart: always
mqtt:
container_name: test-mqtt
image: toke/mosquitto
image: eclipse-mosquitto
volumes:
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf
ports:
- "1883:1883"
- "9001:9001"
restart: always
mysql:
image: mysql:8.0.27
image: mysql:8.0.28
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: test
Expand Down
56 changes: 56 additions & 0 deletions integration/injector/e2e/injector.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import { RuntimeException } from '@nestjs/core/errors/exceptions/runtime.exception';
import { UnknownDependenciesException } from '@nestjs/core/errors/exceptions/unknown-dependencies.exception';
import { UnknownExportException } from '@nestjs/core/errors/exceptions/unknown-export.exception';
import { Test } from '@nestjs/testing';
import { expect } from 'chai';
import * as chai from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
import {
DYNAMIC_TOKEN,
DYNAMIC_VALUE,
NestDynamicModule,
} from '../src/dynamic/dynamic.module';
import { ExportsModule } from '../src/exports/exports.module';
import { InjectModule } from '../src/inject/inject.module';
import { InjectSameNameModule } from '../src/inject/inject-same-name.module';
import {
SelfInjectionProviderModule,
SelfInjectionProviderCustomTokenModule,
SelfInjectionForwardProviderModule,
} from '../src/self-injection/self-injection-provider.module';
chai.use(chaiAsPromised);

describe('Injector', () => {
describe('when "providers" and "exports" properties are inconsistent', () => {
Expand All @@ -24,6 +34,16 @@ describe('Injector', () => {
});
});

describe("When class injects a provider with the same as class's name", () => {
it('should compile with success', async () => {
const builder = Test.createTestingModule({
imports: [InjectSameNameModule],
});

await expect(builder.compile()).to.eventually.be.fulfilled;
});
});

describe('when Nest cannot resolve dependencies', () => {
it(`should fail with "RuntimeException"`, async () => {
try {
Expand All @@ -35,6 +55,42 @@ describe('Injector', () => {
expect(err).to.be.instanceof(RuntimeException);
}
});

describe('due to self-injection providers', () => {
it('should fail with "UnknownDependenciesException" due to self-injection via same class reference', async () => {
const builder = Test.createTestingModule({
imports: [SelfInjectionProviderModule],
});

await expect(
builder.compile(),
).to.eventually.be.rejected.and.be.an.instanceOf(
UnknownDependenciesException,
);
});
it('should fail with "UnknownDependenciesException" due to self-injection via forwardRef to the same class reference', async () => {
const builder = Test.createTestingModule({
imports: [SelfInjectionForwardProviderModule],
});

await expect(
builder.compile(),
).to.eventually.be.rejected.and.be.an.instanceOf(
UnknownDependenciesException,
);
});
it('should fail with "UnknownDependenciesException" due to self-injection via custom provider', async () => {
const builder = Test.createTestingModule({
imports: [SelfInjectionProviderCustomTokenModule],
});

await expect(
builder.compile(),
).to.eventually.be.rejected.and.be.an.instanceOf(
UnknownDependenciesException,
);
});
});
});

describe('when dynamic module', () => {
Expand Down
96 changes: 96 additions & 0 deletions integration/injector/e2e/optional-factory-provider-dep.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { UnknownDependenciesException } from '@nestjs/core/errors/exceptions/unknown-dependencies.exception';
import { Test } from '@nestjs/testing';
import { expect } from 'chai';

describe('Optional factory provider deps', () => {
describe('when dependency is optional', () => {
describe('and it is available', () => {
it('then it should be injected into the factory function', async () => {
const defaultValue = 'DEFAULT_VALUE';
const moduleRef = await Test.createTestingModule({
providers: [
{
provide: 'FACTORY',
useFactory: dep => dep ?? defaultValue,
inject: [{ token: 'MISSING_DEP', optional: true }],
},
{ provide: 'MISSING_DEP', useValue: 'OPTIONAL_DEP_VALUE' },
],
}).compile();

const factoryProvider = moduleRef.get('FACTORY');
expect(factoryProvider).to.equal('OPTIONAL_DEP_VALUE');
});
});
describe('otherwise', () => {
it('"undefined" should be injected into the factory function', async () => {
const defaultValue = 'DEFAULT_VALUE';
const moduleRef = await Test.createTestingModule({
providers: [
{
provide: 'FACTORY',
useFactory: dep => dep ?? defaultValue,
inject: [{ token: 'MISSING_DEP', optional: true }],
},
],
}).compile();

const factoryProvider = moduleRef.get('FACTORY');
expect(factoryProvider).to.equal(defaultValue);
});
});
});
describe('otherwise', () => {
describe('and dependency is not registered', () => {
it('should error out', async () => {
try {
const builder = Test.createTestingModule({
providers: [
{
provide: 'FACTORY',
useFactory: () => 'RETURNED_VALUE',
inject: ['MISSING_DEP'],
},
],
});
await builder.compile();
} catch (err) {
expect(err).to.be.instanceOf(UnknownDependenciesException);
}
});
});
});
describe('and dependency is registered but it cannot be instantiated', () => {
it('should error out', async () => {
try {
const builder = Test.createTestingModule({
providers: [
{
provide: 'POSSIBLY_MISSING_DEP',
useFactory: () => null,
inject: ['MISSING_DEP'],
},
{
provide: 'FACTORY',
useFactory: () => 'RETURNED_VALUE',
inject: [{ token: 'POSSIBLY_MISSING_DEP', optional: false }],
},
],
});
await builder.compile();
} catch (err) {
expect(err).to.be.instanceOf(UnknownDependenciesException);
expect(err.message).to
.equal(`Nest can't resolve dependencies of the POSSIBLY_MISSING_DEP (?). Please make sure that the argument MISSING_DEP at index [0] is available in the RootTestModule context.

Potential solutions:
- If MISSING_DEP is a provider, is it part of the current RootTestModule?
- If MISSING_DEP is exported from a separate @Module, is that module imported within RootTestModule?
@Module({
imports: [ /* the Module containing MISSING_DEP */ ]
})
`);
}
});
});
});
16 changes: 16 additions & 0 deletions integration/injector/src/inject/inject-same-name.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Module, Injectable, Inject } from '@nestjs/common';

@Injectable()
class CoreService {
constructor(@Inject(CoreService.name) private readonly coreService: any) {}
}

@Module({
providers: [
{
provide: CoreService.name,
useValue: 'anything',
},
],
})
export class InjectSameNameModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Module, Injectable, Inject, forwardRef } from '@nestjs/common';

@Injectable()
class ServiceInjectingItself {
constructor(private readonly coreService: ServiceInjectingItself) {}
}

@Injectable()
class ServiceInjectingItselfForwared {
constructor(
@Inject(forwardRef(() => ServiceInjectingItself))
private readonly coreService: ServiceInjectingItself,
) {}
}

@Injectable()
class ServiceInjectingItselfViaCustomToken {
constructor(@Inject('AnotherToken') private readonly coreService: any) {}
}

@Module({
providers: [ServiceInjectingItself],
})
export class SelfInjectionProviderModule {}

@Module({
providers: [ServiceInjectingItselfForwared],
})
export class SelfInjectionForwardProviderModule {}

@Module({
providers: [
ServiceInjectingItselfViaCustomToken,
{
provide: 'AnotherToken',
useClass: ServiceInjectingItselfViaCustomToken,
},
],
})
export class SelfInjectionProviderCustomTokenModule {}