UltimateConnection - Message service with Infinite topics

Have you ever encountered this error while working with MessageSerive?

"The game server has reached the allowed limit of active subscriptions."

Have you ever wanted to have UNLIMITED topics for MessageService?

Then say hello to UltimateConnection.

UltimateConnection is a modulescript which can creates infinite topics while in reality it uses just one.


  • API

module.CreateController() Creates “Mega Topic” with given name (not required but recommended) and returns the “Mega Topic”
returns MegaTopic

local MegaTopic = module.CreateMegaTopic(MegaTopicName : string)

MegaTopic:InsertTopic() Creates secondary topic with given name (required)
Doesnt return

MegaTopic:InsertTopic(TopicName : string)

MegaTopic:PublishAsync() Works exactly like MessageService:PublishAsync() (TopicName is required)
Doesnt return

MegaTopic:PublishAsync(TopicName : string, … : any)

MegaTopic:SubsribeAsync() Works exactly like MessageService:SubscriveAsync() (TopicName and func is required).
Returns table

MegaTopic:SubscribeAsync(TopicName : string, func : Function)

MegaTopic:SubsribeAllAsync() Subscribes to all connected topics (func is required) and returns table with structure:

{
    Data = ... --table
    Topic = "" --string (topic name)
}

Returns table

MegaTopic:SubscribeAllAsync(func : Function)

MegaTopic:DisconnectTopic() disconnects from given topic (aka wont return data on PublishAsync and PublishAllAsync) (TopicName is required)

MegaTopic:DisconnectTopic(TopicName : string)

MegaTopic:ConnectTopic() does the opposite of DisconnectTopic (TopicName is required).

MegaTopic:ConnectTopic(TopicName : string)


  • Code
local module = {}
module.__index = module

local MessageService = game:GetService("MessagingService")

function module.CreateMegaTopic(ControllerName : string)
	local AlphaBind = Instance.new("BindableEvent")
	_G._Servers = _G._Servers or {} 

	local self 
	if _G._Servers[ControllerName] then
		self = _G._Servers[ControllerName] 
	else
		self = setmetatable({},module)
		self.Name = ControllerName or "MegaTopic"
		self.__AllBind = AlphaBind.Event
		self.__TopicsBinds = {}
		_G._Servers[ControllerName] = self
	end
	
	MessageService:SubscribeAsync(self.Name,function(Info)
		local Data = Info.Data
		local EventName = Data[#Data]
		table.remove(Data,#Data)
		table.sort(Data)
		
		Data = typeof(Data[1]) == "table" and Data[1] or Data
		if self.__TopicsBinds[EventName].Connected then self.__TopicsBinds[EventName].Bind:Fire(Data) AlphaBind:Fire({Data = Data,Topic = EventName}) end
	end)
	
	return self
end

function module:InsertTopic(TopicName : string)
	local Bindable = Instance.new("BindableEvent")
	self.__TopicsBinds[TopicName] = {Bind = Bindable,Connected = true}
	self[TopicName] = Bindable.Event
end

function module:PublishAsync(TopicName : string, ... : any)
	local Data =  {...}
	table.insert(Data,TopicName)		
	MessageService:PublishAsync(self.Name,Data)
end

function module:SubscribeAsync(TopicName : string,Func)
	self[TopicName]:Connect(Func)
end

function module:SubscribeAllAsync(Func)
	self.__AllBind:Connect(Func)
end

function module:DisconnectTopic(TopicName : string)
	self.__TopicsBinds[TopicName].Connected = false
end

function module:ConnectTopic(TopicName : string)
	self.__TopicsBinds[TopicName].Connected = true
end

return module

Feel free to criticize and edit

11 Likes

This is going to save me so much time, thank you for creating this module!

One example i forgot to add

local MessagesPlus = require(script.UltimateConnection)

local Obj = MessagesPlus.CreateMegaTopic("Admin_1")

Obj:InsertTopic("Ban")

Obj:SubscribeAsync("Ban",function(info)
	print(info.User.." was banned")
end)

Obj:PublishAsync("Ban",{User = "Roblox"})
2 Likes

You really shouldn’t be using _G

Seems like a bad idea to me, did you test this before publishing the module?


MessagingService

4 Likes

yea i actually did test and i didn’t encounter (probably bug?) (also its seem very bearable somehow)
also i replaced the global variable now it works with other modules

1 Like

Is this allowed? I’m worried I’ll get banned if I use this to bypass the topic limit.

1 Like

Does this work with Announcing Messaging Service API for Open Cloud?

Sorry for bump, but can you please also answer the other questions?

After i read the documentation, i think it will work just fine, i have to dig deeper into it before i make final statements