QuickFix

QuickFixJ

时区不对问题

现象

客户端如果不设置时区TimeZone.setDefault(TimeZone.getTimeZone(ZoneOffset.UTC));服务端就无法接收消息

问题原因

客户端在重写Application#toApp/Application#toAdmin时主动修改了SendingTime字段:message.getHeader().setField(new SendingTime(LocalDateTime.now()));。而服务端接并没有设置时区,默认就是UTC时区。也就是说客户端如果不设置UTC时区,发出的时间是北京时间9点,服务端收到后,当前时间是UTC时间1点,然后判断消息是否过期时发现这个消息不应该处理,就没有进行处理。

解决办法

发送时不要改SendingTime,因为quickfix.Session#insertSendingTime会插入一个当前时间对应的UTC时间,服务端也是UTC时间的话,正好能对应上。

原理

服务端逻辑:

# 入异步队列
put:332, LinkedBlockingQueue (java.util.concurrent)
put:40, QueueTrackers$1 (quickfix.mina)
enqueue:203, ThreadPerSessionEventHandlingStrategy$MessageDispatchingThread (quickfix.mina)
onMessage:82, ThreadPerSessionEventHandlingStrategy (quickfix.mina)
processMessage:111, AcceptorIoHandler (quickfix.mina.acceptor)
messageReceived:136, AbstractIoHandler (quickfix.mina)
messageReceived:997, DefaultIoFilterChain$TailFilter (org.apache.mina.core.filterchain)
callNextMessageReceived:641, DefaultIoFilterChain (org.apache.mina.core.filterchain)
access$1300:48, DefaultIoFilterChain (org.apache.mina.core.filterchain)
messageReceived:1114, DefaultIoFilterChain$EntryImpl$1 (org.apache.mina.core.filterchain)
flush:437, ProtocolCodecFilter$ProtocolDecoderOutputImpl (org.apache.mina.filter.codec)
messageReceived:256, ProtocolCodecFilter (org.apache.mina.filter.codec)
callNextMessageReceived:641, DefaultIoFilterChain (org.apache.mina.core.filterchain)
access$1300:48, DefaultIoFilterChain (org.apache.mina.core.filterchain)
messageReceived:1114, DefaultIoFilterChain$EntryImpl$1 (org.apache.mina.core.filterchain)
messageReceived:121, IoFilterAdapter (org.apache.mina.core.filterchain)
callNextMessageReceived:641, DefaultIoFilterChain (org.apache.mina.core.filterchain)
fireMessageReceived:634, DefaultIoFilterChain (org.apache.mina.core.filterchain)
# Channel#read
read:539, AbstractPollingIoProcessor (org.apache.mina.core.polling)
access$1200:68, AbstractPollingIoProcessor (org.apache.mina.core.polling)
process:1242, AbstractPollingIoProcessor$Processor (org.apache.mina.core.polling)
process:1231, AbstractPollingIoProcessor$Processor (org.apache.mina.core.polling)
# nio select
run:683, AbstractPollingIoProcessor$Processor (org.apache.mina.core.polling)
run:64, NamePreservingRunnable (org.apache.mina.util)
runWorker:1142, ThreadPoolExecutor (java.util.concurrent)
run:617, ThreadPoolExecutor$Worker (java.util.concurrent)
run:748, Thread (java.lang)




有效SendingTime校验,默认120s内
isGoodTime:1834, Session (quickfix)
verify:1743, Session (quickfix)
nextLogon:2129, Session (quickfix)
next:1026, Session (quickfix)
next:1204, Session (quickfix)
doRun:222, ThreadPerSessionEventHandlingStrategy$MessageDispatchingThread (quickfix.mina)
run:146, ThreadPerSessionEventHandlingStrategy$ThreadAdapter (quickfix.mina)
run:748, Thread (java.lang)

延伸

客户端、服务端时间相差太大,应该也会导致消息不被处理。

客户端发中文服务端收不到

现象

客户端发送英文服务端能收到,发送中文就收不到。

问题原因

客户端默认采用ISO-8895-1编码,需要修改成UTF-8。客户端checksum与服务端算的checksum不一致。
在server端的event.log日志里可以看到:

20230817-09:47:11: Invalid message: Expected CheckSum=89, Received CheckSum=184 in 8=FIX.4.4�9=83�35=0�34=2�49=client-company-001�50=019782�52=20230817-09:47:11.088�56=Heads�112=??�10=184�

解决办法

客户端和服务端都全局调用CharsetSupport.setCharset("UTF_8");,或者在Application#onCreate时调用。

原理

