I work with docker and microservices. Imagine we have 3 services:
user API
/
gateway API
\
hotel API
Requests go through the gateway to services. I have container with php
and nginx
, where volumes is the same. Next I give list of configs:
server {
server_name gateway.api.loc;
root /var/www/der-ibe/ibe-gateway-api/web;
client_max_body_size 32m;
location / {
try_files $uri @rewriteapp;
}
location @rewriteapp {
rewrite ^(.*)$ /app.php/$1 last;
}
location ~ ^/(app|app_dev|config)\.php(/|$) {
...
}
}
server {
server_name hotel.api.loc;
root /var/www/der-ibe/ibe-hotel-api/web;
client_max_body_size 32m;
location / {
try_files $uri @rewriteapp;
}
location @rewriteapp {
rewrite ^(.*)$ /app.php/$1 last;
}
location ~ ^/(app|app_dev|config)\.php(/|$) {
...
}
}
...
docker-compose.yml
version: "3.1"
services:
tphp:
build: docker/php
restart: always
container_name: my_tphp
extra_hosts:
- gateway.api.loc:172.14.10.10
- user.api.loc:172.14.10.10
- hotel.api.loc:172.14.10.10
networks:
- test
volumes:
- ../user-api:/var/www/user-api
- ../hotel-api:/var/www/hotel-api
- ./:/var/www/gateway-api
tnginx:
build: docker/nginx
restart: always
container_name: my_tnginx
ports:
- 80:80
networks:
test:
ipv4_address: 172.14.10.10
volumes:
- ../user-api:/var/www/user-api
- ../hotel-api:/var/www/hotel-api
- ./:/var/www/gateway-api
networks:
ibe:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.14.10.0/24
If I use simple cURL I can reach to hotel and user api, and I can get response from them, but if I try to do it with reactPHP - I can't! My peace of code:
public function asyncGetRequest(Route $route, $params, $token)
{
$url = $this->buildURL($route, $params);
$loop = React\EventLoop\Factory::create();
$dns = '172.14.10.10';
$sender = Clue\React\Buzz\Io\Sender::createFromLoopDns($loop, $dns);
//$url = 'http://172.14.10.10:3000/api/quota/list';
$client = new Clue\React\Buzz\Browser($loop, $sender);
//$client = new Clue\React\Buzz\Browser($loop);
$promise = $client->get($url,
[
'Authorization' => $token,
]
);
/** @var Response $response */
$response = new Response();
try {
$response = Clue\React\Block\await($promise, $loop);
} catch (ResponseException $e) {
$this->logger->error($e->getMessage());
}
dump($response->getBody()->getContents()); // I work on symfony 3.2
die;
}
Clue library is just wrapper for react
. So the error which I get is:
DNS query for hotel.api.loc timed out
and the last error An error occurred in the underlying stream
.
So I have a question: what I do wrong? Why I have access to nginx container by curl, but can't access by reactPHP? Even If point dns!
But if I use bare ip with port I can reach it. I'm not pro in dns, just basic knowledge.
UPDATE
I use Linux Debian (in container). Work on Mac.
A little about logic: when request URI is gateway.api.loc/api/hotel/list
inside gateway we send request to hotel.api.loc
to the same URL(/api/hotel/list
), accept response and return it.
I repeat that I have access to domains by cURL from, but can't do it with reactPHP and don't understand why...