public void Failed(Message.Message.MessageType type) { var responseMessage = DispatchHandler.CreateResponseMessage(_requestMessage, type, _peerBeanMaster.ServerPeerAddress); _dispatcher.Respond(_ctx, responseMessage); }
/// <summary> /// Registers a DispatchHandler object. Implement and register individual handler methods for /// dispatchable object types you want to handle /// </summary> /// <param name="handleToRegister">DispatchHandler to register.</param> public void RegisterHandler(DispatchHandler handlerToRegister) { if (_handlers.Contains(handlerToRegister)) { // already registered, nothing to do return; } _handlers.Add(handlerToRegister); }
public void Failed_tasks_sleeps_and_retries() { var handler = new DispatchHandler(); var dispatcher = new UpdateRecordDispatcher(handler.Dispatch, 1, 1, 2.Seconds()); var firstAttempt = handler.AddCallback((d, r) => r.Throw(new Exception()), new Result<UpdateRecord>(5.Seconds())); var secondAttempt = handler.AddCallback((d, r) => { }, new Result<UpdateRecord>(5.Seconds())); dispatcher.Dispatch(new UpdateRecord(new XUri("mock://foo"), new XDoc("meta"), "default"), new Result()); Assert.IsFalse(firstAttempt.Block().HasException, "first attempt wasn't called"); var stopwatch = Stopwatch.StartNew(); Assert.IsFalse(secondAttempt.Block().HasException, "second attempt wasn't called"); stopwatch.Stop(); Assert.GreaterOrEqual(stopwatch.Elapsed, 2.Seconds(), string.Format("expected at least 2 second delay, took {0:0.00}s", stopwatch.Elapsed.TotalSeconds)); }
public void Dispatcher_retries_specified_times() { var handler = new DispatchHandler(); var dispatcher = new UpdateRecordDispatcher(handler.Dispatch, 1, 2, 0.Seconds()); var firstAttempt = handler.AddCallback((d, r) => r.Throw(new Exception()), new Result<UpdateRecord>(2.Seconds())); var secondAttempt = handler.AddCallback((d, r) => r.Throw(new Exception()), new Result<UpdateRecord>(2.Seconds())); var thirddAttempt = handler.AddCallback((d, r) => r.Throw(new Exception()), new Result<UpdateRecord>(2.Seconds())); var fourthAttempt = handler.AddCallback((d, r) => r.Throw(new Exception()), new Result<UpdateRecord>(5.Seconds())); dispatcher.Dispatch(new UpdateRecord(new XUri("mock://foo"), new XDoc("meta"), "default"), new Result()); Assert.IsFalse(firstAttempt.Block().HasException, "first attempt wasn't called"); Assert.IsFalse(secondAttempt.Block().HasException, "second attempt wasn't called"); Assert.IsFalse(thirddAttempt.Block().HasException, "third attempt wasn't called"); Assert.IsTrue(fourthAttempt.Block().HasException, "fourth attempt shouldn't have happened"); }
public async Task RunAsync([TimerTrigger("0 */5 * * * *", RunOnStartup = false)] TimerInfo myTimer, ILogger log) { //Add your new vendor integration factory method here Dictionary <string, Func <IDispatchVendor> > additionalDispatchCreatorStrategies = new Dictionary <string, Func <IDispatchVendor> > { { "SampleBulkSendVendor", () => new SampleBulkSendVendor() } }; //Pass necessary run-time settings here DispatchHandler dispatchHandler = new DispatchHandler(_dbConnectionString, _dbName, 5, additionalDispatchCreatorStrategies, "SparkPost", 10000); await dispatchHandler.ProcessMultipleMessage(myTimer.IsPastDue); }
public void Failed_task_sleep_does_not_block_next_task() { var handler = new DispatchHandler(); var dispatcher = new UpdateRecordDispatcher(handler.Dispatch, 1, 1, 2.Seconds()); var r1 = new UpdateRecord(new XUri("mock://foo"), new XDoc("meta"), "default"); var r2 = new UpdateRecord(new XUri("mock://foo"), new XDoc("meta"), "default"); var r1firstAttempt = handler.AddCallback((d, r) => r.Throw(new Exception()), new Result<UpdateRecord>(1.Seconds())); var r2firstAttempt = handler.AddCallback((d, r) => { }, new Result<UpdateRecord>(1.Seconds())); var r1SecondAttempt = handler.AddCallback((d, r) => { }, new Result<UpdateRecord>(5.Seconds())); dispatcher.Dispatch(r1, new Result()); dispatcher.Dispatch(r2, new Result()); Assert.IsFalse(r1firstAttempt.Block().HasException, "r1 first attempt wasn't called"); Assert.IsFalse(r1firstAttempt.Block().HasException, "r2 first attempt wasn't called"); Assert.IsFalse(r1SecondAttempt.Block().HasException, "r2 second attempt wasn't called"); }
public void Failed_tasks_sleeps_and_retries() { var handler = new DispatchHandler(); var dispatcher = new UpdateRecordDispatcher(handler.Dispatch, 1, 1, 2.Seconds()); var firstAttempt = handler.AddCallback((d, r) => r.Throw(new Exception()), new Result <UpdateRecord>(5.Seconds())); var secondAttempt = handler.AddCallback((d, r) => { }, new Result <UpdateRecord>(5.Seconds())); dispatcher.Dispatch(new UpdateRecord(new XUri("mock://foo"), new XDoc("meta"), "default"), new Result()); Assert.IsFalse(firstAttempt.Block().HasException, "first attempt wasn't called"); var stopwatch = Stopwatch.StartNew(); Assert.IsFalse(secondAttempt.Block().HasException, "second attempt wasn't called"); stopwatch.Stop(); Assert.GreaterOrEqual(stopwatch.Elapsed, 2.Seconds(), string.Format("expected at least 2 second delay, took {0:0.00}s", stopwatch.Elapsed.TotalSeconds)); }
public void Dispatcher_retries_specified_times() { var handler = new DispatchHandler(); var dispatcher = new UpdateRecordDispatcher(handler.Dispatch, 1, 2, 0.Seconds()); var firstAttempt = handler.AddCallback((d, r) => r.Throw(new Exception()), new Result <UpdateRecord>(2.Seconds())); var secondAttempt = handler.AddCallback((d, r) => r.Throw(new Exception()), new Result <UpdateRecord>(2.Seconds())); var thirddAttempt = handler.AddCallback((d, r) => r.Throw(new Exception()), new Result <UpdateRecord>(2.Seconds())); var fourthAttempt = handler.AddCallback((d, r) => r.Throw(new Exception()), new Result <UpdateRecord>(5.Seconds())); dispatcher.Dispatch(new UpdateRecord(new XUri("mock://foo"), new XDoc("meta"), "default"), new Result()); Assert.IsFalse(firstAttempt.Block().HasException, "first attempt wasn't called"); Assert.IsFalse(secondAttempt.Block().HasException, "second attempt wasn't called"); Assert.IsFalse(thirddAttempt.Block().HasException, "third attempt wasn't called"); Assert.IsTrue(fourthAttempt.Block().HasException, "fourth attempt shouldn't have happened"); }
public void Failed_task_sleep_does_not_block_next_task() { var handler = new DispatchHandler(); var dispatcher = new UpdateRecordDispatcher(handler.Dispatch, 1, 1, 2.Seconds()); var r1 = new UpdateRecord(new XUri("mock://foo"), new XDoc("meta"), "default"); var r2 = new UpdateRecord(new XUri("mock://foo"), new XDoc("meta"), "default"); var r1firstAttempt = handler.AddCallback((d, r) => r.Throw(new Exception()), new Result <UpdateRecord>(1.Seconds())); var r2firstAttempt = handler.AddCallback((d, r) => { }, new Result <UpdateRecord>(1.Seconds())); var r1SecondAttempt = handler.AddCallback((d, r) => { }, new Result <UpdateRecord>(5.Seconds())); dispatcher.Dispatch(r1, new Result()); dispatcher.Dispatch(r2, new Result()); Assert.IsFalse(r1firstAttempt.Block().HasException, "r1 first attempt wasn't called"); Assert.IsFalse(r1firstAttempt.Block().HasException, "r2 first attempt wasn't called"); Assert.IsFalse(r1SecondAttempt.Block().HasException, "r2 second attempt wasn't called"); }
public async Task RunAsync(SQSEvent evnt, ILambdaContext context) { List <Task> tasks = new List <Task>(); foreach (var message in evnt.Records) { //Add your new vendor integration factory method here Dictionary <string, Func <IDispatchVendor> > additionalDispatchCreatorStrategies = new Dictionary <string, Func <IDispatchVendor> > { { "SampleSingleSendVendor", () => new SampleSingleSendVendor() } }; //Pass necessary run-time settings here DispatchHandler dispatchHandler = new DispatchHandler(_dbConnectionString, _dbName, 5, additionalDispatchCreatorStrategies, string.Empty, int.MinValue); //extracting var base64decoded = Convert.FromBase64String(message.Body); var jsonString = Encoding.UTF8.GetString(base64decoded); QueueData queueData = JsonConvert.DeserializeObject <QueueData>(jsonString); tasks.Add(dispatchHandler.ProcessSingleMessage(queueData)); } await Task.WhenAll(tasks); }
/// <summary> /// Removes the handler from the system /// </summary> /// <param name="handler">DispatchHandler to remove</param> public void RemoveHandler(DispatchHandler handler) { _handlers.Remove(handler); }