public override void Connect() { base.Connect(); // If it's the first access for the user, we send the added meta message if (FirstAccess) { SendMetaMessage(MetaState.Added); } // Now send a meta message, that the user is online SendMetaMessage(MetaState.Online); // Declare the queue for the user var queue = GroupChat.SharedSecret.GroupChatName + "." + GroupChat.ChatMember; Model.QueueDeclare(queue, true, false, false, null); var consumer = new EventingBasicConsumer(Model); consumer.Received += (obj, ea) => { var message = BinaryFormatter <ChatMessage> .FromBinary(ea.Body); // Proof that receiver is not the sender if (message.Sender == GroupChat.ChatMember) { return; } // Decrypt the message if (message.IsEncrypted) { message = GroupChat.Decrypt(message); } // if Message can't decrypted (due to wrong shared key etc) if (message == null) { return; } // Check, if the plain text is a json meta object var parsedJsonObject = JObject.Parse(message.PlainText); if (parsedJsonObject.IsValid(MetaMessageSchema)) { var metaMessage = JsonConvert.DeserializeObject <MetaMessage>(message.PlainText); OnMetaMessageReceived?.Invoke(GroupChat.ChatMember, message.Sender, metaMessage); } else if (parsedJsonObject.IsValid(ContentMessageSchema)) { var contentMessage = JsonConvert.DeserializeObject <TMessageObject>(message.PlainText); OnMessageReceived?.Invoke(GroupChat.ChatMember, message.Sender, contentMessage); } }; Model.QueueBind(queue, "amq.fanout", GroupChat.SharedSecret.GroupChatName, null); Model.BasicConsume(queue, true, string.Empty, false, true, null, consumer); }