public RPCClientService(RabbitMqConfig rabbitMqConfig) { _rabbitConfig = rabbitMqConfig; _factory = new ConnectionFactory(); _factory.UserName = _rabbitConfig.UserName; _factory.Password = _rabbitConfig.Password; _factory.VirtualHost = _rabbitConfig.VirtualHost; _connection = _factory.CreateConnection(_rabbitConfig.AmqpLists); _channel = _connection.CreateModel(); _consumer = new EventingBasicConsumer(_channel); _mqRespone = new MQRespone() { SerialNumber = Guid.NewGuid().ToString() }; }
static void Main(string[] args) { Console.WriteLine("【----等待发送消息----"); RabbitMqConfig mqConfig = new RabbitMqConfig(); mqConfig.AmqpLists = new List <RabbitMQ.Client.AmqpTcpEndpoint>() { new AmqpTcpEndpoint(new Uri("amqp://192.168.10.244:5672")) }; mqConfig.UserName = "******"; mqConfig.Password = "******"; mqConfig.VirtualHost = "/"; mqConfig.ExchangeName = "touchExchange"; mqConfig.RoutingKey = "touchRoutingKey"; mqConfig.ExchangeType = ExchangeTypeEnum.direct; mqConfig.DurableMessage = true; while (true) { RPCClientService clientService = new RPCClientService(mqConfig); Task <string> t = clientService.SendMsg(Console.ReadLine()); Console.WriteLine("----消息发送开始----"); if (!t.Wait(5000)) { Console.WriteLine("接收消息响应超时"); } else { MQRespone res = t.Result.ToString().ToObject <MQRespone>(); Console.WriteLine(string.Format("消息状态:{0},消息内容:{1},消息序列号:{2}", res.ResponeStatusEnum, res.Body.message, res.SerialNumber)); } clientService.Close(); Console.WriteLine("----消息发送结束----】"); Console.WriteLine(""); Console.WriteLine("【----等待发送消息----"); } }