1: yML configuration of consumer dubbo
dubbo:
consumer:
timeout: 300000
protocol:
name: dubbo
port: -1
cloud:
subscribed-services: order-server
# subscribed-services: hello-server,account-server,storage-server,order-server
Copy the code
2: Press CTRL + Left-click subscribed-services as shown below:
3: Here is the corresponding setter method, find the definition above:
/**
* All services of Dubbo.
*/
public static final String ALL_DUBBO_SERVICES = "*";
/**
* The subscribed services, the default value is "*". The multiple value will use
* comma(",") as the separator.
*
* @see #ALL_DUBBO_SERVICES
*/
private String subscribedServices = ALL_DUBBO_SERVICES;
Copy the code
Read the answer. The default value is *. Multiple values are separated by commas (,).
Next, let’s take a look at the most superficial process, which is to see what happens to the data we input, and how we find the provider.
4: Cursor over the DubboCloudProperties class. CTRL + click on the DubboCloudProperties class.
No usages found in Project Files
Press Ctrl+Alt+F7 again to search in 'Project and Libraries
Copy the code
5: Follow the reminder, Ctrl+Alt+F7, if the reminder is off, double click F7 to get the picture below
6: Enter directly, which is the highlighted line. Go back and copy ubscribedServices, no “S” at the beginning, lowercase or uppercase, Ctrl+F.
7: Read the source code by clicking the up and down arrow, or F3(next)/Shift+F3(previous). Here we see that he initialized at line 237.
- I sorted out some information, and friends in need can click to get it directly
- Microservice architecture: RPC+Dubbo+SpirngBoot+Alibaba+Docker+K8s
- Java Core Knowledge Set +25 topic interview set
As usual, CTRL + click the initSubscribedServices() method.
Read it. If ALL_DUBBO_SERVICES is equal to our input provider, it’s output blah, blah, blah.
9: So what is ALL_DUBBO_SERVICES? CTRL + click to find the first file again:
@ConfigurationProperties(prefix = CONFIG_PROPERTY_PREFIX) public class DubboCloudProperties { /** * All services of Dubbo. */ public static final String ALL_DUBBO_SERVICES = "*"; Private String subscribedServices = ALL_DUBBO_SERVICES; / *... * /}Copy the code
10: Now test the output of that thing, start a provider, and write * or comment out the provider to which the consumer subscribed. Start consumers.
View logs:
The 2021-05-27 16:28:24. 6564-950 WARN [client. The listener] A.C.D.M.R.D ubboServiceMetadataRepository: Current application will subscribe all services(size:20) in registry, a lot of memory and CPU cycles may be used, thus it's strongly recommend you using the externalized property 'dubbo.cloud.subscribed-services' to specify the servicesCopy the code
See Step 8.
11: Then read else, and if we fill in the content, join the collection and subscribedServices()
newSubscribedServices.addAll(dubboCloudProperties.subscribedServices());
Copy the code
CTRL subscribedServices() and you’ll go to the first file again:
Continue to read: use commaDelimitedListToStringArray will we enter into an array of strings, process the return.
12: let’s take a look at how commaDelimitedListToStringArray processing, find a place to import it:
import static org.springframework.util.StringUtils.commaDelimitedListToStringArray;
Then CTRL:
/**
* Convert a comma delimited list (e.g., a row from a CSV file) into an
* array of strings.
* @param str the input {@code String} (potentially {@code null} or empty)
* @return an array of strings, or the empty array in case of empty input
*/
public static String[] commaDelimitedListToStringArray(@Nullable String str) {
return delimitedListToStringArray(str, ",");
}
Copy the code
Separator The multiple value will use comma(“,”) as The separator. The corresponding.
Conclusion:
-
Do not write or * will subscribe to all.
-
Write too much use, separate.