Reputation: 223
when I add multiple solr server as endpoint and using a single solarium client to fire query on any solr server; I add replication master/slave to solr. for now I taste when the server for onecore(master or slave) is failed the client/solarium must use the available endpoint.
I get this ERROR:
Message: Solr HTTP error: HTTP request failed, Failed connect to 127.0.0.1:8983; No error
because i stop solr in port 8983 and solr is running at slave core in port 9000, in this case iam looking for to connect to localhost2 if localhost is not running. This is my code:
$config = array(
"endpoint" => array("localhost" => array("host"=>"127.0.0.1",
"port"=>"8983", "path"=>"/solr", "core"=>"master",),
"localhost2" => array("host"=>"127.0.0.1",
"port"=>"9000", "path"=>"/solr", "core"=>"slave",)
) );
$client = new Solarium\Client($config);
$ping = $client->createPing();
$client->ping($ping,"localhost2");
$client->getEndpoints();
when the key localhost is not running and the key localhost2 is runing in port 9000 i get this Message Solr HTTP error: HTTP request failed, Failed connect to 127.0.0.1:8983; No error
ANd the output of $client->getEndpoints();
object(Solarium\Client) {
[protected] options => array(
'adapter' => 'Solarium\Core\Client\Adapter\Curl',
'endpoint' => array(
'localhost' => array(
'host' => '*****',
'port' => '*****',
'path' => '/solr',
'core' => 'master'
),
'localhost2' => array(
'host' => '*****',
'port' => '*****',
'path' => '/solr',
'core' => 'slave'
)
)
)
[protected] queryTypes => array(
'select' => 'Solarium\QueryType\Select\Query\Query',
'update' => 'Solarium\QueryType\Update\Query\Query',
'ping' => 'Solarium\QueryType\Ping\Query',
'mlt' => 'Solarium\QueryType\MoreLikeThis\Query',
'analysis-document' => 'Solarium\QueryType\Analysis\Query\Document',
'analysis-field' => 'Solarium\QueryType\Analysis\Query\Field',
'terms' => 'Solarium\QueryType\Terms\Query',
'suggester' => 'Solarium\QueryType\Suggester\Query',
'extract' => 'Solarium\QueryType\Extract\Query',
'get' => 'Solarium\QueryType\RealtimeGet\Query'
)
[protected] pluginTypes => array(
'loadbalancer' => 'Solarium\Plugin\Loadbalancer\Loadbalancer',
'postbigrequest' => 'Solarium\Plugin\PostBigRequest',
'customizerequest' => 'Solarium\Plugin\CustomizeRequest\CustomizeRequest',
'parallelexecution' => 'Solarium\Plugin\ParallelExecution\ParallelExecution',
'bufferedadd' => 'Solarium\Plugin\BufferedAdd\BufferedAdd',
'prefetchiterator' => 'Solarium\Plugin\PrefetchIterator',
'minimumscorefilter' => 'Solarium\Plugin\MinimumScoreFilter\MinimumScoreFilter'
)
[protected] eventDispatcher => object(Symfony\Component\EventDispatcher\EventDispatcher) {
[private] listeners => array()
[private] sorted => array()
}
[protected] pluginInstances => array()
[protected] endpoints => array(
'localhost' => object(Solarium\Core\Client\Endpoint) {
[protected] options => array(
'host' => '*****',
'port' => '*****',
'scheme' => 'http',
'path' => '/solr',
'core' => 'master',
'timeout' => (int) 5,
'key' => 'localhost'
)
},
'localhost2' => object(Solarium\Core\Client\Endpoint) {
[protected] options => array(
'host' => '*****',
'port' => '*****',
'scheme' => 'http',
'path' => '/solr',
'core' => 'slave',
'timeout' => (int) 5,
'key' => 'localhost2'
)
}
)
[protected] defaultEndpoint => 'localhost'
[protected] adapter => null
}
Upvotes: 2
Views: 1624
Reputation: 343
This is used to make multiple solr connection in PHP frameworks.
To add the below code in your config folder
<?php
$config['endpoint1'] = array( // endpoint1 is a FIRST connection.
'endpoint' => array(
'localhost' => array(
'host' => 'host_name', // localhost or www.host.com
'port' => 'port_value', //Default 8983 or 8080 etc,
'path' => '/solr/',
'core' => 'solr_core_name' // core1 or movie1 or etc,
)
)
);
$config['endpoint2'] = array( // endpoint2 is a secound connection.
'endpoint' => array(
'localhost' => array(
'host' => 'host_name', // localhost or www.host.com
'port' => 'port_value', //Default 8983 or 8080 etc,
'path' => '/solr/',
'core' => 'solr_core_name' // core1 or movie1 or etc,
)
)
);
?>
And add connection link in __construct() method
public function __construct() {
parent::__construct();
$this->config->load('solarium');
$this->endpoint1 = new Solarium\Client($this->config->item('endpoint1'));
$this->endpoint2 = new Solarium\Client($this->config->item('endpoint2'));
}
If any doubt to setup solr and thier connection refer to this Github repository.
Upvotes: 0
Reputation: 190
This is how I manage to toggle between 'endpoints':
$endpoints=[
'endpoint' => [
'foo' => [
'host' => '127.0.0.1',
'port' => '9000',
'path' => 'foo',
'core' => 'foo',
'timeout' => 15
],
'baz' => [
'host' => '127.0.0.1',
'port' => '7464',
'path' => 'baz',
'core' => 'baz',
'timeout' => 15
],
]
];
$solrClient = new Solarium\Client($config);
$solrClient->setDefaultEndPoint('baz');
And the function setDefaultEndPoint will do the magic
setDefaultEndPoint
`
Upvotes: 1