background
The previous article described how to register an instance with Divide plug-in in the Soul Gateway administration background once the back-end HTTP service is started.
This article continues to see how the Divide plug-in probes back-end service instances.
IP + port source code analysis
Soul – the admin side
-
When soul-admin is started, the soul.upstreamCheckService is instantiated to check the soul.upflow. check parameter, which defaults to true;
-
UpstreamCheckService creates a timed thread pool that is scheduled every 10 seconds. The task of the thread pool is to iterate over all of Divide’s selectors, calling check to check its list of upstream services.
private void scheduled() { if (UPSTREAM_MAP.size() > 0) { UPSTREAM_MAP.forEach(this::check); }}Copy the code
-
The check method iterates through the current selector list of back-end services, and then calls the checkUrl method to check whether the connection is healthy.
-
The checkUrl method splits IP and port based on the configuration item and checks the connectivity by establishing socket connections.
private static boolean isHostConnector(final String host, final int port) { try (Socket socket = new Socket()) { socket.connect(new InetSocketAddress(host, port)); } catch (IOException e) { return false; } return true; } Copy the code
-
The soul-admin management background updates the back-end service configuration list based on the connectivity check result. This completes a service exploration process.
Soul – the bootstrap
-
Soul-bootstrap also probes upstream instances and is disabled by default; Enabled with the soul.upwell. check configuration;
-
The UpstreamCacheManager instantiation creates a timed thread pool, which is scheduled every 30 seconds by default. The whole process is basically the same as the soul-admin side;
conclusion
- A simple implementation of probing 🙂
private static boolean isHostConnector(final String host, final int port) { try (Socket socket = new Socket()) { socket.connect(new InetSocketAddress(host, port)); } catch (IOException e) { return false; } return true; } Copy the code
series
- Soul source learning [1] – preliminary exploration
- Soul source learning [2] – divide load balancing plug-in
- Soul source learning [3] – Dubbo plug-in
- Soul source learning [4] – RateLimiter stream limiting plug-in
- Soul source learning [5] – SpringCloud plug-in
- Soul source learning [6] – Chain of responsibility mode
- Soul source learning [7] – Data synchronization strategy websocket synchronization
- [8] – Data synchronization strategy for ZooKeeper synchronization
- [9] – ZooKeeper Synchronization (2)
- Soul source learning [10] – Observer mode application
- Soul source learning [11] – Data synchronization strategy HTTP long poll synchronization
- Soul source learning [12] – Data Synchronization strategy HTTP long Poll synchronization (2)
- Soul source learning [13] – data synchronization strategy comparison
- Soul source learning [14] – Deep into divide plug-in