-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
I'm not able to set headers for NATS response #10273
Comments
Please provide a minimum reproduction repository (Git repository/StackBlitz/CodeSandbox project). why reproductions are required |
Added, maybe it was needed 😅 |
I think that the problem is with serializer and it's execution (from publisher) which should respect those headers (now it's omitting them) ;) |
Would you like to create a PR for this issue? |
@kamilmysliwiec no problem, the question is -> should I add check if return value from message pattern method is NatsRecord instance and then respect it's headers in default serializer? This could do the job but it will be a breaking change 💩
serialize(packet) {
if (packet?.data) {
let natsMessage = void 0;
if (packet.data instanceof NatsRecord) {
natsMessage = packet.data;
} else {
// should we handle packet.headers?
natsMessage = new NatsRecordBuilder(packet?.data).build();
}
return {
data: this.jsonCodec.encode({ ...packet, data: natsMessage.data })),
headers: natsMessage.headers,
};
} else if (packet?.response) {
if (packet.response instanceof NatsRecord) {
return {
data: this.jsonCodec.encode({ ...packet, data: void 0 })),
headers: packet.response.headers,
};
}
// should we handle packet.headers?
const natsMessage = new NatsRecordBuilder(packet?.data).build();
return {
data: this.jsonCodec.encode({ ...packet, data: natsMessage.data })),
headers: natsMessage.headers,
};
}
// throw?
}
// ...
const { err, response, isDisposed } = message;
// sick but could do the job 🤔 the problem is that we're not able to recognize if payload was not serialized with custom serializer 😢
response.headers = natsMsg.headers;
if (isDisposed || err) {
return callback({
err,
response,
isDisposed: true,
});
}
//... If we're able to discuss the solution first and agree on smth then I can implement everything 😂 |
Line changer in However forcing developers from v10 to respect serializers and deserializers to implement interface (object with data and headers at least as a |
@jmcdo29 @kamilmysliwiec so what's the plan? 😅 |
SGTM |
Is there an existing issue for this?
Current behavior
I want to send back from my method decorated with MessagePattern/EventPattern data with NATS headers and turns out that they're not passed in any way.
I tried with setting
with hope that they will be applied but with no luck - they're
undefined
😂Minimum reproduction code
https://github.com/Dzixxx/nestjs-typescript-starter-we4m7w
Steps to reproduce
No response
Expected behavior
I would expect that
@Ctx() context: NatsContext
will have methodsetResponseHeader
and inServerNats.getPublisher
method it will apply them to packet and default serializer will handle it:I'm open for any solution and even preparing PR (but I will need some help with preparing the solution)
Dziczek 😉
Package
@nestjs/common
@nestjs/core
@nestjs/microservices
@nestjs/platform-express
@nestjs/platform-fastify
@nestjs/platform-socket.io
@nestjs/platform-ws
@nestjs/testing
@nestjs/websockets
Other package
No response
NestJS version
9
Packages versions
Node.js version
16
In which operating systems have you tested?
Other
No response
The text was updated successfully, but these errors were encountered: