static void Main(string[] args) { Parallel.For(0, RabbitMQConfig.ThreadCount, i => { IMessageCustomer customer = new MessageCustomer("test"); customer.StartListening(); customer.ReceiveMessageCallback = message => { Console.WriteLine("接收到消息:" + message); return(true); }; }); Console.Read(); }
public IMessageCustomer CreateCustomer(string queueName) { IMessageCustomer customer; if (!Customers.ContainsKey(queueName)) { customer = new MessageCustomer(queueName); Customers.Add(queueName, customer); } else { customer = Customers[queueName]; } return(customer); }
static void Main(string[] args) { while (true) { IMessageCustomer customer = new MessageCustomer("test"); customer.StartListening(); customer.ReceiveMessageCallback = message => { Console.WriteLine("接收到消息:" + message); return(false); }; Thread.Sleep(2000); } Console.Read(); }