How to set listener queue name from environment variable?How do you implement a Stack and a Queue in JavaScript?Laravel 5.2 Job with delay fires instantly instead of waitingLaravel 5.1 failed queued jobs fails on failed() method, prevents queue failure event handler from being calledHow to use queue an event in laravel 5.2?Laravel queue listener from external serviceHow to run a Laravel Job at specify QueueHow to inspect the current Named Route using Laravel 5.2Testing listeners with Queue::fake()task scheduled in laravel for sql queryTesting Events and Mail in Laravel 5.2

Different meanings of こわい

Can a virus destroy the BIOS of a modern computer?

Bullying boss launched a smear campaign and made me unemployable

Is it possible to create a QR code using text?

Mathematica command that allows it to read my intentions

Assassin's bullet with mercury

Size of subfigure fitting its content (tikzpicture)

What killed these X2 caps?

Why is it a bad idea to hire a hitman to eliminate most corrupt politicians?

What is the most common color to indicate the input-field is disabled?

Can my sorcerer use a spellbook only to collect spells and scribe scrolls, not cast?

Can compressed videos be decoded back to their uncompresed original format?

Expand and Contract

Why is consensus so controversial in Britain?

Forgetting the musical notes while performing in concert

Do UK voters know if their MP will be the Speaker of the House?

Should I cover my bicycle overnight while bikepacking?

Should I tell management that I intend to leave due to bad software development practices?

Intersection Puzzle

What historical events would have to change in order to make 19th century "steampunk" technology possible?

Plagiarism or not?

How to show a landlord what we have in savings?

A category-like structure without composition?

How do conventional missiles fly?



How to set listener queue name from environment variable?


How do you implement a Stack and a Queue in JavaScript?Laravel 5.2 Job with delay fires instantly instead of waitingLaravel 5.1 failed queued jobs fails on failed() method, prevents queue failure event handler from being calledHow to use queue an event in laravel 5.2?Laravel queue listener from external serviceHow to run a Laravel Job at specify QueueHow to inspect the current Named Route using Laravel 5.2Testing listeners with Queue::fake()task scheduled in laravel for sql queryTesting Events and Mail in Laravel 5.2













0















I just noticed that some of my listeners do not use the queue I expected them to use. Our team upgraded from Laravel 5.2 to 5.5 a few weeks back, and I guess this is when the problem started happening. There hasn't been much load on the system, so I only discovered it by accident.



Anyway. I used to set the queue name on the listener through a queue method, like so:



public function queue(QueueManager $handler, $method, $arguments): void

$handler->connection()->push($method, $arguments, Queue::getNotificationQueue());



This approach is not working anymore, so a default queue ends up handling the job instead of the expected notification queue.



So I looked at the documentation https://laravel.com/docs/5.5/events#queued-event-listeners, which states that the name should be set on a queue property on the listener. My problem is that I have the queue name in an environment variable, so I cannot just set it directly as a property, as shown in the documentation and it does not work to set it on the constructor, like so:



protected $queue;

public function __construct()

$this->queue = Queue::getNotificationQueue();



Does anyone here have an idea of how I can get around this?










