Getting Started Guide

Learn how to use OKMQ in minutes with simple HTTP requests

Free Tier Includes

  • • 100 MB storage
  • • 100,000 messages
  • • 1 channel (queue or stream)
  • • 1 concurrent consumer

1. Get Your API Token

Sign up for an account and you'll receive your API token immediately. Use this token in the Authorization header for all requests.

Authorization: your-api-token

2. Quick Start (No Setup Required)

Try OKMQ right now with simple HTTP requests. No SDK installation needed.


# Set your token
export TOKEN="your-api-token"

# Create a queue
curl -X POST https://api.okmq.net/queues \
  -H "Authorization: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name": "my-queue", "auto_ack": true}'

# Send a message
curl -X POST https://api.okmq.net/queues/my-queue/messages \
  -H "Authorization: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '[{"id": "msg-1", "body": "Hello, OKMQ!"}]'

# Receive messages
curl https://api.okmq.net/queues/my-queue/messages \
  -H "Authorization: $TOKEN"
That's it! You've just created a queue, sent a message, and received it.

3. Generate a Type-Safe Client (Optional)

For production use, we recommend generating a type-safe client from our OpenAPI specification. This gives you autocomplete, type checking, and a better developer experience.

Download OpenAPI Spec

Download the OpenAPI specification

For TypeScript/JavaScript:


# Generate the TypeScript client (no installation needed)
npx @hey-api/openapi-ts \
  -i openapi.yaml \
  -o ./client \
  -c @hey-api/client-fetch

// Now use the generated client
import { postQueues } from './client'
import { client } from './client/client.gen'

// Configure authentication
client.setConfig({
  headers: {
    authorization: process.env.OKMQ_TOKEN || ''
  }
})

// Create a queue (async/await - no callbacks!)
await postQueues({
  body: {
    name: 'my-queue',
    auto_ack: true,
    ttl: 300
  }
})

console.log('Queue created successfully')

For Other Languages:

For Python, Go, Java, Rust, and other languages, use your preferred OpenAPI client generator:


# Python
pip install openapi-python-client
openapi-python-client generate --path openapi.yaml

# Go
go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen@latest
oapi-codegen -package okmq openapi.yaml > okmq.go

# Java, Ruby, Rust, etc. (50+ languages supported)
npm install -g @openapitools/openapi-generator-cli
openapi-generator-cli generate -i openapi.yaml -g  -o ./client

Benefits of Generated Clients

  • Full type safety and autocomplete in your IDE
  • Automatic request/response validation
  • No manual URL construction or header management
  • Catch API misuse at compile time, not runtime

4. Create a Queue

Let's create a queue for processing email notifications. This example shows how to set up a queue with automatic acknowledgment and a 5-minute TTL.


import { postQueues } from './client'
import { client } from './client/client.gen'

// Configure authentication
client.setConfig({
  headers: {
    authorization: process.env.OKMQ_TOKEN || ''
  }
})

// Create email notifications queue
await postQueues({
  body: {
    name: 'email-notifications',
    auto_ack: true,
    ttl: 300 // 5 minutes
  }
})

console.log('Queue created successfully')

5. Send a Message

Now let's send an email notification message to the queue. Messages are sent as JSON arrays, allowing you to send multiple messages in a single request.


import { postQueuesByQueueMessages } from './client'

const sendEmailNotification = async (userEmail, subject, body) => {
  await postQueuesByQueueMessages({
    path: { queue: 'email-notifications' },
    body: [{
      id: `email-${Date.now()}`,
      body: JSON.stringify({
        to: userEmail,
        subject: subject,
        body: body,
        priority: 'normal'
      })
    }]
  })

  console.log('Email notification queued')
}

// Send a welcome email notification
await sendEmailNotification(
  'user@example.com',
  'Welcome to our service!',
  'Thank you for signing up...'
)

6. Process Messages

Create a worker process to continuously poll for new messages and process them. This example shows how to process email notifications.


import { getQueuesByQueueMessages } from './client'

