pom.xml in the application's root directory to add dependencyManagement for polaris-java:<dependencyManagement><dependencies><dependency><groupId>com.tencent.polaris</groupId><artifactId>polaris-dependencies</artifactId><version>${version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement>
<dependencies><dependency><groupId>com.tencent.polaris</groupId><artifactId>polaris-all</artifactId></dependency></dependencies>
global:serverConnectors:- id: polarisprotocol: grpcaddresses:# The IP address needs to be replaced with the client access IP address of the North Star engine you created.- 127.0.0.1:8091# Description: Configuration related to monitoring and log data reportingstatReporter:# Description: Whether to Enable Reportingenable: trueplugin:prometheus:type: push# Description: Configure the pushgateway IP address, effective only when type == push# The IP address needs to be replaced with the client access IP address of the North Star engine you created.address: 127.0.0.1:9091# Description: Set the execution interval for pushing metric data to pushgateway# Range: [1s:...], Default value: 10spushInterval: 10s
import com.tencent.polaris.factory.api.RouterAPIFactory;public static void main(String[] args) throws Exception {RouterAPI routerAPI = RouterAPIFactory.createRouterAPI();}
// ProcessRoutersRequest: Struct for executing routing requeststype ProcessRoutersRequest struct {// Optional parameter to set the routing plugin expected for this routing request// The currently supported routing plugins are as follows// - Custom Routing: ruleBasedRouter// - Nearby Routing: nearbyBasedRouter// - Metadata Routing: dstMetaRouterRouters []string// Optional parameter. Caller service information. You can set the traffic tag information for this request via ServiceInfo.MetadataSourceService ServiceInfo// Required parameter. The list of instances to be routed for services.// 1. InstancesResponse, returned from ConsumerAPI.GetAllInstances.// 2. DefaultServiceInstances, for user to construct manually.DstInstances ServiceInstances// Optional parameter, corresponding to the method($method) Tag in routing rulesMethod string// Optional. Timeout for a single query. Defaults to the global timeout configuration if not specified// Total maximum timeout duration is (1+RetryCount) * TimeoutTimeout *time.Duration// Optional. Retry count. Defaults to the global timeout configuration if not specifiedRetryCount *int}
ProcessRoutersRequest does not yet support the AddArgument method, and the server version >= 1.12.0, the corresponding key names for SourceService.Metadata are as follows:$path$method$header.{Tag key}$query.{Tag key}$cookie.{Tag key}$caller_ip{Tag key}ProcessRoutersRequest struct, you simply need to call the RouterAPI.processRouters method to complete service routing.ProcessRoutersResponse resp = routerAPI.processRouters(registerRequest)
피드백