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

          Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

          Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

          Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved