Skip to content
cloudemu
Services

Message Queue

Point-to-point and pub/sub messaging with FIFO, visibility timeouts, and dead-letter queues, modelled on SQS, Service Bus, and Pub/Sub

aws SQSazr Service Busgcp Pub/Sub

Emulates a managed message queue — the buffer you drop work onto so a producer and a consumer don't have to run at the same time. You create a named queue (or a Pub/Sub topic + subscription), send messages to it, then receive and delete them from the other side. Received messages stay hidden from other consumers until you delete them or their visibility timeout lapses.

Reach for it in tests when your code enqueues jobs, drains a queue, relies on FIFO ordering, or leans on a dead-letter queue for poison messages — so you can exercise those paths without a live broker. Unlike the event bus, consumers pull messages and acknowledge each one, so nothing is lost if a worker crashes mid-batch.

ProviderServiceSDK-compatDriver
AWSSQS (AwsJson1_0)✓ Liveaws.SQS
AzureService Bus (ARM control plane + REST data plane)✓ Liveazure.ServiceBus
GCPPub/Sub (REST)✓ Livegcp.PubSub

Drive it with the real SDK#

This is the recommended path: point the AWS SDK at a cloudemu test server and the same sqs client you use in production talks to the emulator. The create/send/receive/delete cycle below is the full lifecycle of a message — receiving it hides it from other consumers, and deleting it (via the receipt handle) is the acknowledgement that removes it for good.

import (
    "github.com/aws/aws-sdk-go-v2/service/sqs"
    awsserver "github.com/stackshy/cloudemu/v2/server/aws"
)

cloud := cloudemu.NewAWS()
ts := httptest.NewServer(awsserver.New(awsserver.Drivers{SQS: cloud.SQS}))

client := sqs.NewFromConfig(cfg, func(o *sqs.Options) {
    o.BaseEndpoint = aws.String(ts.URL)
})

q, _ := client.CreateQueue(ctx, &sqs.CreateQueueInput{
    QueueName: aws.String("orders"),
})

client.SendMessage(ctx, &sqs.SendMessageInput{
    QueueUrl: q.QueueUrl, MessageBody: aws.String("order-123"),
})

rcv, _ := client.ReceiveMessage(ctx, &sqs.ReceiveMessageInput{
    QueueUrl: q.QueueUrl, MaxNumberOfMessages: 1,
})

client.DeleteMessage(ctx, &sqs.DeleteMessageInput{
    QueueUrl: q.QueueUrl, ReceiptHandle: rcv.Messages[0].ReceiptHandle,
})

The same pattern works for the other providers: armservicebus (Azure ARM control plane) plus raw HTTP for the Service Bus data plane — the modern azservicebus SDK is AMQP-only and out of scope — and google.golang.org/api/pubsub/v1 for GCP Pub/Sub. See SDK-Compat Server.

Use the Portable Go API#

When you don't need a real SDK client, the same driver is callable directly — no HTTP server, no client construction. It's the leanest way to seed a queue or assert on its contents inside a test.

import mqdriver "github.com/stackshy/cloudemu/v2/services/messagequeue/driver"

q, _ := aws.SQS.CreateQueue(ctx, mqdriver.QueueConfig{Name: "orders"})
aws.SQS.SendMessage(ctx, mqdriver.SendMessageInput{
    QueueURL: q.URL, Body: "order-123",
})
msgs, _ := aws.SQS.ReceiveMessages(ctx, mqdriver.ReceiveMessageInput{
    QueueURL: q.URL, MaxMessages: 1,
})

Behavior & fidelity#

  • FIFO ordering and dedup. FIFO queues deliver messages in order within a GroupID and drop duplicates sharing a DeduplicationID within a 5-minute window — drive that window with the fake clock instead of waiting on wall time.
  • Visibility timeout. A received message is invisible to other consumers until it's deleted or the timeout expires, at which point it becomes receivable again — so an un-acked message is redelivered rather than lost.
  • Dead-letter queues. A message received more than MaxReceiveCount times moves automatically to the configured DLQ, mirroring the redrive policy on real SQS.
  • SDK-compat status — Live across all three providers. SQS, Service Bus, and Pub/Sub all accept their real SDK/REST clients today for the operations listed above (CreateQueue, GetQueueUrl, ListQueues, DeleteQueue, SendMessage, ReceiveMessage, DeleteMessage on SQS; ARM Microsoft.ServiceBus/namespaces[/queues] CRUD plus the REST data plane on Service Bus; topic/subscription lifecycle, :publish, :pull, :acknowledge on Pub/Sub). Batch ops, ChangeMessageVisibility, queue attributes, and PurgeQueue are available through the Portable Go API but not yet on the SDK-compat surface.

On this page

On this page