public static Message createMessage(ProtoMessage.Message protoMsg) throws Exception { Message m = new Message(); m.setMsgId(protoMsg.getMsgId()); m.setBody(protoMsg.getBody().getBytes()); m.setBornTime(protoMsg.getBornTime()); m.setFilter(protoMsg.getFilter()); m.setGroupId(protoMsg.getGroupId()); m.setMessageType(numToMsgType(protoMsg.getMessageType())); List<String> key = protoMsg.getPropertiesKeyList(); List<String> value = protoMsg.getPropertiesValueList(); if (key != null && !key.isEmpty()) { for (int i = 0; i < key.size(); i++) { m.setProperty(key.get(i), value.get(i)); } } m.setTopic(protoMsg.getTopic()); return m; }
public static ProtoMessage.Message createProtoMessage(Message m) { ProtoMessage.Message.Builder builder = ProtoMessage.Message.newBuilder(); builder.setMsgId(m.getMsgId()); builder.setTopic(m.getTopic()); builder.setBody(new String(m.getBody())); builder.setGroupId(m.getGroupId()); builder.setFilter(m.getFilter()); builder.setBornTime(m.getBornTime()); builder.setMessageType(m.getMessageType().ordinal()); Map<String, String> map = m.getPropMap(); if (map != null && !map.isEmpty()) { for (String key : map.keySet()) { builder.addPropertiesKey(key); builder.addPropertiesValue(map.get(key)); } } return builder.build(); }