Exemplo n.º 1
0
    static void Start(IBusContext busContext)
    {
        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:
                busContext.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)
                };
                busContext.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)
                };
                busContext.Publish(anotherEventMessage);
                Console.WriteLine("Published AnotherEventMessage with Id {0}.", eventId);
                continue;

            default:
                return;
            }
        }
        #endregion
    }
Exemplo n.º 2
0
        public async Task InterfaceMessage()
        {
            IBusContext busContext = null;

            #region InterfacePublish
            await busContext.Publish <IMyEvent>(m => { m.SomeProperty = "Hello world"; });

            #endregion
        }
    static async Task PublishEvent(IBusContext busContext)
    {
        Guid eventId = Guid.NewGuid();

        await busContext.Publish <IMyEvent>(m =>
        {
            m.EventId = eventId;
        });

        Console.WriteLine("Event published, id: " + eventId);
    }
Exemplo n.º 4
0
        public async Task ConcreteMessage()
        {
            IBusContext busContext = null;

            #region InstancePublish
            MyEvent message = new MyEvent {
                SomeProperty = "Hello world"
            };
            await busContext.Publish(message);

            #endregion
        }
Exemplo n.º 5
0
    static async Task AsyncMain()
    {
        BusConfiguration busConfiguration = new BusConfiguration();

        busConfiguration.EndpointName("Samples.Versioning.V2Publisher");
        busConfiguration.UseSerialization <JsonSerializer>();
        busConfiguration.UsePersistence <InMemoryPersistence>();
        busConfiguration.UsePersistence <MsmqPersistence, StorageType.Subscriptions>();
        busConfiguration.EnableInstallers();
        busConfiguration.SendFailedMessagesTo("error");

        IEndpointInstance endpoint = await Endpoint.Start(busConfiguration);

        try
        {
            IBusContext busContext = endpoint.CreateBusContext();
            Console.WriteLine("Press enter to publish a message");
            Console.WriteLine("Press any key to exit");
            while (true)
            {
                ConsoleKeyInfo key = Console.ReadKey();
                Console.WriteLine();

                if (key.Key != ConsoleKey.Enter)
                {
                    return;
                }
                await busContext.Publish <V2.Messages.ISomethingHappened>(sh =>
                {
                    sh.SomeData = 1;
                    sh.MoreInfo = "It's a secret.";
                });

                Console.WriteLine("Published event.");
            }
        }
        finally
        {
            await endpoint.Stop();
        }
    }
Exemplo n.º 6
0
 public async Task Publish(object message) => await _context.Publish(message);