public class TopicUtils extends Object
| 构造器和说明 |
|---|
TopicUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static List<String> |
expand(String topic)
展开topic
before:
/device/a,b,v/*
after:
/device/a/*
/device/b/*
/device/v/*
before:
/device/{id}
after:
/device/*
|
static Map<String,String> |
getPathVariables(String template,
String topic)
根据模版从url上提取变量,如果提取出错则返回空Map
getPathVariables("/device/{productId}","/device/test123");
=> {"productId","test1234"}
|
static boolean |
match(String[] pattern,
String[] topicParts) |
static boolean |
match(String pattern,
String topic)
匹配topic
match("/test/*","/test/1"); // true
match("/test/*","/test/1/2"); // false
match("/test/**","/test/1/2"); // true
|
static String[] |
split(String topic)
分隔topic
|
public static boolean match(String pattern, String topic)
match("/test/*","/test/1"); // true
match("/test/*","/test/1/2"); // false
match("/test/**","/test/1/2"); // true
pattern - 匹配模版topic - 要匹配的topicpublic static Map<String,String> getPathVariables(String template, String topic)
getPathVariables("/device/{productId}","/device/test123");
=> {"productId","test1234"}
template - 模版topic - 要提取的topicCopyright © 2019–2022. All rights reserved.