stream-lua的receive(1)方法的正确使用方法?

178 views
Skip to first unread message

Bocer

unread,
Jan 7, 2019, 4:17:28 AM1/7/19
to openresty
想使用openresty搭建一个业务的路由系统,各系统间都是socket短连接,传递不定长的字符串报文。
源系统通过socket短连接发送一个字符串到openresty,通过steam模块接收并解析报文首位的路由码,根据路由码将报文路由到不同的后台服务器,并将后台服务器的返回报文转回给源系统。
1.在使用receive方法接收源系统发起的报文时,因为字符串报文并不存在行的概念,另外在接收的时候,不能关闭连接,所以*a,*l参数无法使用。
2.receiveany方法没有实现? attempt to call method 'receiveany' ( a nil value)
3.sock:receiveuntil()能够实现要求,但是现有业务系统必须全部改造,来添加终止标志串
4.看到别人提过receive(1),自己写了一段,但为什么每次都是等到超时时间后,才能继续执行?是循环条件不对吗?error.log也会出现一条stream lua tcp socket read time Out错误,有没有方法在读取字符串结束后立即进行后续处理,不必等到超时结束?

local line =""
repeat
   
local  text,err,partial  =  sock:receive(1)
   
if not  text  then
       
break
   
end
   line  
=  line..text
until (not  text  and  not  partial)
ngx
.say(line)






Yuansheng Wang

unread,
Jan 8, 2019, 11:04:23 PM1/8/19
to open...@googlegroups.com
On Mon, Jan 7, 2019 at 5:17 PM Bocer <yyg...@gmail.com> wrote:
想使用openresty搭建一个业务的路由系统,各系统间都是socket短连接,传递不定长的字符串报文。
源系统通过socket短连接发送一个字符串到openresty,通过steam模块接收并解析报文首位的路由码,根据路由码将报文路由到不同的后台服务器,并将后台服务器的返回报文转回给源系统。
1.在使用receive方法接收源系统发起的报文时,因为字符串报文并不存在行的概念,另外在接收的时候,不能关闭连接,所以*a,*l参数无法使用。
2.receiveany方法没有实现? attempt to call method 'receiveany' ( a nil value)

你可以用春哥前些日子发布的 rc 版本,应该是包含这个 API 的。

 
3.sock:receiveuntil()能够实现要求,但是现有业务系统必须全部改造,来添加终止标志串
4.看到别人提过receive(1),自己写了一段,但为什么每次都是等到超时时间后,才能继续执行?是循环条件不对吗?error.log也会出现一条stream lua tcp socket read time Out错误,有没有方法在读取字符串结束后立即进行后续处理,不必等到超时结束?

local line =""
repeat
   
local  text,err,partial  =  sock:receive(1)
   
if not  text  then
       
break
   
end
   line  
=  line..text
until (not  text  and  not  partial)
ngx
.say(line)






--
--
邮件来自列表“openresty”,专用于技术讨论!
订阅: 请发空白邮件到 openresty...@googlegroups.com
发言: 请发邮件到 open...@googlegroups.com
退订: 请发邮件至 openresty+...@googlegroups.com
归档: http://groups.google.com/group/openresty
官网: http://openresty.org/
仓库: https://github.com/agentzh/ngx_openresty
教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html


--

Yuansheng +86-18600159913
OpenResty Inc.
Reply all
Reply to author
Forward
0 new messages