-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
61 changed files
with
1,906 additions
and
753 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,5 +34,6 @@ module.exports = { | |
WeakSet: 'readonly', | ||
Promise: 'readonly', | ||
Reflect: 'readonly', | ||
Symbol: 'readonly', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,4 +35,4 @@ coverage/ | |
*.tgz | ||
|
||
*.txt | ||
*.gql | ||
*.gql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
version: "3.3" | ||
services: | ||
mqtt: | ||
image: eclipse-mosquitto | ||
container_name: mqtt | ||
ports: | ||
- "1883:1883" | ||
rabbitmq: | ||
image: rabbitmq | ||
container_name: rabbit | ||
ports: | ||
- "5672:5672" | ||
# zookeeper: | ||
# container_name: kafka-zookeeper | ||
# hostname: zookeeper | ||
# image: confluentinc/cp-zookeeper:5.3.2 | ||
# ports: | ||
# - "2181:2181" | ||
# environment: | ||
# ZOOKEEPER_CLIENT_PORT: 2181 | ||
# ZOOKEEPER_TICK_TIME: 2000 | ||
# kafka: | ||
# container_name: kafka | ||
# hostname: kafka | ||
# image: confluentinc/cp-kafka:5.3.2 | ||
# depends_on: | ||
# - zookeeper | ||
# ports: | ||
# - "29092:29092" | ||
# - "9092:9092" | ||
# environment: | ||
# KAFKA_BROKER_ID: 1 | ||
# KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 | ||
# KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT | ||
# KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092 | ||
# KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 | ||
# KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0 | ||
# grpc: | ||
nats: | ||
image: nats | ||
container_name: nats | ||
ports: | ||
- "4222:4222" | ||
# redis: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ArgumentsHost, Catch, HttpException } from '@nestjs/common'; | ||
import { BaseExceptionFilter } from '@nestjs/core'; | ||
|
||
@Catch() | ||
export class ExceptionFilter extends BaseExceptionFilter { | ||
catch(exception: HttpException, host: ArgumentsHost) { | ||
const res = host.switchToHttp().getResponse(); | ||
res.send(exception); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { | ||
Controller, | ||
Get, | ||
Inject, | ||
OnModuleInit, | ||
UseFilters, | ||
} from '@nestjs/common'; | ||
import { ClientGrpc } from '@nestjs/microservices'; | ||
import { ExceptionFilter } from './exception.filter'; | ||
import { HelloService } from './hello-service.interface'; | ||
|
||
@Controller() | ||
export class GrpcClientController implements OnModuleInit { | ||
private helloService: HelloService; | ||
|
||
constructor(@Inject('GRPC_SERVICE') private readonly grpc: ClientGrpc) {} | ||
|
||
async onModuleInit() { | ||
this.helloService = this.grpc.getService<HelloService>('HelloService'); | ||
} | ||
@Get() | ||
sayHello() { | ||
return this.helloService.sayHello({ ip: '127.0.0.1' }); | ||
} | ||
|
||
@Get('error') | ||
@UseFilters(ExceptionFilter) | ||
sayError() { | ||
return this.helloService.sayError({ ip: '127.0.0.1' }); | ||
} | ||
|
||
@Get('skip') | ||
saySkip() { | ||
return this.helloService.saySkip({ ip: '127.0.0.1' }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { ClientsModule, Transport } from '@nestjs/microservices'; | ||
import { join } from 'path'; | ||
import { GrpcClientController } from './grpc-client.controller'; | ||
|
||
@Module({ | ||
imports: [ | ||
ClientsModule.register([ | ||
{ | ||
transport: Transport.GRPC, | ||
name: 'GRPC_SERVICE', | ||
options: { | ||
package: 'hello', | ||
protoPath: join(__dirname, '..', 'hello/hello.proto'), | ||
}, | ||
}, | ||
]), | ||
], | ||
controllers: [GrpcClientController], | ||
}) | ||
export class GrpcClientModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface HelloService { | ||
sayHello(data: { ip?: string }): { hello: string }; | ||
sayError(data: { ip?: string }): { hello: string }; | ||
saySkip(data: { ip?: string }): { hello: string }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
syntax="proto3"; | ||
|
||
package hello; | ||
|
||
service HelloService { | ||
rpc SayHello (Ip) returns (Greeting) {} | ||
|
||
rpc SayError (Ip) returns (Greeting) {} | ||
|
||
rpc SaySkip (Ip) returns (Greeting) {} | ||
} | ||
|
||
message Greeting { | ||
string hello = 1; | ||
} | ||
|
||
message Ip { | ||
optional string ip = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Catch, HttpException } from '@nestjs/common'; | ||
import { BaseRpcExceptionFilter } from '@nestjs/microservices'; | ||
import { Observable, throwError } from 'rxjs'; | ||
|
||
@Catch() | ||
export class ExceptionFilter extends BaseRpcExceptionFilter { | ||
catch(exception: HttpException): Observable<any> { | ||
return throwError(exception.message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { BadRequestException, Controller, UseFilters } from '@nestjs/common'; | ||
import { GrpcMethod } from '@nestjs/microservices'; | ||
import { OgmaSkip } from '@ogma/nestjs-module'; | ||
import { AppService } from '../../app.service'; | ||
import { ExceptionFilter } from './exception.filter'; | ||
|
||
@Controller() | ||
export class GrpcServerController { | ||
constructor(private readonly service: AppService) {} | ||
|
||
@GrpcMethod('HelloService', 'SayHello') | ||
sayHello() { | ||
return this.service.getHello(); | ||
} | ||
|
||
@GrpcMethod('HelloService', 'SayError') | ||
@UseFilters(ExceptionFilter) | ||
sayError() { | ||
throw new BadRequestException('Borked'); | ||
} | ||
|
||
@OgmaSkip() | ||
@GrpcMethod('HelloService', 'SaySkip') | ||
saySkip() { | ||
return this.service.getHello(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { AppService } from '../../app.service'; | ||
import { GrpcServerController } from './grpc-server.controller'; | ||
|
||
@Module({ | ||
controllers: [GrpcServerController], | ||
providers: [AppService], | ||
}) | ||
export class GrpcServerModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ArgumentsHost, Catch, HttpException } from '@nestjs/common'; | ||
import { BaseExceptionFilter } from '@nestjs/core'; | ||
|
||
@Catch() | ||
export class ExceptionFilter extends BaseExceptionFilter { | ||
catch(exception: HttpException, host: ArgumentsHost) { | ||
const res = host.switchToHttp().getResponse(); | ||
res.send(exception); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { | ||
Controller, | ||
Get, | ||
Inject, | ||
OnModuleDestroy, | ||
OnModuleInit, | ||
UseFilters, | ||
} from '@nestjs/common'; | ||
import { ClientKafka } from '@nestjs/microservices'; | ||
import { ExceptionFilter } from './exception.filter'; | ||
|
||
@Controller() | ||
export class KafkaClientController implements OnModuleInit, OnModuleDestroy { | ||
constructor(@Inject('KAFKA_SERVICE') private readonly kafka: ClientKafka) {} | ||
|
||
async onModuleInit() { | ||
['hello', 'error', 'skip'].forEach((key) => | ||
this.kafka.subscribeToResponseOf(`say.${key}`), | ||
); | ||
} | ||
|
||
onModuleDestroy() { | ||
this.kafka.close(); | ||
} | ||
|
||
@Get() | ||
sayHello() { | ||
return this.kafka.send('say.hello', { ip: '127.0.0.1' }); | ||
} | ||
|
||
@Get('error') | ||
@UseFilters(ExceptionFilter) | ||
sayError() { | ||
return this.kafka.send('say.error', { ip: '127.0.0.1' }); | ||
} | ||
|
||
@Get('skip') | ||
saySkip() { | ||
return this.kafka.send('say.skip', { ip: '127.0.0.1' }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Module } from '@nestjs/common'; | ||
// import { ClientsModule, Transport } from '@nestjs/microservices'; | ||
import { KafkaClientController } from './kafka-client.controller'; | ||
|
||
@Module({ | ||
imports: [ | ||
/* ClientsModule.register([ | ||
{ | ||
name: 'KAFKA_SERVICE', | ||
transport: Transport.KAFKA, | ||
options: { | ||
client: { | ||
clientId: 'client', | ||
brokers: ['localhost:9092'], | ||
}, | ||
consumer: { | ||
groupId: 'client-consumer', | ||
}, | ||
}, | ||
}, | ||
]), */ | ||
], | ||
controllers: [KafkaClientController], | ||
}) | ||
export class KafkaClientModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Catch, HttpException } from '@nestjs/common'; | ||
import { BaseRpcExceptionFilter } from '@nestjs/microservices'; | ||
import { Observable, throwError } from 'rxjs'; | ||
|
||
@Catch() | ||
export class ExceptionFilter extends BaseRpcExceptionFilter { | ||
catch(exception: HttpException): Observable<any> { | ||
return throwError(exception.message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { BadRequestException, Controller, UseFilters } from '@nestjs/common'; | ||
import { MessagePattern } from '@nestjs/microservices'; | ||
import { OgmaSkip } from '@ogma/nestjs-module'; | ||
import { AppService } from '../../app.service'; | ||
import { ExceptionFilter } from './exception.filter'; | ||
|
||
@Controller() | ||
export class KafkaServerController { | ||
constructor(private readonly service: AppService) {} | ||
|
||
@MessagePattern('say.hello') | ||
sayHello() { | ||
return this.service.getHello(); | ||
} | ||
|
||
@UseFilters(ExceptionFilter) | ||
@MessagePattern('say.error') | ||
sayError() { | ||
throw new BadRequestException('Borked'); | ||
} | ||
|
||
@OgmaSkip() | ||
@MessagePattern('say.skip') | ||
saySkip() { | ||
return this.service.getHello(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { AppService } from '../../app.service'; | ||
import { KafkaServerController } from './kafka-server.controller'; | ||
|
||
@Module({ | ||
controllers: [KafkaServerController], | ||
providers: [AppService], | ||
}) | ||
export class KafkaServerModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.