Symfony config + HttpClient gives "Invalid transport"
Closed this issue · 2 comments
jmsche commented
Hi,
I'm currently testing the new Symfony bundle, and I'm facing this issue when trying to index data:
In AbstractTransport.php line 129:
[Elastica\Exception\InvalidException]
Invalid transport
When I dump() the $transport before the if() statement, I get a string instead of a service:
@JoliCode\Elastically\Transport\HttpClientTransport
Here is my (truncated) Elastically config:
services:
_defaults:
autowire: true
autoconfigure: true
JoliCode\Elastically\Messenger\DocumentExchangerInterface:
alias: App\Elasticsearch\DocumentExchanger
JoliCode\Elastically\Transport\HttpClientTransport: ~
elastically:
connections:
default:
client:
host: '%env(ELASTICSEARCH_HOST)%'
port: '%env(ELASTICSEARCH_PORT)%'
transport: '@JoliCode\Elastically\Transport\HttpClientTransport'
mapping_directory: '%kernel.project_dir%/config/elasticsearch'
bulk_size: 100
prefix: formations_%kernel.environment%
index_class_mapping:
sector: App\Elasticsearch\Model\Sector
framework:
messenger:
transports:
sync: 'sync://'
routing:
'JoliCode\Elastically\Messenger\IndexationRequest': sync
Did I miss something?
lyrixx commented
Hmm, the @
in front of the transport value is suspicious.
And I checked, and I totally forgot to replace the transport by a Reference
if it exist.
Can you try something like :
diff --git a/src/Bridge/Symfony/DependencyInjection/ElasticallyExtension.php b/src/Bridge/Symfony/DependencyInjection/ElasticallyExtension.php
index 9e4e216..1a8e3db 100644
--- a/src/Bridge/Symfony/DependencyInjection/ElasticallyExtension.php
+++ b/src/Bridge/Symfony/DependencyInjection/ElasticallyExtension.php
@@ -64,6 +64,9 @@ class ElasticallyExtension extends Extension
$container->setDefinition("elastically.{$name}.result_set_builder", $resultSetBuilder);
$client = new ChildDefinition('elastically.abstract.client');
+ if (array_key_exists('transport', $config)) {
+ $config['transport'] = new Reference($config['transport']);
+ }
$client->replaceArgument('$config', $config['client']);
$client->replaceArgument('$resultSetBuilder', new Reference("elastically.{$name}.result_set_builder"));
$client->replaceArgument('$indexNameMapper', new Reference("elastically.{$name}.index_name_mapper"));
Note: you must relove the leading @