[QUESTION] Send message to specific subscribers
RazaGR opened this issue · comments
RazaGR commented
How can we send message to only connections which are subscribed to specific topic exmple/topic
?
Below code is sending message to all connections, which are not subscribed to that topic, I would like to send message to only connections which are subscribed to exmple/topic
:
// Send to subscribers
foreach ($server->connections as $sub_fd) {
if ($sub_fd != $fd) {
$server->send(
$sub_fd,
V3::pack(
[
'type' => $data['type'],
'topic' => $data['topic'],
'message' => $data['message'],
'dup' => $data['dup'],
'qos' => $data['qos'],
'retain' => $data['retain'],
'message_id' => $data['message_id'] ?? '',
]
)
);
}
}
Is there something available in Swoole or, Do I have to manage the state myself? like for example I can store in DB each new connection and then compare before sending.
Luffy commented
You need to store the subscription connection information yourself