Connect your application to MSE Microservices Governance by using the Java agent and adding custom tracking with the Java SDK. This approach lets you flexibly instrument any code block.
Limitations
-
Make sure that your MSE Java agent is version 3.2.9 or later.
-
Due to programming model limitations, Microservices Governance displays only custom interfaces with active traffic.
For information about agent versions, see MSE Java agent release notes. You can also specify an agent version by following the instructions in Specify the version of the MSE agent.
Procedure
If your application is already connected to MSE Microservices Governance, follow these steps to add a custom interface.
-
Add the following dependency to your application's pom.xml file:
<dependency> <groupId>com.alibaba.csp</groupId> <artifactId>sentinel-core</artifactId> <version>1.8.7</version> </dependency> -
Add tracking. Wrap your business logic with the following code:
import com.alibaba.csp.sentinel.Entry; import com.alibaba.csp.sentinel.SphU; import com.alibaba.csp.sentinel.slots.block.BlockException; import com.alibaba.csp.sentinel.EntryType; // HelloWorld is the resource name. This name is displayed on the monitoring page and in the interface list in the console. // Rules are also configured based on this resource name. // EntryType.IN identifies this as an ingress resource. try (Entry entry = SphU.entry("HelloWorld", EntryType.IN)) { // Your protected business logic. System.out.println("Hello MSE Sentinel!"); } catch (BlockException e) { // A throttling or degradation event is triggered. Handle the event here, for example, by using a fallback or logging the event. }Note-
EntryType distinguishes whether the traffic on a resource is inbound or outbound. EntryType.IN indicates inbound traffic, and EntryType.OUT indicates outbound traffic. System rules take effect only on ingress resources.
-
The total application traffic shown on the console includes statistics for only EntryType.IN traffic.
-
The resource name for custom tracking cannot exceed 1,024 characters.
-
Use only the
-,_,., or:symbols for resource names in custom tracking.
-
Verify the results
Log on to the MSE console. In the left-side navigation pane, choose Microservices Governance > Application Governance. The connection is successful if the application's resource card appears on the Application Governance page and is reporting data.
Additionally, if your custom interface generates traffic, the interface appears on the Custom Interface tab for the corresponding application.
Navigate to the application's interface details page and select the Custom Interface tab. The left side lists each custom interface with metrics such as request volume and success rate. The right side displays monitoring charts for QPS and maximum concurrency for the selected interface.
Related documentation
You can protect your custom interfaces with traffic control measures. For more information, see Configure a throttling rule, Configure an isolation rule, and Configure a circuit breaking rule.