dev-master
9999999-devThe PHPMQ message protocol
MIT
The Requires
- php >=7.1
The Development Requires
The PHPMQ message protocol
The PHPMQ message protocol, (*2)
composer require php-mq/protocol
Each message sent from a client to the endpoint must have a leading header line which defines:, (*3)
Example:, (*4)
H0100102 means: PACKET-ID | VERSION | MSG-TYPE | PACKAGE COUNT H | 01 | 001 | 02
So a header always has a length of 8 byte., (*5)
001
- Client sends a message (client to server)002
- Client wants to consume messages (consume request)003
- Server dispatches a message (server to client)004
- Client acknowledges a message (acknowledgement)005
- Client wants to re-queue a message (pop from queue, append to queue)006
- Client sends a dead letter for a message (remove message from queue)Each data package in a message is preceded by a package header with defines:, (*6)
Example:, (*7)
P01000000000000000000000000000000256 means: PACKET-ID | PKG-TYPE | CONTENT-LENGTH (as int) P | 01 | 256
So a package header always has a length of 32 byte., (*8)
Please note: The content length has a length of 32 bytes and is filled up with zeros., (*9)
PKG-Type | Meaning |
---|---|
01 | Queue name |
02 | Message content |
03 | Message ID |
04 | Count of message for consumption |
05 | Time to live of message (TTL) |
01
- Queue name02
- Message content05
- Message TTL01
- Queue name02
- Message content03
- Message ID05
- Message TTL01
- Queue name04
- Count of messages the client wants to consume from the queue01
- Queue name03
- Message ID01
- Queue name03
- Message ID05
- Message TTL01
- Queue name03
- Message IDClient sends a new message with content "Hello World" for queue "Foo" to server with a TTL of 3600 seconds., (*10)
H0100103 P0100000000000000000000000000003 Foo P0200000000000000000000000000011 Hello World P0500000000000000000000000000004 3600
Client wants to consume 5 messages from queue "Foo"., (*11)
H0100202 P0100000000000000000000000000003 Foo P0400000000000000000000000000001 5
Server sends the message above to the client 300 seconds later., (*12)
H0100304 P0100000000000000000000000000003 Foo P0200000000000000000000000000011 Hello World P0300000000000000000000000000032 d7e7f68761d34838494b233148b5486c P0500000000000000000000000000004 3300
Note: TTL was reduced to 3300 seconds., (*13)
Client acknowledges the consumed message with ID d7e7f68761d34838494b233148b5486c
., (*14)
H0100402 P0100000000000000000000000000003 Foo P0300000000000000000000000000032 d7e7f68761d34838494b233148b5486c
Client wants the message to be re-queued at the end of the queue, with a new TTL of 3600 seconds., (*15)
H0100503 P0100000000000000000000000000003 Foo P0300000000000000000000000000032 d7e7f68761d34838494b233148b5486c P0500000000000000000000000000004 3600
Client wants the message to be removed from queue, regardless its TTL, (*16)
H0100602 P0100000000000000000000000000003 Foo P0300000000000000000000000000032 d7e7f68761d34838494b233148b5486c
Contributions are welcome and will be fully credited. Please see the contribution guide for details., (*17)
The PHPMQ message protocol
MIT