stream特别MQTT都是长连接,preread自然仅在初始连接时有效,并且仅仅是用来做最初检查。你如果要过滤所有报文,意味着你必须读取socket传入的数据,这会导致socket内的数据无法向后传递
It is possible to acquire the raw request socket using ngx.req.socket and receive data from or send data to the client. However, keep in mind that calling the receive() method of the request socket will consume the data from the buffer and such consumed data will not be seen by handlers further down the chain.
所以,如果要过滤的话,你可能不能用单纯的反向处理,而是需要将服务器作为一个独立的MQTT服务器,接受数据,然后同时作为一个mqtt client转发数据到目标mqtt服务器。