# 消息放入异步队列
offer:327, ConcurrentLinkedQueue (java.util.concurrent)
offer:226, DefaultIoSessionDataStructureFactory$DefaultWriteRequestQueue (org.apache.mina.core.session)
write:433, AbstractPollingIoProcessor (org.apache.mina.core.polling)
write:68, AbstractPollingIoProcessor (org.apache.mina.core.polling)
write:278, SimpleIoProcessorPool (org.apache.mina.core.service)
write:80, SimpleIoProcessorPool (org.apache.mina.core.service)
filterWrite:895, DefaultIoFilterChain$HeadFilter (org.apache.mina.core.filterchain)
callPreviousFilterWrite:744, DefaultIoFilterChain (org.apache.mina.core.filterchain)
access$1500:48, DefaultIoFilterChain (org.apache.mina.core.filterchain)
filterWrite:1132, DefaultIoFilterChain$EntryImpl$1 (org.apache.mina.core.filterchain)
# 调用DemuxingProtocolEncoder#encode -> FIXMessageEncoder#encode将字符串转成bytes
# 编码由CharsetSupport#getCharset提供,默认ISO-8859-1
# 想修改需要CharsetSupport.setCharset(StandardCharsets.UTF_8.name());
# 可以考虑在onCreate处调用,或者全局调用一次
filterWrite:345, ProtocolCodecFilter (org.apache.mina.filter.codec)
callPreviousFilterWrite:744, DefaultIoFilterChain (org.apache.mina.core.filterchain)
access$1500:48, DefaultIoFilterChain (org.apache.mina.core.filterchain)
filterWrite:1132, DefaultIoFilterChain$EntryImpl$1 (org.apache.mina.core.filterchain)
filterWrite:1020, DefaultIoFilterChain$TailFilter (org.apache.mina.core.filterchain)
callPreviousFilterWrite:744, DefaultIoFilterChain (org.apache.mina.core.filterchain)
# 责任链
fireFilterWrite:737, DefaultIoFilterChain (org.apache.mina.core.filterchain)
# 这里还会检查Channel连通性
write:570, AbstractIoSession (org.apache.mina.core.session)
write:515, AbstractIoSession (org.apache.mina.core.session)
# 异步写到mina
send:63, IoSessionResponder (quickfix.mina)
# 输出outgoing日志
send:2661, Session (quickfix)
# 插入header字段,调用Application#toAdmin、Application#toApp
# 登陆成功了才能调用send
sendRaw:2590, Session (quickfix)
send:2648, Session (quickfix)
sendToTarget:681, Session (quickfix)
# 获取异步队列数据并write buffer
flushNow:997, AbstractPollingIoProcessor$Processor (org.apache.mina.core.polling)
flush:921, AbstractPollingIoProcessor$Processor (org.apache.mina.core.polling)
run:688, AbstractPollingIoProcessor$Processor (org.apache.mina.core.polling)
run:64, NamePreservingRunnable (org.apache.mina.util)
runWorker:1142, ThreadPoolExecutor (java.util.concurrent)
run:617, ThreadPoolExecutor$Worker (java.util.concurrent)
run:748, Thread (java.lang)

服务端解码:

getMessageString:250, FIXMessageDecoder (quickfix.mina.message)
parseMessage:221, FIXMessageDecoder (quickfix.mina.message)
decode:105, FIXMessageDecoder (quickfix.mina.message)
doDecode:199, DemuxingProtocolDecoder (org.apache.mina.filter.codec.demux)
decode:180, CumulativeProtocolDecoder (org.apache.mina.filter.codec)
messageReceived:253, ProtocolCodecFilter (org.apache.mina.filter.codec)
callNextMessageReceived:641, DefaultIoFilterChain (org.apache.mina.core.filterchain)
access$1300:48, DefaultIoFilterChain (org.apache.mina.core.filterchain)
messageReceived:1114, DefaultIoFilterChain$EntryImpl$1 (org.apache.mina.core.filterchain)
messageReceived:121, IoFilterAdapter (org.apache.mina.core.filterchain)
callNextMessageReceived:641, DefaultIoFilterChain (org.apache.mina.core.filterchain)
fireMessageReceived:634, DefaultIoFilterChain (org.apache.mina.core.filterchain)
read:539, AbstractPollingIoProcessor (org.apache.mina.core.polling)
access$1200:68, AbstractPollingIoProcessor (org.apache.mina.core.polling)
process:1242, AbstractPollingIoProcessor$Processor (org.apache.mina.core.polling)
process:1231, AbstractPollingIoProcessor$Processor (org.apache.mina.core.polling)
run:683, AbstractPollingIoProcessor$Processor (org.apache.mina.core.polling)
run:64, NamePreservingRunnable (org.apache.mina.util)
runWorker:1142, ThreadPoolExecutor (java.util.concurrent)
run:617, ThreadPoolExecutor$Worker (java.util.concurrent)
run:748, Thread (java.lang)
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,014评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,796评论 3 386
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 158,484评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,830评论 1 285
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,946评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,114评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,182评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,927评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,369评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,678评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,832评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,533评论 4 335
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,166评论 3 317
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,885评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,128评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,659评论 2 362
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,738评论 2 351

推荐阅读更多精彩内容