我的Rabbit队列问题当前只对队列中的第一条消息做出反应,之后被忽略的任何其他消息都被忽略了.
我首先实例化连接并在IQueueConnectionProvider中声明队列:
var connectionFactory = new ConnectionFactory() { HostName = hostName }; var connection = _connectionFactory.CreateConnection(); var channel = connection.CreateModel();
然后IQueueConnectionProvider在我的IQueueListener中用作只有一个方法的依赖项:
public void ListenToQueue(string queue) { var channel = _queueConnectionProvider.GetQueue(); var consumer = new EventingBasicConsumer(channel); consumer.Received += (model, ea) => { string path = @"d:\debug.log.txt"; File.AppendAllLines(path, new List() {"MESSAGE RECEIVED", Environment.NewLine }); var body = ea.Body; var message = Encoding.UTF8.GetString(body); channel.BasicAck(ea.DeliveryTag, false); }; channel.BasicConsume(queue, true, consumer); }
我的日志文件最终只是一行"MESSAGE RECEIVED",但我可以在Rabbit ui界面看到我的其他服务正在将消息推送到该队列就好了.
这里有什么我想念的吗?