Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow

StackOverflow Logo StackOverflow Logo

StackOverflow Navigation

Search
Ask A Question

Mobile menu

Close
Ask A Question
  • Home
  • Add group
  • Feed
  • User Profile
  • Communities
  • Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
Home/ Questions/Q 391
Next

StackOverflow Latest Questions

Saralyn
  • 0
  • 0
SaralynBegginer
Asked: January 3, 20252025-01-03T00:46:39+00:00 2025-01-03T00:46:39+00:00In: PHP

php – Can’t set the message handler on Symfony without attributes

  • 0
  • 0
php – Can’t set the message handler on Symfony without attributes

I have this command

name;
    }

    public function getText(): string
    {
        return $this->text;
    }

    public function getUserId(): UuidInterface
    {
        return Uuid::fromString($this->userId);
    }
}

and this handler

getName()),
            new Text($command->getTe xt()),
            new UserId($command->getUserId())
        );
    
        $this->todoRepository->save($todo);
    }
    
}

this messenger.yaml configuration

framework:
    messenger:
        # Uncomment this (and the failed transport below) to send failed messages to this transport for later handling.
        # failure_transport: failed

        transports:
            # https://symfony.com/doc/current/messenger.html#transport-configuration
            async: 
                dsn: '%env(RABBITMQ_DSN)%'
                retry_strategy:
                    max_retries: 5
                    delay: 1000
                    multiplier: 2
                    max_delay: 60000
            # failed: 'doctrine://default?queue_name=failed'
            # sync: 'sync://'

        routing:
            # Route your messages to the transports
            # 'App\Message\YourMessage': async
            'App\Todo\Application\Command\CreateTodoCommand': async

and this services.yaml config

# This file is the entry point to configure your own services.
# Files in the packages/ subdirectory configure your dependencies.

# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
parameters:

services:
    # default configuration for services in *this* file
    _defaults:
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
    # Registra el repositorio como servicio
    App\Todo\Infrastructure\Repository\DoctrineTodoRepository:
        arguments:
            $em: '@doctrine.orm.entity_manager'
        
    # Registra el handler y autowire la interfaz con su implementación
    App\Todo\Application\Command\CreateTodoCommandHandler:
        arguments:
            $todoRepository: '@App\Todo\Infrastructure\Repository\DoctrineTodoRepository'


    # makes classes in src/ available to be used as services
    # this creates a service per class whose id is the fully-qualified class name
    App\:
        resource: '../src/'
        exclude:
            - '../src/DependencyInjection/'
            - '../src/Entity/'
            - '../src/Kernel.php'

    # add more service definitions when explicit configuration is needed
    # please note that last definitions always *replace* previous ones

But when I try t consume the queued messages I get this error

messenger.CRITICAL: Error thrown while handling message App\Todo\Application\Command\CreateTodoCommand. Removing from transport after 5 retries. Error: "No handler for message "App\Todo\Application\Command\CreateTodoCommand"." {"class":"App\\Todo\\Application\\Command\\CreateTodoCommand","retryCount":5,"error":"No handler for message \"App\\Todo\\Application\\Command\\CreateTodoCommand\".","exception":"[object] (Symfony\\Component\\Messenger\\Exception\\NoHandlerForMessageException(code: 0): No handler for message \"App\\Todo\\Application\\Command\\CreateTodoCommand\". at /var/www/html/vendor/symfony/messenger/Middleware/HandleMessageMiddleware.php:117)"} []

If I check the handlers with bin/console debug:messenger there is no CreateTodoCommandHandler on the list

Messenger
=========

messenger.bus.default
---------------------

 The following messages can be dispatched:

 ---------------------------------------------------------- 
  Symfony\Component\Process\Messenger\RunProcessMessage     
      handled by process.messenger.process_message_handler  
                                                            
  Symfony\Component\Console\Messenger\RunCommandMessage     
      handled by console.messenger.execute_command_handler  
                                                            
  Symfony\Component\Messenger\Message\RedispatchMessage     
      handled by messenger.redispatch_message_handler       
                                                            
 ---------------------------------------------------------- 

And I cleared cache several times

I think the config is correct, but there is no way to set the handler, there is something wrong or do I missed something?

If I use an attribute

use Symfony\Component\Messenger\Attribute\AsMessageHandler;

#[AsMessageHandler]
class CreateTodoCommandHandler implements CommandHandlerInterface

then everything work correctly.

It’s a handler registration problem, and I need to set the handler without using an attribute.

0
  • 0 0 Answers
  • 92 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • Popular
  • Answers
  • W3spoint99

    What is Physics? Definition, History, Importance, Scope (Class 11)

    • 1 Answer
  • W3spoint99

    The Living World – Introduction, Classification, Characteristics, FAQs (Class 11 ...

    • 1 Answer
  • W3spoint99

    Explain - Biological Classification (Class 11 - Biology)

    • 1 Answer
  • Saralyn
    Saralyn added an answer When Humans look at their childhood pictures, the first thing… January 17, 2025 at 3:25 pm
  • Saralyn
    Saralyn added an answer Previously, length was measured using units such as the length… January 17, 2025 at 3:25 pm
  • Saralyn
    Saralyn added an answer Measurement forms the fundamental principle to various other branches of… January 17, 2025 at 3:25 pm

Related Questions

  • Reading fancy apostrophe PHP [duplicate]

    • 0 Answers
  • Unable to send mail via PHPMailer [SMTP->Error: Password not accepted ...

    • 0 Answers
  • Concerns when migrating from PHP 5.6 to 8.4 [closed]

    • 0 Answers
  • Laravel Auth::attempt() error: "Unknown column 'password'" when using a custom ...

    • 0 Answers
  • Core PHP cURL - header origin pass null value

    • 0 Answers

Trending Tags

biology class 11 forces how physics relates to other sciences interdisciplinary science learn mathematics math sets tutorial null sets physics physics and astronomy physics and biology physics and chemistry physics applications science science connections science education sets in mathematics set theory basics types of sets types of sets explained

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

  • About US
  • Privacy Policy
  • Questions
  • Recent Questions
  • Web Stories

© 2025 WikiQuora.Com. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.