我的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<string>() {"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界面看到我的其他服务正在将消息推送到该队列就好了.
这里有什么我想念的吗?