static async Task Start(IBusSession busSession) { Console.WriteLine("Press '1' to publish IEvent"); Console.WriteLine("Press '2' to publish EventMessage"); Console.WriteLine("Press '3' to publish AnotherEventMessage"); Console.WriteLine("Press 'Enter' to publish a message.To exit, Ctrl + C"); #region PublishLoop while (true) { ConsoleKeyInfo key = Console.ReadKey(); Console.WriteLine(); Guid eventId = Guid.NewGuid(); switch (key.Key) { case ConsoleKey.D1: await busSession.Publish <IMyEvent>(m => { m.EventId = eventId; m.Time = DateTime.Now.Second > 30 ? (DateTime?)DateTime.Now : null; m.Duration = TimeSpan.FromSeconds(99999D); }); Console.WriteLine("Published IMyEvent with Id {0}.", eventId); continue; case ConsoleKey.D2: EventMessage eventMessage = new EventMessage { EventId = eventId, Time = DateTime.Now.Second > 30 ? (DateTime?)DateTime.Now : null, Duration = TimeSpan.FromSeconds(99999D) }; await busSession.Publish(eventMessage); Console.WriteLine("Published EventMessage with Id {0}.", eventId); continue; case ConsoleKey.D3: AnotherEventMessage anotherEventMessage = new AnotherEventMessage { EventId = eventId, Time = DateTime.Now.Second > 30 ? (DateTime?)DateTime.Now : null, Duration = TimeSpan.FromSeconds(99999D) }; await busSession.Publish(anotherEventMessage); Console.WriteLine("Published AnotherEventMessage with Id {0}.", eventId); continue; default: return; } } #endregion }
static void Start(IBusSession busSession) { Console.WriteLine("Press '1' to publish IEvent"); Console.WriteLine("Press '2' to publish EventMessage"); Console.WriteLine("Press '3' to publish AnotherEventMessage"); Console.WriteLine("Press 'Enter' to publish a message.To exit, Ctrl + C"); #region PublishLoop while (true) { ConsoleKeyInfo key = Console.ReadKey(); Console.WriteLine(); Guid eventId = Guid.NewGuid(); switch (key.Key) { case ConsoleKey.D1: busSession.Publish<IMyEvent>(m => { m.EventId = eventId; m.Time = DateTime.Now.Second > 30 ? (DateTime?) DateTime.Now : null; m.Duration = TimeSpan.FromSeconds(99999D); }); Console.WriteLine("Published IMyEvent with Id {0}.", eventId); continue; case ConsoleKey.D2: EventMessage eventMessage = new EventMessage { EventId = eventId, Time = DateTime.Now.Second > 30 ? (DateTime?) DateTime.Now : null, Duration = TimeSpan.FromSeconds(99999D) }; busSession.Publish(eventMessage); Console.WriteLine("Published EventMessage with Id {0}.", eventId); continue; case ConsoleKey.D3: AnotherEventMessage anotherEventMessage = new AnotherEventMessage { EventId = eventId, Time = DateTime.Now.Second > 30 ? (DateTime?) DateTime.Now : null, Duration = TimeSpan.FromSeconds(99999D) }; busSession.Publish(anotherEventMessage); Console.WriteLine("Published AnotherEventMessage with Id {0}.", eventId); continue; default: return; } } #endregion }
/// <summary> /// Instantiates a message of type T and publishes it. /// </summary> /// <typeparam name="T">The type of message, usually an interface.</typeparam> /// <param name="session">The instance of <see cref="IBusSession" /> to use for the action.</param> /// <param name="messageConstructor">An action which initializes properties of the message.</param> public static Task Publish <T>(this IBusSession session, Action <T> messageConstructor) { Guard.AgainstNull(nameof(session), session); Guard.AgainstNull(nameof(messageConstructor), messageConstructor); return(session.Publish(messageConstructor, new PublishOptions())); }
/// <summary> /// Publish the message to subscribers. /// </summary> /// <param name="session">The instance of <see cref="IBusSession" /> to use for the action.</param> /// <param name="message">The message to publish.</param> public static Task Publish(this IBusSession session, object message) { Guard.AgainstNull(nameof(session), session); Guard.AgainstNull(nameof(message), message); return(session.Publish(message, new PublishOptions())); }
public async Task Handle(DemoMessage message, IMessageHandlerContext context) { Console.WriteLine($"Received {nameof(DemoMessage)}"); await session.Publish(new DemoEvent()); await demoServiceA.PublishEvent(); await demoServiceB.PublishEvent(); }
static async Task PublishEvent(IBusSession busSession) { Guid eventId = Guid.NewGuid(); await busSession.Publish <IMyEvent>(m => { m.EventId = eventId; }); Console.WriteLine("Event published, id: " + eventId); }
static async Task PublishEvent(IBusSession busSession) { Guid eventId = Guid.NewGuid(); await busSession.Publish<IMyEvent>(m => { m.EventId = eventId; }); Console.WriteLine("Event published, id: " + eventId); }
public async Task Publish() { #region publishAtStartup BusConfiguration busConfiguration = new BusConfiguration(); //Other config IEndpointInstance endpointInstance = await Endpoint.Start(busConfiguration); IBusSession busSession = endpointInstance.CreateBusSession(); await busSession.Publish(new MyEvent()); #endregion }
public Task PublishEvent() { return(session.Publish(new DemoEvent(), new PublishOptions())); }
/// <summary> /// Publish the message to subscribers. /// </summary> /// <param name="session">The instance of <see cref="IBusSession" /> to use for the action.</param> /// <typeparam name="T">The message type.</typeparam> public static Task Publish <T>(this IBusSession session) { Guard.AgainstNull(nameof(session), session); return(session.Publish <T>(_ => { }, new PublishOptions())); }