/// <summary> /// Stores the message with the given headers and body data, delaying it until the specified <paramref name="approximateDueTime"/> /// </summary> public Task Defer(DateTimeOffset approximateDueTime, Dictionary <string, string> headers, byte[] body) { if (headers == null) { throw new ArgumentNullException(nameof(headers)); } if (body == null) { throw new ArgumentNullException(nameof(body)); } lock (_deferredMessages) { var @new = new DeferredMessage(approximateDueTime, headers, body); var added = _deferredMessages .AddOrUpdate(headers.GetValue(Headers.MessageId), id => @new, (id, existing) => existing); if (added == @new) { Interlocked.Increment(ref DueCount); } } return(Task.CompletedTask); }
static void DeferMessage(IBus bus) { DeferredMessage message = new DeferredMessage(); SendOptions sendOptions = new SendOptions(); sendOptions.RouteToLocalEndpointInstance(); sendOptions.DelayDeliveryWith(TimeSpan.FromSeconds(10)); bus.Send(message, sendOptions); Console.WriteLine(); Console.WriteLine("{0} - {1}", DateTime.Now.ToLongTimeString(), "Sent a message that is deferred for 10 seconds"); }
static void DeferMessage(IBus bus) { DeferredMessage message = new DeferredMessage(); SendOptions sendOptions = new SendOptions(); sendOptions.RouteToLocalEndpointInstance(); sendOptions.DelayDeliveryWith(TimeSpan.FromSeconds(10)); bus.Send(message, sendOptions); Console.WriteLine(); Console.WriteLine("{0} - {1}", DateTime.Now.ToLongTimeString(), "Sent a message that is deferred for 10 seconds"); }
static void Main() { // using var で、変数のスコープに紐づいた using になる。 // スコープを抜けるときに Dispose が呼ばれる。 using var a = new DeferredMessage("a"); using var b = new DeferredMessage("b"); Console.WriteLine("c"); // c, b, a の順でメッセージが表示される }
public void Add(DeferredMessage message) { _repository.Save(message); }
public DeferredMessage Get(Guid id) { DeferredMessage msg = _repository.Get <DeferredMessage>(id); return(msg); }
public void Add(DeferredMessage message) { _repository.Save(message); }
public void Add(DeferredMessage message) { lock (_messages) _messages.Add(message.Id, message); }
public void Handle(DeferredMessage message) { Data.GotTheDeferredMessage = true; }