This commit is contained in:
Redkale
2021-01-12 18:38:10 +08:00
parent bcad47ebd5
commit 0ae469d8e2
2 changed files with 20 additions and 3 deletions

View File

@@ -8,6 +8,7 @@ package org.redkale.mq;
import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import org.redkale.convert.*;
import org.redkale.convert.json.JsonConvert;
import org.redkale.util.Comment;
/**
@@ -72,6 +73,9 @@ public class MessageRecord implements Serializable {
@Comment("消息内容的类型")
protected byte ctype;
@Comment("本地附加对象,不会被序列化")
protected Object localattach;
public MessageRecord() {
}
@@ -100,6 +104,11 @@ public class MessageRecord implements Serializable {
return content == null ? null : new String(content, StandardCharsets.UTF_8);
}
public MessageRecord attach(Object attach) {
this.localattach = attach;
return this;
}
@ConvertDisabled
public boolean isEmptyTopic() {
return this.topic == null || this.topic.isEmpty();
@@ -266,11 +275,13 @@ public class MessageRecord implements Serializable {
if (this.resptopic != null) sb.append(",\"resptopic\":\"").append(this.resptopic).append("\"");
if (this.content != null) {
if (this.ctype == CTYPE_HTTP_REQUEST) {
sb.append(",\"content\":").append(HttpSimpleRequestCoder.getInstance().decode(this.content)).append("\"");
sb.append(",\"content\":").append(HttpSimpleRequestCoder.getInstance().decode(this.content));
} else if (this.ctype == CTYPE_HTTP_RESULT) {
sb.append(",\"content\":").append(HttpResultCoder.getInstance().decode(this.content)).append("\"");
sb.append(",\"content\":").append(HttpResultCoder.getInstance().decode(this.content));
} else if (localattach != null) {
sb.append(",\"attach\":").append(JsonConvert.root().convertTo(localattach));
} else {
sb.append(",\"content\":").append(new String(this.content, StandardCharsets.UTF_8)).append("\"");
sb.append(",\"content\":\"").append(new String(this.content, StandardCharsets.UTF_8)).append("\"");
}
}
sb.append("}");

View File

@@ -289,6 +289,12 @@ public final class SncpClient {
if (targetTopic == null) targetTopic = this.topic;
MessageRecord message = messageClient.createMessageRecord(targetTopic, null, reqbytes);
final String tt = targetTopic;
if (logger.isLoggable(Level.FINER)) {
Object n = action.method.getDeclaringClass().getSimpleName() + "." + action.method.getName();
message.attach(Utility.append(new Object[]{n}, params));
} else {
message.attach(params);
}
return messageClient.sendMessage(message).thenApply(msg -> {
if (msg == null || msg.getContent() == null) {
logger.log(Level.SEVERE, action.method + " sncp mq(params: " + convert.convertTo(params) + ", message: " + message + ") deal error, this.topic = " + this.topic + ", targetTopic = " + tt + ", result = " + msg);