Repository navigation
fix(microservices): unwrap records returned by message handlers - #18008
Merged
Merged
Conversation
A handler that returns an MqttRecord, NatsRecord or RmqRecord sent the
whole record to the client. The record options were dropped.
The server builds the reply as { response, isDisposed, id }. The record
checks and the record serializers read only the data field, so they
never saw the record in response.
MQTT: the serializer unwraps the record in response. The publisher
passes the record options (QoS, retain, properties) to publish. This
change removes the dead delete of data.options.
NATS: the serializer unwraps the record in response and returns its
headers. The reply sends them with respond.
RMQ: the serializer unwraps the record in response and returns its
options. The reply sends them with sendToQueue. The correlation id of
the request wins over a record option, so the client still matches the
reply. Before this fix, record options never reached sendToQueue.
The MQTT and RMQ record serializer types now accept a reply packet.
Closes nestjs#18007
Merged
3 of 10 tasks
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
PR Type
What is the current behavior?
Issue Number: #18007
Closes #18007
Hi! π A
@MessagePattern()handler that returns anMqttRecord,NatsRecordorRmqRecordsends the whole record to the client, and the record options are dropped.The server builds the reply as
{ response, isDisposed, id }. The record checks and the record serializers read onlypacket.data, so they never see the record inpacket.response.ServerMqtt.getPublisher()already tries to handle anMqttRecord, but it readsresponse.data, which is alwaysundefinedon a reply.I ran the repro on 12.1.2 with real brokers. The three clients got
{ data, options }or{ data, headers }, and the replies had no record options:What is the new behavior?
response. The publisher passes the record options (QoS, retain, properties) topublish. This change removes the deaddeleteofdata.options.responseand returns its headers. The reply sends them withrespond.responseand returns its options. The reply sends them withsendToQueue. The correlation id of the request wins over a record option, so the client still matches the reply.The same repro against a local build of this branch:
Does this PR introduce a breaking change?
A handler that returns a plain object, and a client that sends a record, take the same path as before.
One type note: the MQTT and RMQ record serializer types now accept a reply packet. The NATS serializer already took
any. The serializers are not exported from the package root. A deep import ofRmqRecordSerializernow seesdataandpatternas optional in its output type.Other information
The new record specs use the real reply packet shape. They cover these cases:
Server.send()with a handler that returns a record: the transport gets the record data,isDisposedand the record options.dataandoptionsorheaderskeys. The MQTT and NATS specs also cover a primitive reply. The serializers also accept anundefinedornullpacket.The older
ServerMqttandServerNatsspecs used a packet shape that the server never builds, so they did not catch this. The new specs fix that shape.The docs show record builders only on the client, with
client.send(). I am happy to open a docs PR that shows a record in a handler too. π