public void when_write_and_read_envelope() { var serializer = new TestMessageSerializer(new[] { typeof(SerializerTest1), typeof(SerializerTest2), }); var streamer = new EnvelopeStreamer(serializer); var date = DateTime.UtcNow; var savedBytes = streamer.SaveEnvelopeData(new ImmutableEnvelope("EnvId", date, new SerializerTest1 { Name = "Test1" }, new[] { new MessageAttribute("key1", "val1"), new MessageAttribute("key2", "val2"), })); var envelope = streamer.ReadAsEnvelopeData(savedBytes); Assert.AreEqual("EnvId", envelope.EnvelopeId); Assert.AreEqual(date, envelope.CreatedUtc); Assert.AreEqual(2, envelope.Attributes.Count); Assert.AreEqual("key1", envelope.Attributes.ToArray()[0].Key); Assert.AreEqual("val1", envelope.Attributes.ToArray()[0].Value); Assert.AreEqual("key2", envelope.Attributes.ToArray()[1].Key); Assert.AreEqual("val2", envelope.Attributes.ToArray()[1].Value); Assert.AreEqual(typeof(SerializerTest1), envelope.Message.GetType()); Assert.AreEqual("Test1", (envelope.Message as SerializerTest1).Name); }
Action <ImmutableEnvelope> MakeRouter(MessageStore tape) { var entities = CreateQueueWriter(AggregateHandlerQueue); var processing = _serviceQueues.Select(CreateQueueWriter).ToArray(); return(envelope => { var message = envelope.Message; if (message is ICommand) { // all commands are recorded to audit stream, as they go through router tape.RecordMessage("audit", envelope); } if (message is IEvent) { throw new InvalidOperationException("Events are not expected in command router queue"); } var data = Streamer.SaveEnvelopeData(envelope); if (message is ICommand <IIdentity> ) { entities.PutMessage(data); return; } if (message is IFuncCommand) { // randomly distribute between queues var i = Environment.TickCount % processing.Length; processing[i].PutMessage(data); return; } throw new InvalidOperationException("Unknown message format"); }); }