This commit is contained in:
@@ -117,41 +117,41 @@ public abstract class MessageAgent {
|
|||||||
this.httpNodes.put(topic, new HttpMessageNode(ns, service, servlet, processor, createConsumer(topic, processor)));
|
this.httpNodes.put(topic, new HttpMessageNode(ns, service, servlet, processor, createConsumer(topic, processor)));
|
||||||
}
|
}
|
||||||
|
|
||||||
//格式: sncp:req:user
|
//格式: sncp.req.user
|
||||||
protected String generateSncpReqTopic(Service service) {
|
protected String generateSncpReqTopic(Service service) {
|
||||||
String resname = Sncp.getResourceName(service);
|
String resname = Sncp.getResourceName(service);
|
||||||
return "sncp:req:" + Sncp.getResourceType(service).getSimpleName().replaceAll("Service.*$", "").toLowerCase() + (resname.isEmpty() ? "" : ("-" + resname));
|
return "sncp.req." + Sncp.getResourceType(service).getSimpleName().replaceAll("Service.*$", "").toLowerCase() + (resname.isEmpty() ? "" : ("-" + resname));
|
||||||
}
|
}
|
||||||
|
|
||||||
//格式: sncp:resp:node10
|
//格式: sncp.resp.node10
|
||||||
protected String generateSncpRespTopic() {
|
protected String generateSncpRespTopic() {
|
||||||
return "sncp:resp:node" + nodeid;
|
return "sncp.resp.node" + nodeid;
|
||||||
}
|
}
|
||||||
|
|
||||||
//格式: http:req:user
|
//格式: http.req.user
|
||||||
public String generateHttpReqTopic(String module) {
|
public String generateHttpReqTopic(String module) {
|
||||||
return "http:req:" + module.toLowerCase();
|
return "http.req." + module.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
//格式: http:req:user
|
//格式: http.req.user
|
||||||
protected String generateHttpReqTopic(Service service) {
|
protected String generateHttpReqTopic(Service service) {
|
||||||
String resname = Sncp.getResourceName(service);
|
String resname = Sncp.getResourceName(service);
|
||||||
return "http:req:" + Rest.getWebModuleName(service.getClass()).toLowerCase() + (resname.isEmpty() ? "" : ("-" + resname));
|
return "http.req." + Rest.getRestName(service).toLowerCase() + (resname.isEmpty() ? "" : ("-" + resname));
|
||||||
}
|
}
|
||||||
|
|
||||||
//格式: http:resp:node10
|
//格式: http.resp.node10
|
||||||
protected String generateHttpRespTopic() {
|
protected String generateHttpRespTopic() {
|
||||||
return "http:resp:node" + nodeid;
|
return "http.resp.node" + nodeid;
|
||||||
}
|
}
|
||||||
|
|
||||||
//格式: ws:resp:wsgame
|
//格式: ws.resp.wsgame
|
||||||
public String generateWebSocketRespTopic(WebSocketNode node) {
|
public String generateWebSocketRespTopic(WebSocketNode node) {
|
||||||
return "ws:resp:" + node.getName();
|
return "ws.resp." + node.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
//格式: xxxx:resp:node10
|
//格式: xxxx.resp.node10
|
||||||
protected String generateRespTopic(String protocol) {
|
protected String generateRespTopic(String protocol) {
|
||||||
return protocol + ":resp:node" + nodeid;
|
return protocol + ".resp.node" + nodeid;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class HttpMessageNode {
|
protected static class HttpMessageNode {
|
||||||
|
|||||||
@@ -22,15 +22,19 @@ public abstract class MessageConsumer extends Thread {
|
|||||||
|
|
||||||
protected final String topic;
|
protected final String topic;
|
||||||
|
|
||||||
|
protected MessageAgent agent;
|
||||||
|
|
||||||
protected final MessageProcessor processor;
|
protected final MessageProcessor processor;
|
||||||
|
|
||||||
protected final Logger logger = Logger.getLogger(this.getClass().getSimpleName());
|
protected final Logger logger = Logger.getLogger(this.getClass().getSimpleName());
|
||||||
|
|
||||||
protected volatile boolean closed;
|
protected volatile boolean closed;
|
||||||
|
|
||||||
protected MessageConsumer(String topic, MessageProcessor processor) {
|
protected MessageConsumer(MessageAgent agent, String topic, MessageProcessor processor) {
|
||||||
|
Objects.requireNonNull(agent);
|
||||||
Objects.requireNonNull(topic);
|
Objects.requireNonNull(topic);
|
||||||
Objects.requireNonNull(processor);
|
Objects.requireNonNull(processor);
|
||||||
|
this.agent = agent;
|
||||||
this.topic = topic;
|
this.topic = topic;
|
||||||
this.processor = processor;
|
this.processor = processor;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import org.redkale.asm.Type;
|
|||||||
import org.redkale.convert.*;
|
import org.redkale.convert.*;
|
||||||
import org.redkale.convert.json.*;
|
import org.redkale.convert.json.*;
|
||||||
import org.redkale.net.Cryptor;
|
import org.redkale.net.Cryptor;
|
||||||
|
import org.redkale.net.sncp.Sncp;
|
||||||
import org.redkale.service.*;
|
import org.redkale.service.*;
|
||||||
import org.redkale.util.*;
|
import org.redkale.util.*;
|
||||||
import org.redkale.source.Flipper;
|
import org.redkale.source.Flipper;
|
||||||
@@ -172,7 +173,7 @@ public final class Rest {
|
|||||||
return (!controller.name().isEmpty()) ? controller.name().trim() : serviceType.getSimpleName().replaceAll("Service.*$", "").toLowerCase();
|
return (!controller.name().isEmpty()) ? controller.name().trim() : serviceType.getSimpleName().replaceAll("Service.*$", "").toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getWebModuleName(Class<? extends Service> serviceType) {
|
static String getWebModuleName(Class<? extends Service> serviceType) {
|
||||||
final RestService controller = serviceType.getAnnotation(RestService.class);
|
final RestService controller = serviceType.getAnnotation(RestService.class);
|
||||||
if (controller == null) return serviceType.getSimpleName().replaceAll("Service.*$", "");
|
if (controller == null) return serviceType.getSimpleName().replaceAll("Service.*$", "");
|
||||||
if (controller.ignore()) return null;
|
if (controller.ignore()) return null;
|
||||||
@@ -205,6 +206,13 @@ public final class Rest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getRestName(Service service) {
|
||||||
|
final RestService controller = service.getClass().getAnnotation(RestService.class);
|
||||||
|
if (controller != null && !controller.name().isEmpty()) return controller.name();
|
||||||
|
final Class serviceType = Sncp.getServiceType(service);
|
||||||
|
return serviceType.getSimpleName().replaceAll("Service.*$", "");
|
||||||
|
}
|
||||||
|
|
||||||
//仅供Rest动态构建里 currentUserid() 使用
|
//仅供Rest动态构建里 currentUserid() 使用
|
||||||
public static <T> T orElse(T t, T defValue) {
|
public static <T> T orElse(T t, T defValue) {
|
||||||
return t == null ? defValue : t;
|
return t == null ? defValue : t;
|
||||||
|
|||||||
Reference in New Issue
Block a user