修改:主题消息内容多行文本支持
This commit is contained in:
parent
d7058907d6
commit
9be0721de0
@ -8,10 +8,7 @@ import org.redkale.service.Service;
|
|||||||
import org.redkale.util.*;
|
import org.redkale.util.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.BufferedReader;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
@ -108,8 +105,22 @@ public class ZHubClient extends AbstractConsumer implements IConsumer, IProducer
|
|||||||
reader.readLine(); //$n len(key)
|
reader.readLine(); //$n len(key)
|
||||||
String topic = reader.readLine(); // topic
|
String topic = reader.readLine(); // topic
|
||||||
|
|
||||||
reader.readLine(); //$n len(value)
|
String lenStr = reader.readLine();//$n len(value)
|
||||||
String value = reader.readLine(); // value
|
int clen = 0;
|
||||||
|
if (lenStr.startsWith("$")) {
|
||||||
|
clen = Integer.parseInt(lenStr.replace("$", ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
String value = "";
|
||||||
|
do {
|
||||||
|
if (value.length() > 0) {
|
||||||
|
value += "\r\n";
|
||||||
|
}
|
||||||
|
String s = reader.readLine();
|
||||||
|
value += s; // value
|
||||||
|
} while (clen > 0 && clen > strLength(value));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// lock msg
|
// lock msg
|
||||||
if ("lock".equals(topic)) {
|
if ("lock".equals(topic)) {
|
||||||
@ -154,6 +165,7 @@ public class ZHubClient extends AbstractConsumer implements IConsumer, IProducer
|
|||||||
if (e instanceof SocketException) {
|
if (e instanceof SocketException) {
|
||||||
initSocket(Integer.MAX_VALUE);
|
initSocket(Integer.MAX_VALUE);
|
||||||
}
|
}
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
@ -261,7 +273,7 @@ public class ZHubClient extends AbstractConsumer implements IConsumer, IProducer
|
|||||||
StringBuffer buf = new StringBuffer();
|
StringBuffer buf = new StringBuffer();
|
||||||
buf.append("*" + data.length + "\r\n");
|
buf.append("*" + data.length + "\r\n");
|
||||||
for (String d : data) {
|
for (String d : data) {
|
||||||
buf.append("$" + d.length() + "\r\n");
|
buf.append("$" + strLength(d) + "\r\n");
|
||||||
buf.append(d + "\r\n");
|
buf.append(d + "\r\n");
|
||||||
}
|
}
|
||||||
sendMsgQueue.add(buf.toString());
|
sendMsgQueue.add(buf.toString());
|
||||||
@ -291,6 +303,11 @@ public class ZHubClient extends AbstractConsumer implements IConsumer, IProducer
|
|||||||
return false;
|
return false;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
private int strLength(String str) {
|
||||||
|
str = str.replaceAll("[^\\x00-\\xff]", "*");
|
||||||
|
return str.length();
|
||||||
|
}
|
||||||
|
|
||||||
private String toStr(Object v) {
|
private String toStr(Object v) {
|
||||||
if (v instanceof String) {
|
if (v instanceof String) {
|
||||||
return (String) v;
|
return (String) v;
|
||||||
|
Loading…
Reference in New Issue
Block a user