This commit is contained in:
@@ -8,6 +8,7 @@ package org.redkale.mq;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import org.redkale.convert.*;
|
import org.redkale.convert.*;
|
||||||
|
import org.redkale.convert.json.JsonConvert;
|
||||||
import org.redkale.util.Comment;
|
import org.redkale.util.Comment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -72,6 +73,9 @@ public class MessageRecord implements Serializable {
|
|||||||
@Comment("消息内容的类型")
|
@Comment("消息内容的类型")
|
||||||
protected byte ctype;
|
protected byte ctype;
|
||||||
|
|
||||||
|
@Comment("本地附加对象,不会被序列化")
|
||||||
|
protected Object localattach;
|
||||||
|
|
||||||
public MessageRecord() {
|
public MessageRecord() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,6 +104,11 @@ public class MessageRecord implements Serializable {
|
|||||||
return content == null ? null : new String(content, StandardCharsets.UTF_8);
|
return content == null ? null : new String(content, StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MessageRecord attach(Object attach) {
|
||||||
|
this.localattach = attach;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@ConvertDisabled
|
@ConvertDisabled
|
||||||
public boolean isEmptyTopic() {
|
public boolean isEmptyTopic() {
|
||||||
return this.topic == null || this.topic.isEmpty();
|
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.resptopic != null) sb.append(",\"resptopic\":\"").append(this.resptopic).append("\"");
|
||||||
if (this.content != null) {
|
if (this.content != null) {
|
||||||
if (this.ctype == CTYPE_HTTP_REQUEST) {
|
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) {
|
} 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 {
|
} 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("}");
|
sb.append("}");
|
||||||
|
|||||||
@@ -289,6 +289,12 @@ public final class SncpClient {
|
|||||||
if (targetTopic == null) targetTopic = this.topic;
|
if (targetTopic == null) targetTopic = this.topic;
|
||||||
MessageRecord message = messageClient.createMessageRecord(targetTopic, null, reqbytes);
|
MessageRecord message = messageClient.createMessageRecord(targetTopic, null, reqbytes);
|
||||||
final String tt = targetTopic;
|
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 -> {
|
return messageClient.sendMessage(message).thenApply(msg -> {
|
||||||
if (msg == null || msg.getContent() == null) {
|
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);
|
logger.log(Level.SEVERE, action.method + " sncp mq(params: " + convert.convertTo(params) + ", message: " + message + ") deal error, this.topic = " + this.topic + ", targetTopic = " + tt + ", result = " + msg);
|
||||||
|
|||||||
Reference in New Issue
Block a user