mirror of
https://github.com/fhmq/hmq.git
synced 2026-08-30 22:34:52 +00:00
update
This commit is contained in:
+30
-27
@@ -372,12 +372,10 @@ func (b *Broker) handleConnection(typ int, conn net.Conn) {
|
|||||||
ol.Close()
|
ol.Close()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
b.QueryConnect(cid)
|
go b.QueryConnect(cid)
|
||||||
}
|
}
|
||||||
b.clients.Store(cid, c)
|
b.clients.Store(cid, c)
|
||||||
b.OnlineOfflineNotification(cid, true)
|
b.OnlineOfflineNotification(cid, true)
|
||||||
|
|
||||||
//TODO notify othernode to close connect
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c.readLoop()
|
c.readLoop()
|
||||||
@@ -472,33 +470,44 @@ func (b *Broker) PublishMessage(packet *packets.PublishPacket) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
b.ProcessRemote(packet, qsub)
|
go b.ProcessRemote(packet, qsub)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Broker) ProcessRemote(packet *packets.PublishPacket, loaclShareSub []*subscription) {
|
func (b *Broker) ProcessRemote(packet *packets.PublishPacket, loaclShareSub []*subscription) {
|
||||||
shareRemoteID := ""
|
|
||||||
remoteSubInfo := b.QuerySubscribe(packet.TopicName, packet.Qos)
|
|
||||||
totalShare := len(loaclShareSub)
|
|
||||||
for _, v := range remoteSubInfo {
|
|
||||||
totalShare = totalShare + v.shareSubCount
|
|
||||||
}
|
|
||||||
target := r.Intn(totalShare)
|
|
||||||
|
|
||||||
if target < len(loaclShareSub) {
|
remoteSubInfo := b.QuerySubscribe(packet.TopicName, packet.Qos)
|
||||||
shareRemoteID = b.id
|
|
||||||
} else {
|
//calc which node process share message
|
||||||
target = target - len(loaclShareSub)
|
shareRemoteID := ""
|
||||||
for k, v := range remoteSubInfo {
|
{
|
||||||
if target < v.shareSubCount {
|
totalShare := len(loaclShareSub)
|
||||||
shareRemoteID = k
|
for _, v := range remoteSubInfo {
|
||||||
return
|
totalShare = totalShare + v.shareSubCount
|
||||||
|
}
|
||||||
|
|
||||||
|
target := r.Intn(totalShare)
|
||||||
|
if target < len(loaclShareSub) {
|
||||||
|
shareRemoteID = b.id
|
||||||
|
//send local
|
||||||
|
if shareRemoteID == b.id {
|
||||||
|
sub := loaclShareSub[target]
|
||||||
|
publish(sub, packet)
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
target = target - len(loaclShareSub)
|
||||||
|
for k, v := range remoteSubInfo {
|
||||||
|
if target < v.shareSubCount {
|
||||||
|
shareRemoteID = k
|
||||||
|
return
|
||||||
|
}
|
||||||
|
target = target - v.shareSubCount
|
||||||
}
|
}
|
||||||
target = target - v.shareSubCount
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//send remote
|
//send remote message
|
||||||
for id, sub := range remoteSubInfo {
|
for id, sub := range remoteSubInfo {
|
||||||
rpcCli := b.rpcClient[id]
|
rpcCli := b.rpcClient[id]
|
||||||
if sub.subCount > 0 {
|
if sub.subCount > 0 {
|
||||||
@@ -506,10 +515,4 @@ func (b *Broker) ProcessRemote(packet *packets.PublishPacket, loaclShareSub []*s
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//send local
|
|
||||||
if shareRemoteID == b.id {
|
|
||||||
sub := loaclShareSub[target]
|
|
||||||
publish(sub, packet)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user