Sign In Register

How can we help you today?

Start a new topic

Message Queue Solution


Is there message queue solution in GameSparks or suggested way how to queue messages?

We use an event in which we receive players messages asynchronously. Messages are processed and stored on MongoDb (actually as ScriptData of challenge but it's Mongo in the end).  Problem occurs when we have processing of data that depends on previous processing of data for example:

t  | description
t0: player p1 sends message through event e

t1: event e processes p1 message, gets data d = 0 (v1)  from challenge scriptdata

t2: player p2 sends message through event e

t3: event e processes p2 message, gets data  d = 0 (v1) from challenge scriptdata

t4: event e finishes and writes data d += 50 (v2) for player p1

t5: event e finishes and writes data d += 35 (v3) for player p2 (INCORRECT overwrite of v1 version of data)

And this is wrong as with queuing system messages would be processed one after another and that would make result v1 (d=0) -> v2 (d=50) -> v3(d=85).

Do you have in place solution for this problem?

Best Regards,


Hi Sasha,

There are several ways you could implement a message control system yourself.

1. Add a timestamp to outgoing messages, so that you can handle out-of-order messages received on the client.

2. You could add a delay to the messages using SparkScheduler (although this decreases the likelihood of messages arriving out of order, it doesn't preclude it entirely).

3. Wait for confirmation from the client regarding receipt of message A before sending message B. To do this, you would send the first message as you are currently, then in you client's message handling, add a request which, when sent to the server, triggers the sending of the second message.

Hopefully one of these methods will satisfy your requirements.


Have same configuration.

Use Spark.lockKey to ensure that your event runs once at a time.

I think using .setSendViaSocket(true) uses TCP to ensure that messages arrive in order.

Login to post a comment