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