Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

Handler receives the envelope instead of the message it was registered for

未關閉
#341 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
5/5
預估耗時
一週以上
新手友好度
35/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
php
領域
api, backend

研究方向

Read Worker.php, ConsumeFinalHandler.php, and the guide at docs/guide/en/messages-and-handlers.md:108; trace how IdEnvelope, DelayEnvelope, and FailureEnvelope move through the consume pipeline. First resolve the contract choice raised in the issue, especially alongside the #338 Worker and pipeline rework. Done means handlers receive the intended message or envelope contract consistently, with the guide and behavior agreeing.

由索引模型根據 Issue 內容生成。

描述

Worker::process() passes the message into the consume pipeline exactly as it arrived, and ConsumeFinalHandler hands that to the handler. Nothing unwraps an envelope on the way, so a handler written the way the guide writes it breaks as soon as the message is wrapped.

The documented handler (docs/guide/en/messages-and-handlers.md:108):

public function handle(MessageInterface $message): void
{
    assert($message instanceof SendEmailMessage);
    $this->mailer->send($message->to, $message->subject, $message->body);
}

Called with an adapter-assigned id, which is the normal asynchronous path:

$worker->process(new IdEnvelope($message, 'id-42'), 'test');

With zend.assertions=1:

MessageFailureException: Processing of message #id-42 is stopped because of an exception:
assert($message instanceof SendEmailMessage).

With zend.assertions=-1, the production default:

Warning: Undefined property: Yiisoft\Queue\Message\IdEnvelope::$to
sending to: NULL

No error, and the work is done against empty values. DelayEnvelope and FailureEnvelope behave the same way. Call path: Worker.php:45 → ConsumeMiddlewareDispatcher → ConsumeFinalHandler.php:21.

Worth deciding which contract is meant:

  • unwrap in Worker before dispatching, so a handler always receives the message type it was registered for, and offer the envelope separately to handlers that want the metadata, or
  • keep passing the envelope and change every handler example in the guide to unwrap first ($message instanceof Envelope ? $message->getMessage() : $message), since assert() is not a guard in production.

InMemoryAdapter happens not to trigger this because it stores the unwrapped message, but any adapter that stores what push() returned does.

#338 reworks Worker and the pipeline around it, so this probably wants deciding before that lands.

主要語言
PHP
星號
61
分支
31
PR 合併指標
30 天內沒有已合併 PR

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

yiisoft/queue 的其他 Issue

查看 yiisoft/queue 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。