2017 © Pedro Peláez
 

library protocol

The PHPMQ message protocol

image

php-mq/protocol

The PHPMQ message protocol

  • Tuesday, January 2, 2018
  • by hollodotme
  • Repository
  • 1 Watchers
  • 0 Stars
  • 33 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 1 Versions
  • 18 % Grown

The README.md

Build Status Latest Stable Version Total Downloads Coverage Status, (*1)

Protocol

Description

The PHPMQ message protocol, (*2)

Installation

composer require php-mq/protocol

Usage


Message headers

Each message sent from a client to the endpoint must have a leading header line which defines:, (*3)

  • A flag that identifies the line as message header
  • A number that identifies the version of the message protocol
  • The type of the message (see message types) (3 bytes)
  • The number of the following packages (see packet types)

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)

Message types

  • 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)

Packet headers

Each data package in a message is preceded by a package header with defines:, (*6)

  • A flag that identifies the line as package header
  • A number that identifies the package type
  • The length of the following package content

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)

Packet types

All

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)

For messages from client to endpoint

  • 01 - Queue name
  • 02 - Message content
  • 05 - Message TTL

For messages from endpoint to client

  • 01 - Queue name
  • 02 - Message content
  • 03 - Message ID
  • 05 - Message TTL

For Consumption

  • 01 - Queue name
  • 04 - Count of messages the client wants to consume from the queue

For message acknowledgment

  • 01 - Queue name
  • 03 - Message ID

For message re-queue

  • 01 - Queue name
  • 03 - Message ID
  • 05 - Message TTL

For dead letter

  • 01 - Queue name
  • 03 - Message ID

Full message examples

Send a message

Client 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

Consume messages

Client wants to consume 5 messages from queue "Foo"., (*11)

H0100202
P0100000000000000000000000000003
Foo
P0400000000000000000000000000001
5

Dispatch a message

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)

Acknowledge a message

Client acknowledges the consumed message with ID d7e7f68761d34838494b233148b5486c., (*14)

H0100402
P0100000000000000000000000000003
Foo
P0300000000000000000000000000032
d7e7f68761d34838494b233148b5486c

Re-queue a message

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

Send a dead letter

Client wants the message to be removed from queue, regardless its TTL, (*16)

H0100602
P0100000000000000000000000000003
Foo
P0300000000000000000000000000032
d7e7f68761d34838494b233148b5486c

Contributing

Contributions are welcome and will be fully credited. Please see the contribution guide for details., (*17)

The Versions

02/01 2018

dev-master

9999999-dev

The PHPMQ message protocol

  Sources   Download

MIT

The Requires

  • php >=7.1

 

The Development Requires