Microservices interaction with external services
See original GitHub issueI’m submitting a…
[ ] Regression
[X ] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
When using nestjs as a NATS microservice, the nats payload (data), when using the @MessagePattern decorator, is always undefined.
@MessagePattern('sms.send')
test(data: any) {
console.log('function called OK');
console.log(data); // Allways undefined
}
In the provided example I can log “function called OK” but data is allways undefined.
Here is my main.ts
import { NestFactory } from '@nestjs/core';
import { Transport } from '@nestjs/microservices';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.createMicroservice(AppModule, {
transport: Transport.NATS,
options: {
url: 'nats://nats:4222',
queue: 'sms',
},
});
app.listen(() => console.log('Microservice is listening'));
}
bootstrap();
I have tried both regular strings and json encoded objects as valid payloads.
Expected behavior
data should not be undefined
Minimal reproduction of the problem with instructions
What is the motivation / use case for changing the behavior?
Environment
Nest version: X.Y.Z
For Tooling issues:
- Node version: XX
- Platform:
Others:
Issue Analytics
- State:
- Created 4 years ago
- Comments:16 (7 by maintainers)
Top Results From Across the Web
Interservice communication in microservices - Microsoft Learn
Synchronous communication. In this pattern, a service calls an API that another service exposes, using a protocol such as HTTP or gRPC.
Read more >Microservices Communications - Medium
Because microservices are distributed and microservices communicate with each other by inter-service communication on network level.
Read more >Chapter 8. External API patterns - Microservices Patterns
Figure 8.9. The API gateway's API consists of a graph-based schema that's mapped to the services. A client issues a query that retrieves...
Read more >Microservices with External Integration
Searching for micro services integrate external service gives lots of information. – Greg Burghardt. May 14, 2020 at 11:30. 2.
Read more >Microservices External API Integration Patterns
Direct Communication It is possible to design APIs in such a way that clients can directly invoke the services. Microservice architecture.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I dont think it is a documentation issue, I think is the way that Nest microservices communicate via NATS is incorrect in that a NATS payload should be by default an arbitairy string not an opiniated JSON object.
@kamilmysliwiec
Are there any plans to allow custom shape? I’d like to migrate our services to NestJS, but we currently use this shape:
So far, this is really the only hurdle for our migration to NestJS. Awesome framework!
[EDIT]
Is there a way to add translation logic for messages? I tried using an Interceptor, but
undefined
is the only element in thecontext.args
array. Looks like Nest is pulling out thedata
property before the Interceptor is called.