8 changed files with 285 additions and 119 deletions
@ -1,6 +1,6 @@ |
|||||
spring: |
spring: |
||||
profiles: |
profiles: |
||||
active: dev |
active: prod |
||||
include: util-dev,common |
include: util-prod,common |
||||
|
|
||||
|
|
||||
|
|||||
@ -1,105 +1,141 @@ |
|||||
package com.ccsens.util.bean.message.common; |
package com.ccsens.util.bean.message.common; |
||||
|
|
||||
import cn.hutool.core.date.DateUtil; |
import cn.hutool.core.collection.CollectionUtil; |
||||
import com.ccsens.util.JacksonUtil; |
import cn.hutool.core.date.DateUtil; |
||||
import com.fasterxml.jackson.annotation.JsonProperty; |
import com.alibaba.fastjson.JSONObject; |
||||
import com.fasterxml.jackson.core.JsonProcessingException; |
import com.ccsens.util.JacksonUtil; |
||||
import lombok.Data; |
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
|
import com.fasterxml.jackson.core.JsonProcessingException; |
||||
import java.util.Set; |
import io.swagger.annotations.ApiModel; |
||||
|
import lombok.Data; |
||||
/** |
|
||||
* @author wei |
import java.util.HashSet; |
||||
*/ |
import java.util.List; |
||||
@Data |
import java.util.Set; |
||||
public class InMessage { |
|
||||
/** |
/** |
||||
* 消息ID |
* @author wei |
||||
*/ |
*/ |
||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY) |
@Data |
||||
private String id; |
public class InMessage { |
||||
/** |
/** |
||||
* 发送时间(s) |
* 消息ID |
||||
* Notice: 指的是服务器收到发送请求的时间,不是服务器发出消息的时间 |
*/ |
||||
*/ |
@JsonProperty(access = JsonProperty.Access.READ_ONLY) |
||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY) |
private String id; |
||||
private Long time; |
/** |
||||
/** |
* 发送时间(s) |
||||
* 消息来自于那个域 |
* Notice: 指的是服务器收到发送请求的时间,不是服务器发出消息的时间 |
||||
*/ |
*/ |
||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY) |
@JsonProperty(access = JsonProperty.Access.READ_ONLY) |
||||
private MessageConstant.DomainType fromDomain; |
private Long time; |
||||
/** |
/** |
||||
* 发送者信息 |
* 消息来自于那个域 |
||||
*/ |
*/ |
||||
private String from; |
@JsonProperty(access = JsonProperty.Access.READ_ONLY) |
||||
/** |
private MessageConstant.DomainType fromDomain; |
||||
* 消息要发送到哪个域 |
/** |
||||
*/ |
* 发送者信息 |
||||
private MessageConstant.DomainType toDomain = MessageConstant.DomainType.User; |
*/ |
||||
/** |
private String from; |
||||
* 调用者信息 |
/** |
||||
* User : netty,无需配置 |
* 消息要发送到哪个域 |
||||
* Queue: 配置Queue Name |
*/ |
||||
* Rest : 配置URL,发送方式 |
private MessageConstant.DomainType toDomain = MessageConstant.DomainType.User; |
||||
* Server: 无需配置 |
/** |
||||
*/ |
* 调用者信息 |
||||
private MessageConstant.InvokerMessage invokerMessage; |
* User : netty,无需配置 |
||||
|
* Queue: 配置Queue Name |
||||
/** |
* Rest : 配置URL,发送方式 |
||||
* 接受者信息(列表) |
* Server: 无需配置 |
||||
*/ |
*/ |
||||
private Set<String> tos; |
private MessageConstant.InvokerMessage invokerMessage; |
||||
/** |
|
||||
* 消息的标示符(通常是由用户传过来的消息ID,该消息在用户系统中的ID) |
/** |
||||
*/ |
* 接受者信息(列表) |
||||
private String unikey; |
*/ |
||||
/** |
private Set<String> tos; |
||||
* 发送规则 |
/** |
||||
* DeSerialize but not serialize @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) |
* 消息的标示符(通常是由用户传过来的消息ID,该消息在用户系统中的ID) |
||||
*/ |
*/ |
||||
private MessageRule rule; |
private String unikey; |
||||
/** |
/** |
||||
* 发送内容 |
* 发送规则 |
||||
* 如果toDomain是Server: 代表消息是发给当前服务器的,必须是MessageSysData的子类型 |
* DeSerialize but not serialize @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) |
||||
* 其他:(格式不限,由用户指定) |
*/ |
||||
*/ |
private MessageRule rule; |
||||
private String data; |
/** |
||||
|
* 发送内容 |
||||
|
* 如果toDomain是Server: 代表消息是发给当前服务器的,必须是MessageSysData的子类型 |
||||
public InMessage(){ |
* 其他:(格式不限,由用户指定) |
||||
this.time = DateUtil.currentSeconds(); |
*/ |
||||
} |
private String data; |
||||
public static InMessage newToServerMessage(MessageConstant.DomainType fromDomain,ServerMessage serverMessage) throws JsonProcessingException { |
|
||||
InMessage inMessage = new InMessage(); |
|
||||
inMessage.setFromDomain(fromDomain); |
public InMessage(){ |
||||
inMessage.setToDomain(MessageConstant.DomainType.Server); |
this.time = DateUtil.currentSeconds(); |
||||
inMessage.setData(JacksonUtil.beanToJson(serverMessage)); |
} |
||||
return inMessage; |
public static InMessage newToServerMessage(MessageConstant.DomainType fromDomain,ServerMessage serverMessage) throws JsonProcessingException { |
||||
} |
InMessage inMessage = new InMessage(); |
||||
|
inMessage.setFromDomain(fromDomain); |
||||
public static InMessage newToQueueMessage(String from, Set<String> tos, String unikey, MessageRule rule, String data) throws JsonProcessingException { |
inMessage.setToDomain(MessageConstant.DomainType.Server); |
||||
InMessage inMessage = new InMessage(); |
inMessage.setData(JacksonUtil.beanToJson(serverMessage)); |
||||
inMessage.setToDomain(MessageConstant.DomainType.Queue); |
return inMessage; |
||||
inMessage.setFrom(from); |
} |
||||
inMessage.setTos(tos); |
|
||||
inMessage.setUnikey(unikey); |
public static InMessage newToQueueMessage(String from, Set<String> tos, String unikey, MessageRule rule, String data) throws JsonProcessingException { |
||||
inMessage.setRule(rule); |
InMessage inMessage = new InMessage(); |
||||
inMessage.setData(data); |
inMessage.setToDomain(MessageConstant.DomainType.Queue); |
||||
return inMessage; |
inMessage.setFrom(from); |
||||
} |
inMessage.setTos(tos); |
||||
public static InMessage newToUserMessage(String from, Set<String> tos, String unikey, MessageRule rule, String data) throws JsonProcessingException { |
inMessage.setUnikey(unikey); |
||||
InMessage inMessage = new InMessage(); |
inMessage.setRule(rule); |
||||
inMessage.setToDomain(MessageConstant.DomainType.User); |
inMessage.setData(data); |
||||
inMessage.setFrom(from); |
return inMessage; |
||||
inMessage.setTos(tos); |
} |
||||
inMessage.setUnikey(unikey); |
public static InMessage newToUserMessage(String from, Set<String> tos, String unikey, MessageRule rule, String data) throws JsonProcessingException { |
||||
inMessage.setRule(rule); |
InMessage inMessage = new InMessage(); |
||||
inMessage.setData(data); |
inMessage.setToDomain(MessageConstant.DomainType.User); |
||||
return inMessage; |
inMessage.setFrom(from); |
||||
} |
inMessage.setTos(tos); |
||||
|
inMessage.setUnikey(unikey); |
||||
|
inMessage.setRule(rule); |
||||
//TODO
|
inMessage.setData(data); |
||||
//添加方便链式调用的构造方法,类似builder
|
return inMessage; |
||||
} |
} |
||||
|
|
||||
|
|
||||
|
//TODO
|
||||
|
//添加方便链式调用的构造方法,类似builder
|
||||
|
|
||||
|
@Data |
||||
|
@ApiModel("接收消息者") |
||||
|
public static class To{ |
||||
|
private Long id; |
||||
|
|
||||
|
public To() { |
||||
|
} |
||||
|
public To(Long id) { |
||||
|
this.id = id; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 将userids列表转成tos格式 |
||||
|
* @param userIds |
||||
|
* @return |
||||
|
*/ |
||||
|
public static Set<String> transTos(List<Long> userIds) { |
||||
|
|
||||
|
Set<String> sets = new HashSet<>(); |
||||
|
if (CollectionUtil.isEmpty(userIds)) { |
||||
|
return sets; |
||||
|
} |
||||
|
userIds.forEach(userId -> { |
||||
|
To to = new To(userId); |
||||
|
sets.add(JSONObject.toJSONString(to)); |
||||
|
}); |
||||
|
return sets; |
||||
|
} |
||||
|
} |
||||
|
|||||
Loading…
Reference in new issue