コード例 #1
0
        public static void ReceiveMessage()
        {
            var configuration = Configuration.GetRabbitMqConfiguration();
            var messageBus    = new MessageBus(configuration);
            var connection    = messageBus.GetConnection();
            var channel       = connection.CreateModel();

            channel.QueueDeclare(queue: configuration.QueueName, durable: false, exclusive: false, autoDelete: false, arguments: null);
            var consumer = new EventingBasicConsumer(channel);

            consumer.Received += HandleMessage;
            channel.BasicConsume(queue: configuration.QueueName, autoAck: true, consumer: consumer);
        }
コード例 #2
0
        public static void Send(string name)
        {
            var message       = string.Format(Message, name);
            var configuration = Configuration.GetRabbitMqConfiguration();
            var messageBus    = new MessageBus(configuration);
            var connection    = messageBus.GetConnection();

            using (connection)
            {
                using var channel = connection.CreateModel();
                channel.QueueDeclare(configuration.QueueName, false, false, false, null);
                var body = Encoding.UTF8.GetBytes(message);
                channel.BasicPublish("", configuration.QueueName, null, body);
            }
        }