share|improve this question


























    0















    I just noticed that some of my listeners do not use the queue I expected them to use. Our team upgraded from Laravel 5.2 to 5.5 a few weeks back, and I guess this is when the problem started happening. There hasn't been much load on the system, so I only discovered it by accident.



    Anyway. I used to set the queue name on the listener through a queue method, like so:



    public function queue(QueueManager $handler, $method, $arguments): void

    $handler->connection()->push($method, $arguments, Queue::getNotificationQueue());



    This approach is not working anymore, so a default queue ends up handling the job instead of the expected notification queue.



    So I looked at the documentation https://laravel.com/docs/5.5/events#queued-event-listeners, which states that the name should be set on a queue property on the listener. My problem is that I have the queue name in an environment variable, so I cannot just set it directly as a property, as shown in the documentation and it does not work to set it on the constructor, like so:



    protected $queue;

    public function __construct()

    $this->queue = Queue::getNotificationQueue();



    Does anyone here have an idea of how I can get around this?










    share|improve this question
























      0












      0








      0








      I just noticed that some of my listeners do not use the queue I expected them to use. Our team upgraded from Laravel 5.2 to 5.5 a few weeks back, and I guess this is when the problem started happening. There hasn't been much load on the system, so I only discovered it by accident.



      Anyway. I used to set the queue name on the listener through a queue method, like so:



      public function queue(QueueManager $handler, $method, $arguments): void

      $handler->connection()->push($method, $arguments, Queue::getNotificationQueue());



      This approach is not working anymore, so a default queue ends up handling the job instead of the expected notification queue.



      So I looked at the documentation https://laravel.com/docs/5.5/events#queued-event-listeners, which states that the name should be set on a queue property on the listener. My problem is that I have the queue name in an environment variable, so I cannot just set it directly as a property, as shown in the documentation and it does not work to set it on the constructor, like so:



      protected $queue;

      public function __construct()

      $this->queue = Queue::getNotificationQueue();



      Does anyone here have an idea of how I can get around this?










      share|improve this question














      I just noticed that some of my listeners do not use the queue I expected them to use. Our team upgraded from Laravel 5.2 to 5.5 a few weeks back, and I guess this is when the problem started happening. There hasn't been much load on the system, so I only discovered it by accident.



      Anyway. I used to set the queue name on the listener through a queue method, like so:



      public function queue(QueueManager $handler, $method, $arguments): void

      $handler->connection()->push($method, $arguments, Queue::getNotificationQueue());



      This approach is not working anymore, so a default queue ends up handling the job instead of the expected notification queue.



      So I looked at the documentation https://laravel.com/docs/5.5/events#queued-event-listeners, which states that the name should be set on a queue property on the listener. My problem is that I have the queue name in an environment variable, so I cannot just set it directly as a property, as shown in the documentation and it does not work to set it on the constructor, like so:



      protected $queue;

      public function __construct()

      $this->queue = Queue::getNotificationQueue();



      Does anyone here have an idea of how I can get around this?







      laravel laravel-5 queue listener jobs






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 7 at 22:48









      SeverinDKSeverinDK

      13810




      13810






















          1 Answer
          1






          active

          oldest

          votes


















          1














          Specifically for SQS queues the $queue property acts a bit weird because it doesn't seem to refer to queues defined in queue.php, but it expects a full queue url, so even the example in the documentation seems off.



          But for dynamic queue names on queued event listeners that for example changes depending on environment, making a custom SqsConnector and SqsQueue will be one way to solve your issue.



          Here is an example of implementation.



          ACMEEventListener.php



          class ACMEEventListener implements ShouldQueue

          public function handle(Event $event): void

          // I'm going to a custom queue


          public static function getQueue(): string

          return 'https://sqs.eu-central-1.amazonaws.com/<account id>/<queue name>';




          CustomSqsConnector.php



          use IlluminateQueueConnectorsSqsConnector;
          use AwsSqsSqsClient;

          class CustomSqsConnector extends SqsConnector

          public function connect(array $config)

          $sqs = new SqsClient($config);

          return new CustomSqsQueue($sqs, $config['queue']);




          CustomSqsQueue.php



          class CustomSqsQueue extends IlluminateQueueSqsQueue


          public function push($job, $data = '', $queue = null)

          if ($job instanceof CallQueuedListener && method_exists($job->class, 'getQueue'))
          $queue = $job->class::getQueue();


          return $this->pushRaw($this->createPayload($job, $data), $queue);




          CustomSqsQueueServiceProvider.php



          class CustomSqsQueueServiceProvider extends ServiceProvider

          public function register(): void

          $this->app->booted(function ()
          $this->app['queue']->extend('custom_sqs', function ()
          return new CustomSqsConnector;
          );
          );




          And then in your queue.php, your default SQS connection driver from sqs to custom_sqs






          share|improve this answer























          • Makes sense. I will attempt this solution and get back to you soon. Thanks.

            – SeverinDK
            Mar 8 at 13:58











          • Works. Thank you!

            – SeverinDK
            Mar 8 at 15:04











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55054041%2fhow-to-set-listener-queue-name-from-environment-variable%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Specifically for SQS queues the $queue property acts a bit weird because it doesn't seem to refer to queues defined in queue.php, but it expects a full queue url, so even the example in the documentation seems off.



          But for dynamic queue names on queued event listeners that for example changes depending on environment, making a custom SqsConnector and SqsQueue will be one way to solve your issue.



          Here is an example of implementation.



          ACMEEventListener.php



          class ACMEEventListener implements ShouldQueue

          public function handle(Event $event): void

          // I'm going to a custom queue


          public static function getQueue(): string

          return 'https://sqs.eu-central-1.amazonaws.com/<account id>/<queue name>';




          CustomSqsConnector.php



          use IlluminateQueueConnectorsSqsConnector;
          use AwsSqsSqsClient;

          class CustomSqsConnector extends SqsConnector

          public function connect(array $config)

          $sqs = new SqsClient($config);

          return new CustomSqsQueue($sqs, $config['queue']);




          CustomSqsQueue.php



          class CustomSqsQueue extends IlluminateQueueSqsQueue


          public function push($job, $data = '', $queue = null)

          if ($job instanceof CallQueuedListener && method_exists($job->class, 'getQueue'))
          $queue = $job->class::getQueue();


          return $this->pushRaw($this->createPayload($job, $data), $queue);




          CustomSqsQueueServiceProvider.php



          class CustomSqsQueueServiceProvider extends ServiceProvider

          public function register(): void

          $this->app->booted(function ()
          $this->app['queue']->extend('custom_sqs', function ()
          return new CustomSqsConnector;
          );
          );




          And then in your queue.php, your default SQS connection driver from sqs to custom_sqs






          share|improve this answer























          • Makes sense. I will attempt this solution and get back to you soon. Thanks.

            – SeverinDK
            Mar 8 at 13:58











          • Works. Thank you!

            – SeverinDK
            Mar 8 at 15:04















          1














          Specifically for SQS queues the $queue property acts a bit weird because it doesn't seem to refer to queues defined in queue.php, but it expects a full queue url, so even the example in the documentation seems off.



          But for dynamic queue names on queued event listeners that for example changes depending on environment, making a custom SqsConnector and SqsQueue will be one way to solve your issue.



          Here is an example of implementation.



          ACMEEventListener.php



          class ACMEEventListener implements ShouldQueue

          public function handle(Event $event): void

          // I'm going to a custom queue


          public static function getQueue(): string

          return 'https://sqs.eu-central-1.amazonaws.com/<account id>/<queue name>';




          CustomSqsConnector.php



          use IlluminateQueueConnectorsSqsConnector;
          use AwsSqsSqsClient;

          class CustomSqsConnector extends SqsConnector

          public function connect(array $config)

          $sqs = new SqsClient($config);

          return new CustomSqsQueue($sqs, $config['queue']);




          CustomSqsQueue.php



          class CustomSqsQueue extends IlluminateQueueSqsQueue


          public function push($job, $data = '', $queue = null)

          if ($job instanceof CallQueuedListener && method_exists($job->class, 'getQueue'))
          $queue = $job->class::getQueue();


          return $this->pushRaw($this->createPayload($job, $data), $queue);




          CustomSqsQueueServiceProvider.php



          class CustomSqsQueueServiceProvider extends ServiceProvider

          public function register(): void

          $this->app->booted(function ()
          $this->app['queue']->extend('custom_sqs', function ()
          return new CustomSqsConnector;
          );
          );




          And then in your queue.php, your default SQS connection driver from sqs to custom_sqs






          share|improve this answer























          • Makes sense. I will attempt this solution and get back to you soon. Thanks.

            – SeverinDK
            Mar 8 at 13:58











          • Works. Thank you!

            – SeverinDK
            Mar 8 at 15:04













          1












          1








          1







          Specifically for SQS queues the $queue property acts a bit weird because it doesn't seem to refer to queues defined in queue.php, but it expects a full queue url, so even the example in the documentation seems off.



          But for dynamic queue names on queued event listeners that for example changes depending on environment, making a custom SqsConnector and SqsQueue will be one way to solve your issue.



          Here is an example of implementation.



          ACMEEventListener.php



          class ACMEEventListener implements ShouldQueue

          public function handle(Event $event): void

          // I'm going to a custom queue


          public static function getQueue(): string

          return 'https://sqs.eu-central-1.amazonaws.com/<account id>/<queue name>';




          CustomSqsConnector.php



          use IlluminateQueueConnectorsSqsConnector;
          use AwsSqsSqsClient;

          class CustomSqsConnector extends SqsConnector

          public function connect(array $config)

          $sqs = new SqsClient($config);

          return new CustomSqsQueue($sqs, $config['queue']);




          CustomSqsQueue.php



          class CustomSqsQueue extends IlluminateQueueSqsQueue


          public function push($job, $data = '', $queue = null)

          if ($job instanceof CallQueuedListener && method_exists($job->class, 'getQueue'))
          $queue = $job->class::getQueue();


          return $this->pushRaw($this->createPayload($job, $data), $queue);




          CustomSqsQueueServiceProvider.php



          class CustomSqsQueueServiceProvider extends ServiceProvider

          public function register(): void

          $this->app->booted(function ()
          $this->app['queue']->extend('custom_sqs', function ()
          return new CustomSqsConnector;
          );
          );




          And then in your queue.php, your default SQS connection driver from sqs to custom_sqs






          share|improve this answer













          Specifically for SQS queues the $queue property acts a bit weird because it doesn't seem to refer to queues defined in queue.php, but it expects a full queue url, so even the example in the documentation seems off.



          But for dynamic queue names on queued event listeners that for example changes depending on environment, making a custom SqsConnector and SqsQueue will be one way to solve your issue.



          Here is an example of implementation.



          ACMEEventListener.php



          class ACMEEventListener implements ShouldQueue

          public function handle(Event $event): void

          // I'm going to a custom queue


          public static function getQueue(): string

          return 'https://sqs.eu-central-1.amazonaws.com/<account id>/<queue name>';




          CustomSqsConnector.php



          use IlluminateQueueConnectorsSqsConnector;
          use AwsSqsSqsClient;

          class CustomSqsConnector extends SqsConnector

          public function connect(array $config)

          $sqs = new SqsClient($config);

          return new CustomSqsQueue($sqs, $config['queue']);




          CustomSqsQueue.php



          class CustomSqsQueue extends IlluminateQueueSqsQueue


          public function push($job, $data = '', $queue = null)

          if ($job instanceof CallQueuedListener && method_exists($job->class, 'getQueue'))
          $queue = $job->class::getQueue();


          return $this->pushRaw($this->createPayload($job, $data), $queue);




          CustomSqsQueueServiceProvider.php



          class CustomSqsQueueServiceProvider extends ServiceProvider

          public function register(): void

          $this->app->booted(function ()
          $this->app['queue']->extend('custom_sqs', function ()
          return new CustomSqsConnector;
          );
          );




          And then in your queue.php, your default SQS connection driver from sqs to custom_sqs







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 8 at 13:52









          mewmmewm

          932713




          932713












          • Makes sense. I will attempt this solution and get back to you soon. Thanks.

            – SeverinDK
            Mar 8 at 13:58











          • Works. Thank you!

            – SeverinDK
            Mar 8 at 15:04

















          • Makes sense. I will attempt this solution and get back to you soon. Thanks.

            – SeverinDK
            Mar 8 at 13:58











          • Works. Thank you!

            – SeverinDK
            Mar 8 at 15:04
















          Makes sense. I will attempt this solution and get back to you soon. Thanks.

          – SeverinDK
          Mar 8 at 13:58





          Makes sense. I will attempt this solution and get back to you soon. Thanks.

          – SeverinDK
          Mar 8 at 13:58













          Works. Thank you!

          – SeverinDK
          Mar 8 at 15:04





          Works. Thank you!

          – SeverinDK
          Mar 8 at 15:04



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55054041%2fhow-to-set-listener-queue-name-from-environment-variable%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          1928 у кіно

          Захаров Федір Захарович

          Ель Греко