@@ -53,14 +53,16 @@ Each queue task consists of two parts:
5353 ` Yiisoft\Queue\Message\Message ` . For more complex cases you should implement the interface by your own.
54542 . A message handler is a callable called by a ` Yiisoft\Queue\Worker\Worker ` . The handler handles each queue message.
5555
56- For example, if you need to download and save a file, your message may look like the following:
56+ For example, if you need to download and save a file, your message creation may look like the following:
57+ - Message handler as the first parameter
58+ - Message data as the second parameter
5759
5860``` php
5961$data = [
6062 'url' => $url,
6163 'destinationFile' => $filename,
6264];
63- $message = new \Yiisoft\Queue\Message\Message('file-download' , $data);
65+ $message = new \Yiisoft\Queue\Message\Message(FileDownloader::class , $data);
6466```
6567
6668Then you should push it to the queue:
@@ -93,9 +95,8 @@ class FileDownloader
9395The last thing we should do is to create a configuration for the ` Yiisoft\Queue\Worker\Worker ` :
9496
9597``` php
96- $handlers = ['file-download' => [new FileDownloader('/path/to/save/files'), 'handle']];
9798$worker = new \Yiisoft\Queue\Worker\Worker(
98- $handlers, // Here it is
99+ [],
99100 $logger,
100101 $injector,
101102 $container
@@ -134,6 +135,28 @@ $status->isReserved();
134135$status->isDone();
135136```
136137
138+ ## Custom handler names
139+ ### Custom handler names
140+
141+ By default, when you push a message to the queue, the message handler name is the fully qualified class name of the handler.
142+ This can be useful for most cases, but sometimes you may want to use a shorter name or arbitrary string as the handler name.
143+ This can be useful when you want to reduce the amount of data being passed or when you communicate with external systems.
144+
145+ To use a custom handler name before message push, you can pass it as the first argument ` Message ` when creating it:
146+ ``` php
147+ new Message('handler-name', $data);
148+ ```
149+
150+ To use a custom handler name on message consume, you should configure handler mapping for the ` Worker ` class:
151+ ``` php
152+ $worker = new \Yiisoft\Queue\Worker\Worker(
153+ ['handler-name' => FooHandler::class],
154+ $logger,
155+ $injector,
156+ $container
157+ );
158+ ```
159+
137160## Different queue channels
138161
139162Often we need to push to different queue channels with an only application. There is the ` QueueFactory ` class to make
0 commit comments