Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

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

Aberta
#341 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
5/5
Tempo estimado
Mais de uma semana
Facilidade para iniciantes
35/100
Tipo de issue
Bug
Clareza
Razoavelmente clara
Status de atividade
Ativa
Stack de tecnologia
php
Domínio
api, backend

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
PHP
Estrelas
61
Forks
31
Métricas de merge de PRs
Nenhum PR com merge em 30d

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de yiisoft/queue

Todas as issues de yiisoft/queue

Issues semelhantes

Mais issues de PHP

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.