[英]Guzzle not using base uri when a dynamic endpoint is selected (Works locally but not on K8S)
我正在構建一個API網關和一堆微服務來運行我的公司。 我選擇使用PHP,因為這是我最有經驗的東西。
本地設置:Opensuse Tumbleweed,PHPStorm,php7.3,SQLite,docker遠程設置:GKE,PHP7.3 Percona Xtra DB和Docker
我正在使用Laravels Lumen Framework 5.8。
我的網關通過Guzzle6 Http Client與微服務通信,並且在本地運行良好。 使用Gitlab將其推送到集群以運行ci / cd管道以將其編譯為docker映像並將其部署到Google Cloud上的Kubernetes時。
我嘗試在“”和“”之間切換,我重寫了整個代碼,查看了Guzzle文檔,閱讀了很多docker中類似行為的堆棧溢出問題
路線
$router->get('/customers','CustomerController@getAll');
$router->post('/customers','CustomerController@createCustomer');
$router->get('/customers/{customer}','CustomerController@getCustomer');
$router->put('/customers/{customer}','CustomerController@updateCustomer');
$router->patch('/customers/{customer}','CustomerController@updateCustomer');
$router->delete('/customers/{customer}','CustomerController@deleteCustomer');
控制者
public function updateCustomer(Request $request, $customer)
{
return $this->successResponse($this->customerService->updateCustomer($request->all(), $customer));
}
public function deleteCustomer($customer)
{
return $this->successResponse($this->customerService->deleteCustomer($customer));
}
服務
public function createCustomer($data)
{
return $this->performRequest('POST','', $data);
}
public function getCustomer($customer)
{
return $this->performRequest('GET', "/{$customer}");
}
public function updateCustomer($data, $customer)
{
return $this->performRequest('PUT', "{$customer}", $data);
}
public function deleteCustomer($customer)
{
return $this->performRequest('DELETE', "{$customer}");
}
performRequest
public function performRequest($method, $requestUrl, $formParams = [], $headers = [])
{
$client = new Client([
'base_uri' => $this->baseUri,
]);
$response = $client->request($method, $requestUrl, ['form_params' => $formParams, 'headers' => $headers]);
return $response->getBody()->getContents();
}
本地端點:-獲取/聯系方式! -發布/聯系方式! -GET / contacts /(聯系人UUID標識符)有效! -PUT / PATCH / contacts /(聯系人UUID標識符)有效! -刪除/ contacts /(聯系人UUID標識符)!
端點生產:-獲取/聯系方式! -發布/聯系方式! -獲取/ contacts /(聯系人UUID標識符)失敗! -PUT / PATCH / contacts /(聯系人UUID標識符)失敗! -刪除/ contacts /(聯系人UUID標識符)失敗!
Sentry Bug Tracker顯示GuzzleHttp \\ Exception \\ RequestException cURL錯誤3 :(請參閱http://curl.haxx.se/libcurl/c/libcurl-errors.html )
當查看哨點上的URL時,失敗的端點上的基本URI被忽略,但這在我的本地計算機上不會發生。
網址不包含協議( http
),添加后將解決格式錯誤的網址錯誤。
最終網址: http://customer-microservice.customer-microservice.svc.cluster.local
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.