static async Task AsyncMain() { Console.Title = "Samples.Notifications"; #region logging DefaultFactory defaultFactory = LogManager.Use <DefaultFactory>(); defaultFactory.Level(LogLevel.Fatal); #endregion #region endpointConfig EndpointConfiguration endpointConfiguration = new EndpointConfiguration("Samples.Notifications"); SubscribeToNotifications.Subscribe(endpointConfiguration); #endregion endpointConfiguration.SendFailedMessagesTo("error"); endpointConfiguration.UseSerialization <JsonSerializer>(); endpointConfiguration.EnableInstallers(); endpointConfiguration.UsePersistence <InMemoryPersistence>(); IEndpointInstance endpoint = await Endpoint.Start(endpointConfiguration); try { await endpoint.SendLocal(new MyMessage()); Console.WriteLine("Press any key to exit"); Console.ReadKey(); } finally { await endpoint.Stop(); } }
static async Task AsyncMain() { Console.Title = "Samples.Notifications"; #region logging var defaultFactory = LogManager.Use <DefaultFactory>(); defaultFactory.Level(LogLevel.Fatal); #endregion #region endpointConfig var endpointConfiguration = new EndpointConfiguration("Samples.Notifications"); SubscribeToNotifications.Subscribe(endpointConfiguration); #endregion endpointConfiguration.SendFailedMessagesTo("error"); endpointConfiguration.UseSerialization <JsonSerializer>(); endpointConfiguration.EnableInstallers(); endpointConfiguration.UsePersistence <InMemoryPersistence>(); #region customDelayedRetries var recoverability = endpointConfiguration.Recoverability(); recoverability.Delayed( customizations: delayed => { delayed.TimeIncrease(TimeSpan.FromSeconds(1)); }); #endregion var endpointInstance = await Endpoint.Start(endpointConfiguration) .ConfigureAwait(false); try { var message = new MyMessage { Property = "PropertyValue" }; await endpointInstance.SendLocal(message) .ConfigureAwait(false); Console.WriteLine("Press any key to exit"); Console.ReadKey(); } finally { await endpointInstance.Stop() .ConfigureAwait(false); } }
static async Task Main() { //required to prevent possible occurrence of .NET Core issue https://github.com/dotnet/coreclr/issues/12668 Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Console.Title = "Samples.Notifications"; #region logging var defaultFactory = LogManager.Use <DefaultFactory>(); defaultFactory.Level(LogLevel.Fatal); #endregion #region endpointConfig var endpointConfiguration = new EndpointConfiguration("Samples.Notifications"); SubscribeToNotifications.Subscribe(endpointConfiguration); #endregion endpointConfiguration.UsePersistence <LearningPersistence>(); endpointConfiguration.UseTransport <LearningTransport>(); #region customDelayedRetries var recoverability = endpointConfiguration.Recoverability(); recoverability.Delayed( customizations: delayed => { delayed.TimeIncrease(TimeSpan.FromSeconds(1)); }); #endregion var endpointInstance = await Endpoint.Start(endpointConfiguration) .ConfigureAwait(false); var message = new MyMessage { Property = "PropertyValue" }; await endpointInstance.SendLocal(message) .ConfigureAwait(false); Console.WriteLine("Press any key to exit"); Console.ReadKey(); await endpointInstance.Stop() .ConfigureAwait(false); }
// using the approach where you explicitly define a handler. //public event SubscribeNotifyHandler SubscribeToNotifications; //public delegate void SubscribeNotifyHandler(object sender, MyCustomEventArgs args); /// <summary> /// Do some work and when done, raise a notification. /// </summary> /// <param name="str"></param> /// <returns></returns> public int DoSomeWork(string str) { for (int i = 0; i < 5; i++) { System.Threading.Thread.Sleep(2000); Console.WriteLine($"\nIn DoSomeWork(): Raising OnWorkEventRaiser({str})"); // raise the event which in turn will signal all the subscribers; can pass back // data in the CustomEventArgs SubscribeToNotifications?.Invoke(this, new MyCustomEventArgs("Responding to work done.")); } // raise completion event WorkCompleted?.Invoke(this, new MyCustomEventArgs("Work has finished.")); return(1); }
static async Task Main() { Console.Title = "Samples.Notifications"; #region logging var defaultFactory = LogManager.Use <DefaultFactory>(); defaultFactory.Level(LogLevel.Fatal); #endregion #region endpointConfig var endpointConfiguration = new EndpointConfiguration("Samples.Notifications"); SubscribeToNotifications.Subscribe(endpointConfiguration); #endregion endpointConfiguration.UsePersistence <LearningPersistence>(); endpointConfiguration.UseTransport <LearningTransport>(); #region customDelayedRetries var recoverability = endpointConfiguration.Recoverability(); recoverability.Delayed( customizations: delayed => { delayed.TimeIncrease(TimeSpan.FromSeconds(1)); }); #endregion var endpointInstance = await Endpoint.Start(endpointConfiguration) .ConfigureAwait(false); var message = new MyMessage { Property = "PropertyValue" }; await endpointInstance.SendLocal(message) .ConfigureAwait(false); Console.WriteLine("Press any key to exit"); Console.ReadKey(); await endpointInstance.Stop() .ConfigureAwait(false); }