public async void Handle(IncrementCounterWithAckCommand message) { //publish the event with some retries and a future expiry await _bus.PublishDurable(new CounterIncrementedWithAckEvent(), new RetryPolicy(3, TimeSpan.FromHours(1))); //now that event(s) are safely published, acknowledge the command await _bus.Acknowledge(message); }
public async Task UnacknowledgedEventWithNonExpiredRetryPolicyIsRetriedAcrossAdditionalStarts() { var @event = new TestDurableEvent(SingleValue); await _bus.PublishDurable(@event); Assume.That(_eventsThatWillBeAcknowledged.ProcessedMessagePayload, Is.EqualTo(SingleValue)); await _bus.Start(); Assert.That(_eventsThatWillBeAcknowledged.ProcessedMessagePayload, Is.EqualTo(string.Format("{0}{0}", SingleValue))); }
public async Task CommandAndEventAreRetriedOnNextStart() { await _bus.SendDurable(new TestDurableCommand(SingleValue)); await _bus.PublishDurable(new TestDurableEvent(SingleValue)); Assume.That(_commands.ProcessedMessagePayload, Is.EqualTo(SingleValue)); Assume.That(_events.ProcessedMessagePayload, Is.EqualTo(SingleValue)); await _bus.Start(); Assert.That(_commands.ProcessedMessagePayload, Is.EqualTo(_doubleValue)); Assert.That(_events.ProcessedMessagePayload, Is.EqualTo(_doubleValue)); }
public async Task CommandAndEventAreNotRetriedAcrossAdditionalStarts() { await _bus.SendDurable(new TestDurableCommand(SingleValue)); await _bus.PublishDurable(new TestDurableEvent(SingleValue)); Assume.That(_commands.ProcessedMessagePayload, Is.EqualTo(SingleValue)); Assume.That(_events.ProcessedMessagePayload, Is.EqualTo(SingleValue)); //despite multiple calls to Start(), messages are NOT retried at all as per the retry policy setting for (int i = 0; i < 10; i++) { await _bus.Start(); } Assert.That(_commands.ProcessedMessagePayload, Is.EqualTo(SingleValue)); Assert.That(_events.ProcessedMessagePayload, Is.EqualTo(SingleValue)); }
public async Task MessageIsNotSendToSubscriberOnStart() { const string singleValue = "0"; //we need a retry policy with at least one retry // so that we'd expect the call to Start() to attempt a retry var retryPolicy = new RetryPolicy(1, DateTimeUtility.PositiveOneHourTimeSpan); var bus = new DurableMessageBus(retryPolicy); var events = new EventSubscribers(); bus.RegisterSubscriptionFor <TestDurableEvent>(events.Handle); await bus.PublishDurable(new TestDurableEvent(singleValue)); Assume.That(events.ProcessedMessagePayload, Is.EqualTo(singleValue), "Event Subscriber didn't receive the expected message."); bus.UnRegisterAllSubscriptionsFor <TestDurableEvent>(); await bus.Start(); Assert.That(events.ProcessedMessagePayload, Is.EqualTo(singleValue), "Bus did not properly ignore queued event."); }
private async Task SendUnacknowledgedCommandAndEventTwiceThenDisposeDurableBus() { _doubleValue = string.Format("{0}{0}", SingleValue); _tripleValue = string.Format("{0}{0}{0}", SingleValue); _retryPolicy = new RetryPolicy(10, DateTimeUtility.PositiveOneHourTimeSpan); _bus = new DurableMessageBus(_retryPolicy); _commands = new DurableCommandSubscribers(); _events = new DurableEventSubscribers(); _bus.RegisterSubscriptionFor <TestDurableCommand>(_commands.Handle); _bus.RegisterSubscriptionFor <TestDurableEvent>(_events.Handle); await _bus.SendDurable(new TestDurableCommand(SingleValue)); await _bus.PublishDurable(new TestDurableEvent(SingleValue)); Assume.That(_commands.ProcessedMessagePayload, Is.EqualTo(SingleValue), "Command Subscriber not registered for command as expected."); Assume.That(_events.ProcessedMessagePayload, Is.EqualTo(SingleValue), "Event Subscriber not registered for event as expected."); await _bus.Start(); Assume.That(_commands.ProcessedMessagePayload, Is.EqualTo(_doubleValue), "Command Subscriber not registered for command as expected."); Assume.That(_events.ProcessedMessagePayload, Is.EqualTo(_doubleValue), "Event Subscriber not registered for event as expected."); await _bus.Stop(); _bus = null; Assume.That(_bus, Is.Null); }