const processEmailNotifications = async () => {
  while (true) {
    try {
      const response = await getQueuesByQueueMessages({
        path: { queue: 'email-notifications' }
      })

      const data = response.data

      if (Array.isArray(data) && data.length > 0) {
        // Process messages only if data is an array with items
        for (const message of data) {
          console.log('Processing email:', message.id)

          // Process the email notification
          const emailData = JSON.parse(message.body)
          await sendEmail(emailData.to, emailData.subject, emailData.body)

          console.log(`Email sent to ${emailData.to}`)
        }
      }

    } catch (error) {
      console.error('Error processing messages:', error)
    }
  }
}

// Simulated email sending function
const sendEmail = async (to, subject, body) => {
  // Your email sending logic here
  console.log(`Sending email to ${to}: ${subject}`)
}

// Start processing
processEmailNotifications()

Complete Example

Here's a complete working example that demonstrates creating a queue, sending messages, and processing them:


import { postQueues, getQueuesByQueueMessages, postQueuesByQueueMessages } from './client'
import { client } from './client/client.gen'

// Configure authentication
client.setConfig({
  headers: {
    authorization: process.env.OKMQ_TOKEN || ''
  }
})

const main = async () => {
  // Create the queue
  await postQueues({
    body: {
      name: 'email-notifications',
      auto_ack: true,
      ttl: 300
    }
  })

  // Start processing messages in the background
  const processMessages = async () => {
    while (true) {
      try {
        const response = await getQueuesByQueueMessages({
          path: { queue: 'email-notifications' }
        })

        const data = response.data
        if (Array.isArray(data) && data.length > 0) {
          for (const message of data) {
            const emailData = JSON.parse(message.body)
            console.log('Processing:', emailData.subject)
            // Process your email here
          }
        }

      } catch (error) {
        console.error('Error processing:', error)
      }
    }
  }
  processMessages()

  // Send test messages every 5 seconds
  setInterval(async () => {
    try {
      await postQueuesByQueueMessages({
        path: { queue: 'email-notifications' },
        body: [{
          id: `email-${Date.now()}`,
          body: JSON.stringify({
            to: 'user@example.com',
            subject: `Test email ${Date.now()}`,
            body: 'Test message'
          })
        }]
      })
    } catch (error) {
      console.error('Error sending:', error)
    }
  }, 5000)
}

main()

Error Handling

OKMQ returns standard HTTP status codes. Here are the most common responses you'll encounter:

StatusMeaningExample Response
200SuccessRequest completed successfully
201CreatedQueue or stream created successfully
401Unauthorized{"error": "unauthorized"}
404Not Found{"error": "queue not found"}
409Conflict{"error": "queue already exists"}
413Quota Exceeded{"error": "message quota exceeded"}

// Example: Handle common errors
const createQueue = async (name) => {
  const response = await fetch('https://api.okmq.net/queues', {
    method: 'POST',
    headers: {
      authorization: process.env.OKMQ_TOKEN,
      'content-type': 'application/json'
    },
    body: JSON.stringify({ name, auto_ack: true })
  })

  if (response.status === 409) {
    console.log('Queue already exists, continuing...')
    return
  }

  if (response.status === 413) {
    const error = await response.json()
    throw new Error(`Quota exceeded: ${error.error}`)
  }

  if (!response.ok) {
    const error = await response.json()
    throw new Error(`Failed to create queue: ${error.error}`)
  }

  console.log('Queue created successfully')
}

List Your Queues and Streams

View all your queues and streams to monitor your messaging infrastructure.


# List all queues
curl https://api.okmq.net/queues -H "Authorization: $TOKEN"

# List all streams
curl https://api.okmq.net/streams -H "Authorization: $TOKEN"

# Get account info and usage
curl https://api.okmq.net/account -H "Authorization: $TOKEN"

Next Steps

1

Learn About Queues

Explore queue features, message structure, retry strategies, acknowledgments, and scheduling

2

Understanding Streams

Real-time message processing with committed offsets and exactly-once delivery

3

API Reference

Complete OpenAPI documentation with all endpoints, parameters, and response schemas