Package com.networknt.consul
Class ConsulUtils
- java.lang.Object
-
- com.networknt.consul.ConsulUtils
-
public class ConsulUtils extends Object
-
-
Constructor Summary
Constructors Constructor Description ConsulUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ConsulService
buildService(URL url)
build consul service from urlstatic URL
buildUrl(String protocol, ConsulService service)
build url from servicestatic String
convertConsulSerivceId(URL url)
convert url to consul service id.static String
convertGroupToServiceName(String group)
convert group to service namestatic String
convertServiceId(String host, int port, String path)
static String
getGroupFromServiceName(String group)
get group from consul servicestatic String
getPathFromServiceId(String serviceId)
get path of url from service id in consulstatic String
getProtocolFromTag(String tag)
get protocol from consul tagstatic String
getUrlClusterInfo(URL url)
get cluster info from url, cluster info (protocol, path)static boolean
isSame(List<URL> urls1, List<URL> urls2)
Check if two lists have the same urls.
-
-
-
Method Detail
-
isSame
public static boolean isSame(List<URL> urls1, List<URL> urls2)
Check if two lists have the same urls.- Parameters:
urls1
- first url listurls2
- second url list- Returns:
- boolean true when they are the same
-
buildService
public static ConsulService buildService(URL url)
build consul service from url- Parameters:
url
- a URL object- Returns:
- ConsulService consul service
-
buildUrl
public static URL buildUrl(String protocol, ConsulService service)
build url from service- Parameters:
protocol
- the protocol of the serviceservice
- consul service- Returns:
- URL object
-
getUrlClusterInfo
public static String getUrlClusterInfo(URL url)
get cluster info from url, cluster info (protocol, path)- Parameters:
url
- a URL object- Returns:
- String url cluster info
-
convertGroupToServiceName
public static String convertGroupToServiceName(String group)
convert group to service name- Parameters:
group
- group- Returns:
- String service name
-
getGroupFromServiceName
public static String getGroupFromServiceName(String group)
get group from consul service- Parameters:
group
- group- Returns:
- group
-
convertConsulSerivceId
public static String convertConsulSerivceId(URL url)
convert url to consul service id. serviceid includes ip+port+service- Parameters:
url
- a URL object- Returns:
- service id
-
getPathFromServiceId
public static String getPathFromServiceId(String serviceId)
get path of url from service id in consul- Parameters:
serviceId
- service id- Returns:
- path
-
getProtocolFromTag
public static String getProtocolFromTag(String tag)
get protocol from consul tag- Parameters:
tag
- tag- Returns:
- protocol
-
-