在线发送消息支持选择同步、异步发送.

This commit is contained in:
许晓东
2023-11-28 21:21:37 +08:00
parent 471e1e4962
commit dc84144443
5 changed files with 62 additions and 9 deletions

View File

@@ -26,6 +26,11 @@ public class SendMessage {
private List<Header> headers;
/**
* true: sync send.
*/
private boolean sync;
@Data
public static class Header{
private String headerKey;

View File

@@ -231,9 +231,16 @@ public class MessageServiceImpl implements MessageService, ApplicationContextAwa
@Override public ResponseData sendWithHeader(SendMessage message) {
String[] headerKeys= message.getHeaders().stream().map(SendMessage.Header::getHeaderKey).toArray(String[]::new);
String[] headerValues= message.getHeaders().stream().map(SendMessage.Header::getHeaderValue).toArray(String[]::new);
log.info("send with header:keys{},values{}",headerKeys, headerValues);
messageConsole.send(message.getTopic(), message.getPartition(), message.getKey(), message.getBody(), message.getNum(), headerKeys, headerValues);
return ResponseData.create().success();
// log.info("send with header:keys{},values{}",headerKeys, headerValues);
Tuple2<Object, String> tuple2 = messageConsole.send(message.getTopic(),
message.getPartition(),
message.getKey(),
message.getBody(),
message.getNum(),
headerKeys,
headerValues,
message.isSync());
return (boolean)tuple2._1 ? ResponseData.create().success() : ResponseData.create().failed(tuple2._2);
}
@Override public ResponseData resend(SendMessage message) {