@override
async def publish(self, cmd: "RedisPublishCommand") -> int | bytes:
body = await build_message(
message=cmd.body,
reply_to=cmd.reply_to,
correlation_id=cmd.correlation_id or self.broker.config.id_generator(),
headers=cmd.headers,
message_format=cmd.message_format,
serializer=self.broker.config.fd_config._serializer,
codec=self.codec,
)
destination = _make_destination_kwargs(cmd)
visitors = (ChannelVisitor(), ListVisitor(), StreamVisitor())
session_id = uuid.uuid4()
for visitor, visited_ch, handler in self._find_handlers(
destination=destination,
visitors=visitors,
cmd=cmd,
session_id=session_id,
):
msg = visitor.get_message(
visited_ch,
body,
handler,
)
self._put_pel(msg=msg, cmd=cmd, handler=handler, session_id=session_id)
await self._execute_handler(msg, handler, session_id=session_id)
return 0