This article is a mirror article of machine translation, please click here to jump to the original article.

View: 2987|Reply: 0

Detailed explanation of Blocking Queries in Consul

[Copy link]
Posted on 8/22/2024 11:11:24 AM | | | |
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)





Previous:.NET/C# to call the Baidu Universal Translation API API
Next:MikroTik (1) RB3011UiAS-RM unboxing picture
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com