# 共享订阅没有和mqtt协议标准一致

**URL:** <https://askemq.com/t/topic/779>\
**Category:** EMQX\
**Created:** [2021 年8 月 5 日 09:21 UTC](https://askemq.com/t/topic/779 "2021-08-05T09:21:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

作者： ![597555230](https://askemq.com/letter_avatar/597555230/32/6_449c533f586939b6e5f246632a46421f.png) [@597555230](https://askemq.com/u/597555230)\
发布日期： [2021 年8 月 5 日 09:21 UTC](https://askemq.com/t/topic/779/1 "2021-08-05T09:21:44Z")

</div>

### 环境信息

- EMQ X 版本：5.0.0
- 操作系统及版本：
- 其他

### 问题描述

1. mqtt 标准协议，共享订阅在下发qos2 消息时，无论什么情况禁止转发给其它订阅者；下发qos1 消息时，如果session进程挂掉，应该把消息转给其它订阅用户；但是emq文档用的 `shared_dispatch_ack_enabled = true｜ false`配置，qos1 和 qos2 统一策略 都可以把消息转给其它订阅用户或者都不可以把消息转给其它订阅者  
mqtt 文档介绍

```auto
If the Server is in the process of sending a QoS 2 message to its chosen subscribing Client and the connection to the Client breaks before delivery is complete, the Server MUST complete the delivery of the message to that Client when it reconnects [MQTT-4.8.2-4] as described in section If the Client's Session terminates before the Client reconnects, the Server MUST NOT send the Application Message to any other subscribed Client [MQTT-4.8.2-5].

 If the Server is in the process of sending a QoS 1 message to its chosen subscribing Client and the connection to that Client breaks before the Server has received an acknowledgement from the Client,
3155 the Server MAY wait for the Client to reconnect and retransmit the message to that Client. If the Client'sSession terminates before the Client reconnects, the Server SHOULD send the Application Message to another Client that is subscribed to the same Shared Subscription. It MAY attempt to send the message to another Client as soon as it loses its connection to the first Client.

```

文档链接[mqtt shared\_subscription](http://docs.oasis-open.org/mqtt/mqtt/v5.0/csprd02/mqtt-v5.0-csprd02.html#_Toc498345378)

1. 即便按照目前emq的标准，当配置 `shared_dispatch_ack_enabled = true`，下发共享订阅 qos1 和qos2 消息时，目前的代码没有收到ack 时就给emqx\_shared\_sub进程通知（原因emqx\_shared\_sub 进程给session进程发数据后，session进程回复，然后马上挂掉），导致实际上数据会丢失，并没有真正把消息转给其它订阅者

2. 即便按照目前emq的标准，当配置 `shared_dispatch_ack_enabled = true`，下发共享订阅 qos1 和qos2 消息时，目前的代码没有收到ack 时就给emqx\_shared\_sub进程通知（原因emqx\_shared\_sub 进程给session进程发数据后，session进程回复，然后马上挂掉），导致实际上数据会丢失，并没有真正把消息转给其它订阅者

3. 共享订阅用 当前session进程去send 并且 receive 消息，另一方面假如改成等待session进程收到 ack 后再给当前session进程发消息，假如一直没有ack回复，会导致session 进程阻塞,应该spawn 一个进程处理

---

<div class="post-metadata">

作者： ![blankalupo](https://askemq.com/letter_avatar/blankalupo/32/6_449c533f586939b6e5f246632a46421f.png) [@blankalupo](https://askemq.com/u/blankalupo)\
发布日期： [2021 年8 月 6 日 02:07 UTC](https://askemq.com/t/topic/779/2 "2021-08-06T02:07:25Z")

</div>

您好，我刚刚看了代码，确实有您说的问题，十分感谢您的意见，我们这边后续会进行改进

---

<div class="post-metadata">

作者： ![qihanzhou](https://askemq.com/letter_avatar/qihanzhou/32/6_449c533f586939b6e5f246632a46421f.png) [@qihanzhou](https://askemq.com/u/qihanzhou)\
发布日期： [2021 年12 月 27 日 14:37 UTC](https://askemq.com/t/topic/779/3 "2021-12-27T14:37:58Z")

</div>

您好， 请问现在这个`问题2`解决了吗？

---

<div class="post-metadata">

作者： ![heeejianbo](https://askemq.com/user_avatar/askemq.com/heeejianbo/32/36_2.png) [@heeejianbo](https://askemq.com/u/heeejianbo)\
发布日期： [2022 年5 月 13 日 06:56 UTC](https://askemq.com/t/topic/779/4 "2022-05-13T06:56:57Z")

</div>

Nice catch!! @597555230 非常棒的问题

我们最近正在修复这个问题 see: [feat(shared): redispatch to another shared sub, when no ACK received by gsychev · Pull Request #7807 · emqx/emqx · GitHub](https://github.com/emqx/emqx/pull/7807)

---

<div class="post-metadata">

作者： ![t1ger](https://askemq.com/user_avatar/askemq.com/t1ger/32/89_2.png) [@t1ger](https://askemq.com/u/t1ger)\
发布日期： [2022 年11 月 7 日 02:37 UTC](https://askemq.com/t/topic/779/5 "2022-11-07T02:37:29Z")

</div>

@597555230 @qihanzhou 以上问题我们已经在 EMQX 5.0.9 中修复。
