Zend\ServiceManager\Exception\ServiceNotCreatedException An exception was raised while creating "emails"; no instance returned
shadow-fox opened this issue · 3 comments
Hi,
I have followed the docs. Using configuration I have set up my queue,
'slm_queue' => array(
'queue_manager' => array(
'factories' => array(
'emails' => 'SlmQueueSqs\Factory\SqsQueueFactory'
),
),
'job_manager' => array(
'factories' => array(
'DemoModule\Job\SendEmail' => 'DemoModule\Job\SendEmailFactory',
),
'invokables' => array(
),
),
),
In the Factory, I have used in a MapperFactory,
$queueManager = $services->get('SlmQueue\Queue\QueuePluginManager');
$queue = $queueManager->get('emails');
return new DemoMapper($dbAdapter, $queue);
And in the Mapper constructor,
protected $queue;
public function __construct(AdapterInterface $adapter, $queue)
{
$this->adapter = $adapter;
$this->queue = $queue;
}
I am getting this error:
An exception was raised while creating "emails"; no instance returned
Also from the AWS module,
Aws\Sqs\Exception\SqsException
File:
demo/vendor/aws/aws-sdk-php/src/Aws/Common/Exception/NamespaceExceptionFactory.php:91
Message: The specified queue does not exist for this wsdl version.
Hi,
This is expected. SlmQueueSqs cannot create queues and it expects you to create them using AWS sdk or in the SQS console.
Here is the possible ways to configure it:
'slm_queue' => [
'queues' => [
'my-first-queue' => [
'queue_url' => 'https://aws.queue-url'
],
'my-second-queue' => 'my-aws-second-queue-name'
],
'queue_manager' => [
'factories' => [
'my-first-queue' => SqsQueueFactory::class,
'my-second-queue' => SqsQueueFactory::class
]
]
],
As you can see this is configuration in two steps. In the queue_manager array we just say :those are SQS queues, you should create them using the sqs queue factory.
On the other hand, in the queues option array, we give option to tell how the queue is referenced on SQS. SlmQueueSqs supports two ways :
- by directly passing the sqs queue URL (you can find it on sqs console), as you can see for my-first-queue
- by associating the queue name with another name that MUST BE the name of the queue in SQS (remember that queue names are unique across AWS).
I highly recommend the first way though, because if you do not specify an URL, the queue URL will be fetched each time from amazon using the name, so that you will have one additional http request. If your application is hosted in the same region as the SQS queue the latency impact should be pretty minimal, but still exists.
I hope it clarifies it's usage. I will update the doc once I'm coming back from holidays to make it clearer.
Sorry I cannot edit comments on the phone, but for "my-second-queue" the example is actually wrong. You have nothing to add in the "queues" option (only set it in the queue_manager).
But once again, I highly recommend you to use it using the queue_url option :)
Thanks @bakura10 I will try that. And update the issue here.