2007-02 Agent Queue

Links to older versions

Queue Simple TCP/IP

This Queue implementation is realized thought one thread TCP/IP server with client implementation in communication protocol.
This implementation is tolerant and is case insensitive. But you should be care full about case sensitive, cause maybe in the future protocol implementation will not be so nice.


Locking is a mechanism that protect data flow from data processing vulnerabilities.
The algorithm is simple:

  • Received message is locked
  • When there is no answer for some longer period of time.
    • Watchdog Agent checks what is going on and try to fix it. (For example by restarting crashed agent).
    • Message is unlocked for processing.
  • When data processing success.
    • Success is confirmed.
    • Data message is removed from queue.

Queue Protocol version 0.01

Important notes :

When line is being send i.e. "Hi.\n" , the c-string terminating zero is not send !.
In that case only only four bytes will be send {'H', 'i', '.', '\n'}.

Both newline ( "\n" ) terminators are accepted: <CR> and <CR><LF>.

Code Decimal Octal Hexadecimal printf notation
<CR> 13 015 D "\013" and "\xD"
<LF> 10 012 A "\012" and "\xA"

So both are correct "\xA" and "\xD\xA"

Queue Communication Protocol looks as following.

Sending dialog

Sending dialog is a dialog that enables to put something into Queue.
In other words to send message to any of agents of given type.
Here how dialog look line.

Client: Hi.\n
Server: Hi.\n
Client: I speak SCS Queue protocol version 0.01.\n
Server: OK.\n (or Bye.\n)
Client: I want to send to any agent of type number 5.\n - (5 is an example number, It could be any integer between 0 and 216)
Server: OK.\n (or Bye.\n)
Client: Data size is 1234.\n - 1234 is an example number. It can be any integer between 0 and 231
Server: OK.\n (or Bye.\n)
Client: Data:\n
Client: HERE IS DATA
Client: .\n - after data there is a dot and newline char
Server: OK.\n (If error then:/ Fail!\n or Bye.\n)
Client: Bye.\n
Server: Bye.\n

So, Client can assume that everything was OK, only if received four times OK.\n .
When client receives any Bye.\n from server it should answer immediately by Bye.\n and close connection.

Receiving dialog

Receiving dialog enables agent to receive message that was addressed to it and lock it.
In other words to pop receive data from Queue and Lock it.

Client: Hi.\n
Server: Hi.\n
Client: I speak SCS Queue protocol version 0.01.\n
Server: OK.\n (or Bye.\n)
Client: I'm agent of type number 5.\n - (5 is an example number, It could be any integer between 0 and 216)
Server: OK.\n (or Bye.\n)
Client: I want to receive.\n
Server: OK.\n (or Bye.\n)
Server: Data size is 1234. Data ID is 456.\n - 456, 1234 are an example numbers. They can be any integer between 0 and 231
Client: OK.\n (or Bye.\n)
Server: Data:\n
Server: HERE IS DATA
Server: .\n - after data there is a dot and newline char
Client: OK.\n
Server: Data is locked.\n
Server: Bye.\n
Client: Bye.\n

So, Client can assume that everything was OK, only if received three times OK.\n and one time \Data is locked.\n .
Server can assume that everything was OK, only if received two times OK.\n .
When client receives any Bye.\n from server it should answer immediately by Bye.\n and close
connection.

Confirmation of success in data processing.

Confirmation is needed to provide Queue information that can remove locked massage from queue.

Client: Hi.\n
Server: Hi.\n
Client: I speak SCS Queue protocol version 0.01.\n
Server: OK.\n (or Bye.\n)
Client: I'm agent of type number 5.\n - (5 is an example number, It could be any integer between 0 and 216)
Server: OK.\n (or Bye.\n)
Client: I confirm a success in processing data, which ID is 456.\n - (456 is an example number, It could be any integer between 0 and 231)
Server: OK.\n (or Bye.\n)
Client: Bye.\n
Server: Bye.\n

So, Client can assume that everything was OK, only if received three times OK.\n .
When client receives any Bye.\n from server it should answer immediately by Bye.\n and close connection.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.