Xmpp消息丢弃:Smack在流恢复后不发送ACK

时间:2016-06-19 01:41:48

标签: android tcp xmpp ejabberd smack

我有基于Ejabberd(版本16.04)和Smack客户端库(Android版本4.17)的Xmpp堆栈。

当客户端暂时脱机时,我面临服务器发送的邮件被丢弃的情况。以下是我用来复制情况的步骤,以及来自ejabberd的日志。

1-客户A上线

2016-06-19 01:22:59.834 [info] <0.505.0>@ejabberd_listener:accept:333 (#Port<0.19955>) Accepted connection 122.172.241.21:26683 -> 139.162.34.247:5222
2016-06-19 01:23:00.449 [info] <0.667.0>@ejabberd_c2s:wait_for_sasl_response:900 ({socket_state,gen_tcp,#Port<0.19955>,<0.666.0>}) Accepted authentication for 9739937980 by undefined from 122.172.241.21
2016-06-19 01:23:00.619 [info] <0.667.0>@ejabberd_c2s:open_session:1111 ({socket_state,gen_tcp,#Port<0.19955>,<0.666.0>}) Opened session for 9739937980@gappi.in/Smack
2016-06-19 01:23:00.698 [info] <0.667.0>@ejabberd_c2s:handle_enable:2700 Stream management with resumption enabled for 9739937980@gappi.in/Smack

2 - 客户端A被不正常地断开连接(wifi断开连接或app被杀)

2016-06-19 01:27:57.582 [info] <0.667.0>@ejabberd_c2s:fsm_next_state:2454 Waiting for resumption of stream for 9739937980@gappi.in/Smack

3 - 其他客户端/机器人向客户端A发送消息

4 - 客户端A在短时间内(60秒)重新上线

2016-06-19 01:28:39.367 [info] <0.505.0>@ejabberd_listener:accept:333 (#Port<0.19963>) Accepted connection 122.172.241.21:26543 -> 139.162.34.247:5222
2016-06-19 01:28:40.050 [info] <0.684.0>@ejabberd_c2s:wait_for_sasl_response:900 ({socket_state,gen_tcp,#Port<0.19963>,<0.683.0>}) Accepted authentication for 9739937980 by undefined from 122.172.241.21
2016-06-19 01:28:40.213 [info] <0.684.0>@ejabberd_c2s:open_session:1111 ({socket_state,gen_tcp,#Port<0.19963>,<0.683.0>}) Opened session for 9739937980@gappi.in/Smack
2016-06-19 01:28:40.214 [info] <0.667.0>@ejabberd_c2s:terminate:1758 ({socket_state,gen_tcp,#Port<0.19955>,<0.666.0>}) Replaced session for 9739937980@gappi.in/Smack
2016-06-19 01:28:40.215 [info] <0.667.0>@ejabberd_c2s:handle_unacked_stanzas:2872 2 stanzas were not acknowledged by 9739937980@gappi.in/Smack
2016-06-19 01:28:40.302 [info] <0.684.0>@ejabberd_c2s:handle_enable:2700 Stream management with resumption enabled for 9739937980@gappi.in/Smack

现在,ejabberd告诉我它还没有收到待处理邮件的确认 2 stanzas were not acknowledged by 9739937980@gappi.in/Smack。此外,Smack库不会收到这些消息并被删除。

很明显,Smack客户端库在重新连接后没有为消息发送正确的ack。我已尝试在我的客户端库代码中启用流管理(XEP-198),但它无法正常工作。我的Smack客户端连接代码如下所示:

XMPPTCPConnectionConfiguration.Builder config = XMPPTCPConnectionConfiguration
            .builder();
config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
config.setServiceName(serverAddress);
config.setHost(serverAddress);
config.setPort(5222);
config.setDebuggerEnabled(true);
XMPPTCPConnection.setUseStreamManagementDefault(true);
XMPPTCPConnection.setUseStreamManagementResumptionDefault(true);
connection = new XMPPTCPConnection(config.build());
connection.setUseStreamManagement(true);
connection.setUseStreamManagementResumption(true);

我需要做哪些更改才能避免丢失这些信息?

感谢。

1 个答案:

答案 0 :(得分:1)

我自己想出来了。

我的客户端代码中存在错误。我很晚才将ChatMessageListener添加到连接中。

即使ejabberd在恢复时正确地重新发送消息,但没有ChatMessageListener这些消息没有被正确地发送或存储到客户端数据库。