// StoreMessage is a part of the `store.MessageStore` implementation. func (dms *DummyMessageStore) StoreMessage(message *protocol.Message, nodeID uint8) (int, error) { partitionName := message.Path.Partition() nextID, ts, err := dms.GenerateNextMsgID(partitionName, 0) if err != nil { return 0, err } message.ID = nextID message.Time = ts message.NodeID = nodeID data := message.Bytes() if err := dms.Store(partitionName, nextID, data); err != nil { return 0, err } return len(data), nil }
// StoreMessage is a part of the `store.MessageStore` implementation. func (fms *FileMessageStore) StoreMessage(message *protocol.Message, nodeID uint8) (int, error) { partitionName := message.Path.Partition() // If nodeID is zero means we are running in standalone more, otherwise // if the message has no nodeID it means it was received by this node if nodeID == 0 || message.NodeID == 0 { id, ts, err := fms.GenerateNextMsgID(partitionName, nodeID) if err != nil { logger.WithError(err).Error("Generation of id failed") return 0, err } message.ID = id message.Time = ts message.NodeID = nodeID log.WithFields(log.Fields{ "generatedID": id, "generatedTime": message.Time, }).Debug("Locally generated ID for message") } data := message.Bytes() if err := fms.Store(partitionName, message.ID, message.Bytes()); err != nil { logger. WithError(err).WithField("partition", partitionName). Error("Error storing locally generated messagein partition") return 0, err } logger.WithFields(log.Fields{ "id": message.ID, "ts": message.Time, "partition": partitionName, "messageUserID": message.UserID, "nodeID": nodeID, }).Debug("Stored message") return len(data), nil }