Request/reply for MQTT 5.0 via zmqtt's native client.request().
zmqtt auto-generates a unique reply topic. We pass our correlation ID explicitly so the responder echoes it back and the caller can verify it on the response StreamMessage.
Source code in faststream/mqtt/publisher/producer.py
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217 | @override
async def request(self, cmd: "MQTTPublishCommand") -> "zmqtt.Message":
"""Request/reply for MQTT 5.0 via zmqtt's native client.request().
zmqtt auto-generates a unique reply topic. We pass our correlation
ID explicitly so the responder echoes it back and the caller can
verify it on the response StreamMessage.
"""
payload, content_type = await self.codec.encode(cmd.body, self.serializer)
correlation_id = cmd.correlation_id or self.id_generator()
user_props: list[tuple[str, str]] = [
(k, str(v)) for k, v in (cmd.headers or {}).items()
]
# Pass correlation_data explicitly so the responder echoes it back.
# Do NOT set response_topic — let zmqtt generate it.
properties = PublishProperties(
content_type=content_type or None,
correlation_data=correlation_id.encode(),
user_properties=tuple(user_props),
message_expiry_interval=cmd.message_expiry_interval,
)
return await self._connected_client.request(
cmd.destination,
payload,
qos=cmd.qos,
timeout=cmd.timeout or 30.0,
properties=properties,
)
|