Exemple #1
0
        public async static Task CreateProducer(ILogger logger)
        {
            var connectionFactory = new HermesConnectionFactory(logger);

            var connection = await connectionFactory.ConnectAsync("127.0.0.1", 8087);

            var producer = connection.GetProducer <Guid, Payload>("client channel 1");

            producer.MessageSent += message => {
                Console.WriteLine($"The Message (key: {message.Key}) has been sent to HermesMQ channel {message.ChannelName}");
            };

            var i = 0;

            do
            {
                var payload = new Payload {
                    Data = $"message {i}"
                };
                var message = await producer.ProduceAsync(Guid.NewGuid(), payload);

                Console.WriteLine($"message {i++} sent");
            } while (Console.ReadKey().Key != ConsoleKey.Escape);

            connection.Dispose();
        }
Exemple #2
0
        public async static Task <IConnection> CreateConsumer(ILogger logger)
        {
            var connectionFactory = new HermesConnectionFactory(logger);

            var connection = await connectionFactory.ConnectAsync("127.0.0.1", 8087);

            var consumer = connection.GetConsumer <Guid, Payload>("client channel 1");

            consumer.MessageReceived += (channel, message) => {
                Console.WriteLine($"message {message.Value.Data} received");
            };

            _ = consumer.ConsumeAsync();

            return(connection);
        }