🚀 Support ZOSCII

This software is free and open-source (MIT license). Help prove ZOSCII works by using it.

ZOSCII development is supported entirely by ZOSCIICOIN.

Learn more about ZOSCIICOIN

ZOSCII MQ System Documentation

Table of Contents

1. Overview and Advantage

The World's First Truly Quantum Proof Message Queue (MQ) and Data Store when used in conjunction with ZOSCII.

ZOSCII MQ is a minimal, file-based Message Queue (MQ) designed for high-assurance, B2B asynchronous communication. It leverages the file system for durability and uses specific file naming conventions for chronological ordering and message retention. It also can provide a robust message store service.

Why Use ZOSCII MQ?

The architecture offers key advantages over traditional message brokers (like RabbitMQ or Kafka) in specific freight and logistics scenarios:

Feature ZOSCII MQ (File-Based) Traditional Broker (RabbitMQ/Kafka)
Durability OS/Disk itself (Persistent) Configurable (Often RAM/DB)
Guaranteed Delivery External Pointer Tracking (Puller's responsibility) Built-in ACK/Offset Tracking
Architecture Simple HTTP Endpoint + File System Complex Daemon/Cluster Management

2. Usage for Integrators: Reading and Writing Messages

ZOSCII MQ uses a simple HTTP API (via index.php) for publishing and fetching messages, and a cron script (replikate.php) for B2B integration.

A. Publishing Messages (Writing to a Queue)

Messages are published using an HTTP GET request to the index.php endpoint.

Endpoint:

/index.php?action=publish

JSON Responses:

The main ZOSCII MQ index.php gives back it's responses as either binary data with a filename as it's Content-Disposition *, or as JSON messages in the format shown here. If possible it is always good to check the system. The error if it has a value is important. If there is no value in the error, then the result is valid. A message may be provided regardless of errors or results.

{
	"system":"ZOSCII MQ",
	"version":"1.0",
	"error":"",
	"message":"Message published.",
	"result":[]
}

* Refer to the implementation of the fetchNextMessage function within replikate.php for an example of how to handle the binary and JSON responses.

Description Do Do Not
check the filename from the Content-Disposition Do -
checking the message is from ZOSCII MQ * response.system === "ZOSCII MQ" Do -
checking that there are no errors response.error.length === 0 Do -
checking if a response message is provided if (response.message.length > 0) { // display the message } Do -
placing logic on the response message if (response.message === "Message Published") { // do someting } - Do Not

* Note: It is possible to confuse JSON messages stored in ZOSCII MQ vs those JSON messages from ZOSCII MQ itself. However it shouldn't hapen if you first check the filename from within the Content-Disposition. Checking if response.system is present and whether it is "ZOSCII MQ" will make this more robust.

Parameter Required Description Example Value
action Yes Must be publish. publish
q Yes The name of the target queue. customer_a
msg Yes The raw message payload (should be URL-encoded). {"item":"A"}
n Optional An optional NONCE or GUID to prevent retries from duplicating messages in the queue. a1b2c3d4-e5f6-4000-8000-0123456789ab
r Optional Retention Days (RRRR). 0000 = no expected retention (suitable for testing). 7

Example Command (HTTP):

GET /index.php?action=publish&q=customer_b&r=30&msg=%7B%22sku%22%3A%20%22123%22%7D&n=a1b2c3d4-e5f6-4000-8000-0123456789ab

JSON Response:

{
	"system":"ZOSCII MQ",
	"version":"1.0",
	"error":"",
	"message":"Message published.",
	"result":[]
}

Filename Format:

The message is saved as a file in the queues/QUEUE_NAME/ directory with the format: YYYYMMDDHHNNSSCCCC-RRRR-GUID.bin

B. Fetching Messages (Reading from a Queue - API Pull)

Messages are fetched sequentially using the unique filename as a pointer. The consumer must track this pointer (the after parameter) to ensure guaranteed, chronological delivery.

Endpoint:

/index.php?action=fetch
Parameter Required Description Example Value
action Yes Must be fetch. fetch
q Yes The name of the source queue to read from. customer_b
after Optional The Pointer. The filename of the LAST successfully processed message. Leave blank or omit for the very first message. 202510300900000001-0000-ed207f80-9fee-428d-8fad-0133255e1790.bin

Success Response:

C. B2B Replication (Puller)

For external partners (e.g. ABC Ltd) to pull data from your (e.g. XYZ Ltd) queue, they should run a dedicated cron job on their server (e.g. ABC_LOCAL_SERVER).

Script:

replikate.php

Setup:

Endpoint:

/replikate.php
Parameter Required Description Example Value
url Yes The URL of the source server's index.php https://XYZ_REMOTE_SERVER/index.php
sq Yes The name of the source queue to read from XYZ_REMOTE_QUEUE (e.g. abc_orders
tq Optional The name of the target queue on the partner's server ABC_LOCAL_QUEUE (e.g. my_orders)
Note: when no tq is provided, messages will be stored in the data store as an unknown message. This can be useful when you wish to move queue items into a data store for later identification or processing.

Example Command for Queue to Queue replication (HTTP):

GET /replikate.php?url=https://SOURCESERVER/index.php&sq=SOURCEQUEUE&tq=TARGETQUEUE

The script manages the state/pointer file (replikate_state_SOURCEQUEUE.txt) automatically.


Example Command for Queue to Store replication (HTTP):

GET /replikate.php?url=https://SOURCESERVER/index.php&sq=SOURCEQUEUE

D. Storing Messages (Writing to a Data Store)

Messages are stored using an HTTP GET request to the index.php endpoint.

Endpoint:

/index.php?action=store
Parameter Required Description Example Value
action Yes Must be store. store
msg Yes The raw message payload (should be URL-encoded). {"item":"A"}
n Optional An optional NONCE or GUID to prevent retries from duplicating messages in the data store. a1b2c3d4-e5f6-4000-8000-0123456789ab
r Optional Retention Days (RRRR). 0000 = no expected retention (suitable for testing). 7

Example Command (HTTP):

GET /index.php?action=store&r=30&msg=%7B%22sku%22%3A%20%22123%22%7D&n=a1b2c3d4-e5f6-4000-8000-0123456789ab

JSON Response:

{
	"system":"ZOSCII MQ",
	"version":"1.0",
	"error":"",
	"message":"Message stored.",
	"result":"202511021826110000-0030-9cc1980a-1719-440a-9650-6991c9cba11d.bin"
}

Filename Format:

The message is saved as a file in the store/x/y/z/ directory with the format: YYYYMMDDHHNNSSCCCC-RRRR-GUID.bin. The file will be returned if the storing of the message is successful. You will need to note this filename for later fast retrieval.

For later retrieval of the message, you must note the response.result.

E. Retrieving Messages (Reading from a Data Store)

Messages are retrieved from the data store by using the previously returned filename. The consumer must track this filename if fast retrieval is required.

Endpoint:

/index.php?action=retrieve
Parameter Required Description Example Value
action Yes Must be retrieve. retrieve
name Yes The Name. The result of a past successful store action. x202511021826110000-0030-9cc1980a-1719-440a-9650-6991c9cba11d.bin

Success Response:

JSON Error Response:

{
	"system":"ZOSCII MQ",
	"version":"1.0",
	"error":"Invalid name 'x202511021826110000-0030-9cc1980a-1719-440a-9650-6991c9cba11d.bin'.",
	"message":"",
	"result":[]
}

F. Scanning Messages (Scan the Data Store for unidentified messages)

Messages are retrieved from the data store by using the previously returned filename. The consumer must track this filename if fast retrieval is required.

Endpoint:

/index.php?action=scan

Success Response:

{
	"system":"ZOSCII MQ",
	"version":"1.0",
	"error":"",
	"message":"",
	"result":[
		"202511021259550001-0005-5192e106-7a99-4418-98eb-8d4cb4c6aa3a-u.bin",
		"202511021259550001-0005-be2b00c1-9419-4661-8c1d-2219780c7980-u.bin"
	]
}

G. Identify Messages

Once messages have been scanned for, then identified, they can then be flagged as identified.

Endpoint:

/index.php?action=identify
Parameter Required Description Example Value
action Yes Must be identify. identify
names Yes The raw message payload (should be URL-encoded). [ "202511021259550001-0005-5192e106-7a99-4418-98eb-8d4cb4c6aa3a-u.bin", "202511021259550001-0005-be2b00c1-9419-4661-x8c1d-2219780c7980-u.bin" ]

Example Command (HTTP):

GET /index.php?action=identify&names=["202511021259550001-0005-5192e106-7a99-4418-98eb-8d4cb4c6aa3a-u.bin","x202511021259550001-0005-be2b00c1-9419-4661-8c1d-2219780c7980-u.bin"]

Success Response:

{
	"system":"ZOSCII MQ",
	"version":"1.0",
	"error":"",
	"message":"Returned messages identified.",
	"result":[
		"202511021259550001-0005-5192e106-7a99-4418-98eb-8d4cb4c6aa3a.bin"
	]
}

3. Server Setup and Maintenance (For Administrators)

A. Core Directory Structure

The system is file-based and requires a dedicated root directory:

./
|-- index.php             (HTTP API: Publish/Fetch)
|-- replikate.php         (Cron: External Puller)
|-- claireup.php          (Cron: Retention Cleanup)
|-- nonce/                (Optional nonce files go here)
|-- queues/
|   |-- customer_a/       (Queue 1)
|   |   |-- *.bin
|   |-- customer_b/       (Queue 2)
|   |   |-- *.bin
|-- states/               (State Files are here for Replicators)
|   |   |-- replikate_state_*.txt
|-- store/                (Data Store Files are here)
|-- statissa.php          (Statistics, it's better to place statissa elsewhere)

B. Critical Cron Jobs

Two cron jobs must be set up on the ZOSCII MQ server to ensure stability:

1. Message Retention Cleanup (claireup.php)

This job ensures disk space is managed by deleting expired messages based on the **RRRR** value in the filename. It processes **all queues globally**.

Setting Value Description
Script claireup.php The retention management script.
Schedule Once daily (e.g., 0 0 * * *) Runs at midnight to clear the previous day's expired files.
Action Deletes any message file where Current Time $\ge$ (Message Time + RRRR days). It deletes messages with RRRR=0000.

Cron Example:

Although it's possible to run claireup.php from a browser it is recommended to run it from cron if possible. To run it from the browser, you will first need to change the CLI_ONLY constant to FALSE from within the claireup.php file. If you do that, you are best ensure that it cannot be run by unauthorised parties if you don't want it to run.

0 0 * * * /usr/bin/php /path/to/claireup.php

4. Deployment Strategies

ZOSCII MQ supports two primary deployment patterns, each optimized for different use cases:

Strategy 1: Internal Business Message Bus

Architecture

Characteristics

Typical Setup

Primary Server (HQ)          Backup Server (DR Site)
   ZOSCII MQ        ─────→      ZOSCII MQ
   [All Queues]     replikate   [Mirror Copy]
                    (periodic)
    

Message Distribution Patterns

Pattern 1: Standard Fan-Out (No replikate.php needed)

Single queue, multiple readers - built-in ZOSCII MQ capability

              Primary Server
                 ZOSCII MQ
          [company_announcements]
                    ↓
       ┌────────────┼────────────┬────────────┐
       ↓            ↓            ↓            ↓
    John's PC    Mary's PC    Bob's PC    ... 1,000+ PCs
    
1 message published → 1,000+ PCs all fetch from same queue
Each PC independently reads the same messages
No replication needed - standard ZOSCII MQ behavior
    

Use Cases:

Benefits:

Pattern 2: Server Striping with replikate.php (Advanced)

Distribute load across multiple servers for scale/geography

                Primary Server (HQ)
                   ZOSCII MQ
            [company_announcements]
                      ↓
          ┌───────────┴───────────┬───────────────┐
          ↓                       ↓               ↓
     replikate.php          replikate.php    replikate.php
          ↓                       ↓               ↓
    Server A (Sydney)       Server B (Tokyo)  Server C (London)
      ZOSCII MQ               ZOSCII MQ         ZOSCII MQ
          ↓                       ↓               ↓
    ┌─────┼─────┐           ┌─────┼─────┐   ┌─────┼─────┐
    ↓     ↓     ↓           ↓     ↓     ↓   ↓     ↓     ↓
  PC1   PC2  PC500       PC501 PC502 PC1000 ... PC2000 PC3000

1 message → striped to 3 regional servers → 3,000+ PCs globally
Each regional server services local PCs (lower latency)
    

Use Cases:

Benefits:

📊 Scale Example: Global Company Alert

Without Striping (Pattern 1):

With Striping (Pattern 2):

Result: 1,000× reduction in WAN bandwidth usage

Strategy 2: High Throughput AWS B2B Integration

Architecture

Characteristics

Typical Setup

Business A (AWS)         Business B (AWS)         Business C (AWS)
 ZOSCII MQ Docker         ZOSCII MQ Docker         ZOSCII MQ Docker
 [Push anytime]           [Push anytime]           [Push anytime]
      ↓                         ↓                         ↓
      └─────────────────────────┴─────────────────────────┘
                                 ↓
                    Head Office Server (Local)
                         ZOSCII MQ
                    [Pulls 24/7 via replikate.php]
                    [Aggregates all business data]
    

Why This Works

Strategy Comparison

Aspect Internal Message Bus AWS B2B Integration
Network 1Gb+ LAN Internet (100-500 Mbps)
Throughput/Day Tens of thousands Thousands (per business)
Traffic Pattern 24/7 potential Business hours (bursty)
Deployment On-premise / Private cloud AWS Docker (1 per customer)
Replication Optional (DR backup) Continuous (aggregation)
Cost Model Single server cost $5-50/month per customer
Use Case Internal operations B2B document exchange
Key Insight: The AWS B2B strategy is ZOSCII MQ's primary design target. The "thousands/day" performance reflects real-world B2B traffic patterns (business hours, peak windows) over internet connections - not a technical limitation.

5. Docker Deploys

Deploying ZOSCII MQ using Docker provides an **instant, persistent message queue** solution. There are three primary deployment strategies for managing the deployment environment and persistent queue data (messages and nonces):

Strategy 1: Instant Deploy (Docker Named Volumes) - Recommended for simplicity

This strategy is best for quick setup and development environments. It uses **Docker Named Volumes** which Docker automatically manages on the host machine.

Deployment Details:

The volumes section in the docker-compose.yml looks like this:

volumes:
  # Data is mapped to Docker-managed volumes defined at the bottom of the file.
  - zoscii_data:/app/queues
  - zoscii_nonce:/app/nonce

volumes:
  zoscii_data:
  zoscii_nonce:

Strategy 2: Dedicated Data Path (Host Bind Mounts) - Recommended for local production

This strategy gives you full control over where the queue data resides. This is essential for environments where you need to explicitly back up, monitor, or manage the queue files using host-level tools (like rsync or specific backup agents).

Deployment Details:

The volumes section in the docker-compose.yml is modified to specify the host path:

volumes:
  # The host path (./zoscii-data) is explicitly mapped to the container path.
  - ./zoscii-data/queues:/app/queues
  - ./zoscii-data/nonce:/app/nonce

# NOTE: Named volumes are NOT defined when using Bind Mounts.

Strategy 3: Serverless Cloud Deploy (AWS Fargate/Google Cloud Run) - Recommended for zero local install

If you wish to deploy without installing Docker or running a package manager locally, the best method is a **Serverless Container Service** that manages the container's lifecycle and infrastructure.

Deployment Details:

Once your ZOSCII MQ Docker image is pushed to a public registry (via automated build, e.g., GitHub Actions), you can deploy it in a few clicks.

6. Running the Cleanup Cron Job (claireup.php)

Since claireup.php is designed to be run from the command line (CLI), you can execute it manually inside the running container:

docker-compose exec zoscii-mq php /app/claireup.php

You can automate this by setting up a host-level cron job that calls the docker-compose exec command every minute. **Note for Strategy 3 (Cloud Deploy):** For cloud deployments, you must use the cloud provider's native scheduling tools (e.g., **AWS CloudWatch Events/EventBridge** or **Google Cloud Scheduler**) to execute the cleanup command on the running container.

6. Comparison with Traditional Message Brokers

Architecture Comparison

Feature ZOSCII MQ Apache Kafka RabbitMQ
Core Size ~35 KB (PHP) ~160 MB + JVM ~150 MB + Erlang
Runtime Dependencies PHP only JVM, Zookeeper/KRaft Erlang VM
Memory Footprint ~10-50 MB 6-32+ GB typical 1-4 GB typical
Protocol HTTP/REST native Binary (needs REST Proxy) AMQP + HTTP API
Distributed Architecture Federated (via replikate.php) Centralized cluster Cluster with federation
Cross-Organization B2B ✅ Native (pull model) ❌ Complex (VPN/proxy) ⚠️ Possible (federation)
Message Storage Direct file access Segmented logs Mnesia DB/Queues
Retention Model Per-message (RRRR days) Per-topic configuration TTL or consumed
Setup Time < 5 minutes Hours to days 30-60 minutes
Debugging ls, cat, grep files JMX, complex tools Management UI

Performance and Scale

Metric ZOSCII MQ Apache Kafka RabbitMQ
Primary Deployment Context B2B over Internet Internal datacenter/LAN Internal datacenter/LAN
Throughput - Internet
(100-500 Mbps typical)
(>1KB messages)
Good
Network-limited
Thousands-tens of thousands/day
Good
Network-limited
Thousands-tens of thousands/day
Good
Network-limited
Thousands-tens of thousands/day
Throughput - Internet
(100-500 Mbps typical)
(>100KB messages)
Optimal
Designed for this
Thousands/day
Zero knowledge maintained
⚠️ Limited
Network bottleneck
Hundreds-low thousands/day
⚠️ Limited
Network bottleneck
Hundreds-low thousands/day
Throughput - Internet
(100-500 Mbps typical)
(>1MB messages)
Handles Well
Network-limited
Hundreds/day
Poor
Network + config issues
Tens-hundreds/day
Poor
Network + memory issues
Tens/day
1 Gb LAN Performance (Internal Network)
Throughput - 1Gb LAN
(Single node)
(>1KB messages)
Excellent
Disk I/O limited
Tens of thousands/day
100-1,000 msg/sec
Optimal
Peak performance
Millions/day
10,000-100,000+ msg/sec
Excellent
Strong performance
Hundreds of thousands/day
5,000-20,000 msg/sec
Throughput - 1Gb LAN
(Single node)
(>100KB messages)
Excellent
Still in designed range
Tens of thousands/day
Consistent performance
⚠️ Good (needs tuning)
Config changes needed
Tens of thousands/day
Efficiency drops
⚠️ Degraded
Memory pressure
Low thousands/day
Performance impact
Throughput - 1Gb LAN
(Single node)
(>1MB messages)
Excellent
File-based handles naturally
Thousands/day
No memory pressure
Poor
Major config needed
Hundreds/day
Batching ineffective
Not Recommended
Severe issues
Dozens/day
Can crash under load
Horizontal Scaling Federated (independent nodes) Add brokers to cluster Add nodes to cluster
Geographic Distribution ✅ Excellent (federation) ⚠️ Complex (MirrorMaker) ✅ Good (federation)
Note on Internet vs LAN Performance: All systems are network-limited over the internet. ZOSCII MQ's "thousands/day" reflects its primary B2B internet use case. On internal 1Gb LAN, ZOSCII MQ performs significantly faster (tens of thousands/day), though Kafka still leads for small message, high-volume internal workloads.

Security Comparison

Security Aspect ZOSCII MQ Apache Kafka RabbitMQ
Message Handling Transparent pass-through
Data stored as-is
Transparent pass-through
Data stored as-is
Transparent pass-through
Data stored as-is
Server Knowledge Zero knowledge by design
Built for ITS/ZOSCII
Pure binary storage
⚠️ Partial knowledge
Keys, headers, offsets
Schema registry possible
❌ Message awareness
Routing, properties, TTL
Content-based routing
Data Storage Raw bytes as provided
No built-in encryption
Raw bytes as provided
No built-in encryption
Raw bytes as provided
No built-in encryption
Public Queue Sharing Safe even if public
ITS/ZOSCII perfect secrecy
Multiple parties, one queue
❌ Requires encryption
Vulnerable if exposed
Computational security only
❌ Requires encryption
Vulnerable if exposed
Computational security only
Queue/Topic Security ✅ Can use secret names
Capability-based access
No enumeration
❌ Topics visible
Listed in metadata
Requires ACLs
⚠️ Queues visible
Listed in management
Requires permissions
Default Security ⚠️ None (relies on web server) ❌ None (wide open) ⚠️ Guest/guest (localhost only)
Authentication HTTP Basic/Digest/OAuth
(.htaccess, PHP session)
SASL (PLAIN/SCRAM/GSSAPI)
SSL certificates
PLAIN/AMQPLAIN/EXTERNAL
LDAP, OAuth 2.0
Transport Encryption ✅ HTTPS (standard) TLS/SSL (must configure) TLS/SSL (built-in)
Message Encryption ✅ ITS-ready (mentioned in docs)
Application-level
Application-level only Application-level only
Authorization/ACLs Web server level
PHP app logic
Complex ACLs
Per-topic permissions
User/vhost permissions
Regex-based
Cross-Organization B2B ✅ Each org owns security
No shared credentials
❌ Shared cluster access
VPN/proxy complexity
⚠️ Federation possible
Shared credentials
Attack Surface HTTP endpoint only
Standard web security
Binary protocol
9092+ other ports
Zookeeper exposure
AMQP + Management
Multiple ports
Audit Trail Web server logs
Filesystem timestamps
Audit log (enterprise)
Complex setup
Firehose tracer
Management events
Security Setup Complexity ✅ Simple (web standard) ❌ Very complex
(JAAS, keystores, ACLs)
⚠️ Moderate
Network Isolation ✅ Standard firewall rules
HTTP/HTTPS only
Multiple ports
Internal communication
Multiple ports
Clustering ports
Data at Rest Plain files
(filesystem encryption)
Plain logs
(filesystem encryption)
Mnesia DB
(filesystem encryption)
Multi-Tenancy Security ✅ Complete isolation
(separate servers)
⚠️ Namespace separation ✅ Vhost isolation

🔐 ZOSCII MQ: Designed for Zero-Knowledge Security

ZOSCII MQ is purpose-built for ZOSCII (100% secure Information Theoretic Encoding) with complete zero-knowledge architecture.

"The server doesn't know what it doesn't need to know."

🔒 ZOSCII MQ Security Advantages:

⚠️ Security Considerations:

Use Case Suitability

✅ Choose ZOSCII MQ When:

⚠️ Choose Kafka/RabbitMQ When:

Federated Architecture Advantage

ZOSCII MQ's replikate.php enables a unique federated architecture:

Company A (Sydney)     Company B (Tokyo)      Company C (London)
    ZOSCII MQ    ←──→    ZOSCII MQ    ←──→    ZOSCII MQ
         ↓                    ↓                     ↓
   [Own Control]        [Own Control]         [Own Control]
   [Own Security]       [Own Security]        [Own Security]
   [Own Data]           [Own Data]            [Own Data]

Each node operates independently - no central point of failure, no shared infrastructure, perfect for B2B logistics and freight forwarding where different organizations need to maintain sovereignty over their systems.

Total Cost of Ownership (TCO)

Cost Factor ZOSCII MQ Kafka RabbitMQ
Infrastructure $5-50/month (VPS) $500-5000+/month $100-1000/month
Operational Expertise Junior PHP dev Senior DevOps team Mid-level DevOps
Monitoring Tools Built-in (statissa.php) Prometheus/Grafana/etc Management plugin
High Availability rsync/filesystem backup/replikate.php Complex cluster config Cluster + mirroring