// ReSharper disable InconsistentNaming static void TestConfiguration(IQueueWriter sender, CqrsEngineBuilder builder) { int i = 0; using (var t = new CancellationTokenSource()) using (TestObserver.When <MessageAcked>(ea => { if (ea.Context.QueueName != "do") { return; } if (i++ >= 5) { t.Cancel(); } })) using (var engine = builder.Build()) { engine.Start(t.Token); sender.PutMessage(new byte[1]); if (!t.Token.WaitHandle.WaitOne(5000)) { t.Cancel(); } Assert.IsTrue(t.IsCancellationRequested); } }
public void Send(object message, string envelopeId, params MessageAttribute[] attributes) { var envelope = new ImmutableEnvelope(envelopeId, DateTime.UtcNow, message, attributes); var data = _streamer.SaveEnvelopeData(envelope); _queue.PutMessage(data); SystemObserver.Notify(new EnvelopeSent( _queue.Name, envelope.EnvelopeId, envelope.Message.GetType().Name, envelope.Attributes)); }
void PublishEvents(IIdentity id, Applied then) { var arVersion = then.Version + 1; var arName = IdentityConvert.ToTransportable(id); var name = String.Format("{0}-{1}", arName, arVersion); var builder = new EnvelopeBuilder(name); builder.AddString("entity", arName); foreach (var @event in then.Events) { builder.AddItem((object)@event); } _writer.PutMessage(_streamer.SaveEnvelopeData(builder.Build())); }
public void DelaySendBatch(string queueName, TimeSpan timeout, params IMessage[] messages) { var id = Guid.NewGuid().ToString().ToLowerInvariant(); DateTimeOffset offset = DateTimeOffset.UtcNow; if (timeout != default(TimeSpan)) { offset = DateTimeOffset.UtcNow + timeout; } foreach (var msg in messages) { var envelope = CreateMessageEnvelope(msg, queueName, offset); _queueWriter.PutMessage(envelope); } }
void SendMessage(object command, string optionalId) { var auth = FormsAuth.GetSessionIdentityFromRequest(); var envelopeId = optionalId ?? Guid.NewGuid().ToString().ToLowerInvariant(); var eb = new EnvelopeBuilder(envelopeId); if (auth.HasValue) { eb.AddString("web-user", auth.Value.User.Id.ToString(CultureInfo.InvariantCulture)); eb.AddString("web-token", auth.Value.Token); } eb.AddItem(command); _writer.PutMessage(_streamer.SaveEnvelopeData(eb.Build())); }
public override void Handle(IHttpContext context) { var msg = new EnvelopeBuilder(Guid.NewGuid().ToString()); var contract = context.GetRequestUrl().Remove(0, "/send/".Length); Type contractType; if (!_serializer.TryGetContractTypeByName(contract, out contractType)) { context.WriteString(string.Format("Trying to post command with unknown contract '{0}'.", contract)); context.SetStatusTo(HttpStatusCode.BadRequest); return; } _writer.PutMessage(_streamer.SaveEnvelopeData(msg.Build())); context.WriteString(string.Format(@" Normally this should be a JSON POST, containing serialized data for {0} but let's pretend that you successfully sent a message. Or routed it", contractType)); context.SetStatusTo(HttpStatusCode.OK); }
public override void Handle(IHttpContext context) { var contract = context.GetRequestUrl().Remove(0, "/mouseevents/".Length); var envelopeBuilder = new EnvelopeBuilder(contract + " - " + DateTime.Now.Ticks.ToString()); Type contractType; if (!_serializer.TryGetContractTypeByName(contract, out contractType)) { context.WriteString(string.Format("Trying to post command with unknown contract '{0}'.", contract)); context.SetStatusTo(HttpStatusCode.BadRequest); return; } var decodedData = HttpUtility.UrlDecode(context.Request.QueryString.ToString()); var mouseEvent = JsonSerializer.DeserializeFromString(decodedData, contractType); envelopeBuilder.AddItem(mouseEvent); _writer.PutMessage(_streamer.SaveEnvelopeData(envelopeBuilder.Build())); context.SetStatusTo(HttpStatusCode.OK); }
// ReSharper disable InconsistentNaming static void TestConfiguration(IQueueWriter sender, RawEngineBuilder builder) { int i = 0; using (var t = new CancellationTokenSource()) using (TestObserver.When<MessageAcked>(ea => { if (ea.Context.QueueName != "do") return; if (i++ >= 5) t.Cancel(); })) using (var engine = builder.Build()) { engine.Start(t.Token); sender.PutMessage(new byte[1]); if (!t.Token.WaitHandle.WaitOne(5000)) { t.Cancel(); } Assert.IsTrue(t.IsCancellationRequested); } }