Skip to content

A UDP microservice strategy implementation(with node dgram) for NestJS.

Notifications You must be signed in to change notification settings

pirumu/nest-udp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nest-udp

Docs | MIT Licensed

A UDP microservice strategy implementation(with node dgram) for NestJS.

Usage example

const hybridAppConfig = {
    host: '127.0.0.1',
    port: 6545
};
const app = await NestFactory.create(AppModule);
app.connectMicroservice({
    strategy: new UdpServer({
    bindOptions: {
        address: hybridAppConfig.host,
        port: hybridAppConfig.port
    },
    socketOptions: {
        type: SocketType.UDP4
    }
    })
});
await app.startAllMicroservices();
await app.listen(hybridAppConfig.port, hybridAppConfig.host);

Decorate your controllers with the @UdpGateway and @IncomingMessage decorators:

@UdpGateway()
@Controller()
export class UDPController {
  @IncomingMessage()
  public async message(@Payload() data, @Ctx() ctx: UdpContext) {
    console.log("incoming message");
    return data;
  }
}

About

A UDP microservice strategy implementation(with node dgram) for NestJS.

Resources

Stars

Watchers

Forks

Packages

No packages published