コード例 #1
0
 public void ProduceMessageString(string queueName, string message)
 {
     using (var connection = _messageQueueServer.CreateServer())
     {
         using (var channel = connection.CreateModel())
         {
             channel.QueueDeclare(queueName, false, false, false, null);
             channel.BasicPublish("", queueName, null, Encoding.UTF8.GetBytes(message));
         }
     }
 }
コード例 #2
0
        public string ConsumeMessages(string queueName)
        {
            BasicGetResult data;

            using (var connection = _messageQueueServer.CreateServer())
                using (var channel = connection.CreateModel())
                {
                    channel.QueueDeclare(queueName, false, false, false, null);
                    data = channel.BasicGet(queueName, true);
                }

            return(data != null?Encoding.UTF8.GetString(data.Body) : null);
        }