--- title: "Producing messages" description: "Producing messages with the PHP core — build the canonical envelope with EnvelopeCodec, encode it, and publish through any transport." source: https://babelqueue.com/docs/php-sdk/1.x/producing-messages/ updated: 2026-06-07T00:00:00.000Z --- # Producing messages Producing is two steps: **build** the canonical envelope, then **encode** it to JSON and publish the bytes with your broker client. ## From a typed job Implement `BabelQueue\Contracts\PolyglotJob` — a URN plus a pure-array payload: ```php use BabelQueue\Contracts\PolyglotJob; final class OrderCreated implements PolyglotJob { public function __construct(public int $orderId) {} public function getBabelUrn(): string { return 'urn:babel:orders:created'; } public function toPayload(): array { return ['order_id' => $this->orderId]; } } ``` ```php use BabelQueue\Codec\EnvelopeCodec; $envelope = EnvelopeCodec::fromJob(new OrderCreated(1042), 'orders'); $json = EnvelopeCodec::encode($envelope); // publish $json onto the "orders" queue with your transport (below) ``` ## From a raw URN + data When you don't have a job object, build it directly: ```php $envelope = EnvelopeCodec::make('urn:babel:orders:created', ['order_id' => 1042], 'orders'); $json = EnvelopeCodec::encode($envelope); ``` `make(string $urn, array $data = [], string $queue = 'default', ?string $traceId = null)` returns the envelope as a plain PHP array. A fresh `trace_id` (v4 UUID) is stamped automatically; pass `$traceId` to continue an existing trace, or implement `BabelQueue\Contracts\HasTraceId` on your job. ## Publish `encode()` produces the exact UTF-8 JSON bytes every other SDK reads — see [Transports](/docs/php-sdk/1.x/transports/) for the reference Redis/RabbitMQ publishers, or move the string with any broker client you already use. ```json { "job": "urn:babel:orders:created", "trace_id": "…", "data": { "order_id": 1042 }, "meta": { "id": "…", "queue": "orders", "lang": "php", "schema_version": 1, "created_at": 1749132727000 }, "attempts": 0 } ``` Next: [Consuming messages](/docs/php-sdk/1.x/consuming-messages/).