Requirements: Some interfaces of Consul support the "block query" function, which can prevent frequent pulling of data in Consul, if the data does not change, it will be blocked until the specified time before responding, and if the data changes, the request will be responded immediately.
Many endpoints in Consul support a feature called "blocking queries." Blocking queries are used to wait for potential changes using long polling. Not all endpoints support blocking, but each endpoint uniquely documents its support for blocking queries in the documentation.
Documentation:The hyperlink login is visible.
Interfaces that support Blocking Queries to block queries
The response header returns:X-Consul-Index, request query parameters to carry:index(X-Consul-Index content of the last response header)
This article takes the KV storage query interface as an example, and the document:The hyperlink login is visible., as shown in the figure below:
The first time you don't carry the request parameter (or carry the default value of 0)
You can see that the response is returned immediately, and the response header contains the x-consul-index information, as shown in the following figure:
Request the interface again
Carry the index request parameter, you can see that the request is blocked (default is 5 minutes), and then the default waiting time will not respond, as shown in the figure below:
Modify the value of KV during the request process
If the Block Query function is triggered to wait during the request process, if the value of KV is modified, the request will respond immediately, as shown in the following figure:
For .NET/C# code calls, refer to the following:
Reference:The hyperlink login is visible.
(End)
|