private bool SubscribeToPubSub(IBPubSubServiceInterface _PubSub, Action <string> _ErrorMessageAction = null) { return(_PubSub.CustomSubscribe("models", (Message, Json) => { //make two copies so that writers don't interfere with each other try { byte[] MessageBytes = Convert.FromBase64String(Json); MemoryStream InputStream = new MemoryStream(MessageBytes); MemoryStream OutputStream = new MemoryStream(); using (DeflateStream decompressionStream = new DeflateStream(InputStream, CompressionMode.Decompress)) { decompressionStream.CopyTo(OutputStream); } string DecompressedMessage = Encoding.UTF8.GetString(OutputStream.ToArray()); NodeMessage MessageReceived = JsonConvert.DeserializeObject <NodeMessage>(DecompressedMessage); AddMessage(MessageReceived, _ErrorMessageAction); } catch (Exception ex) { _ErrorMessageAction?.Invoke($"[{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fffff")}] {ex.Message}\n{ex.StackTrace}"); } })); }
public bool ReceiveSingleMessage(string _TopicName, Action <string, string> _OnMessageAction = null, Action <string> _ErrorMessageAction = null) { if (PubSubService == null) { return(false); } return(PubSubService.CustomSubscribe(_TopicName, _OnMessageAction, _ErrorMessageAction, true)); }