public void Ready(PipeHandler worker) { Contract contract = new Contract { Command = MessageTypeEnum.Ready }; worker.Send(contract); }
protected void SendFinish(PipeHandler worker) { Contract end = new Contract { Command = MessageTypeEnum.End }; var json = JsonHelper.Serialize(end); worker.Send(json); }
protected int ReceiveMsg(PipeHandler worker, ChainwayMQConfig config, bool stop = false) { int count = 0; while (true) { if (stop) { break; } string json = worker.Receive(120); if (string.IsNullOrEmpty(json)) { throw new TimeoutException("接收主机信息超时"); } Contract data = JsonHelper.Deserialize <Contract>(json); switch (data.Command) { case MessageTypeEnum.Work: Contract result = new Contract(); try { ChainwayProducer producer = GetProducer(config.Group, config.Address); foreach (var t in config.Topic) { ChainwayMessage msg = new ChainwayMessage(t); msg.setKeys(data.Keys); msg.setTags(data.Tags); msg.Body = data.Data; producer.send(msg); count++; _logger.Debug(string.Format("表{0}成功推送1条数据到消息队列,json:{1}", data.Keys, data.Data)); } result.Command = MessageTypeEnum.OK; } catch (Exception ex) { result.Command = MessageTypeEnum.Error; result.Message = ex.Message; _logger.WriteException(ex); } worker.Send(result); break; case MessageTypeEnum.End: return(count); } } return(count); }
protected Contract SendMessage(string group, Contract contract, PipeWorker worker) { string json = JsonHelper.Serialize(contract); var config = MQFactory.Consumerconfig.Find(t => t.Group.Equals(group)); PipeHandler handler = new PipeHandler(worker.Pipe); handler.Send(json); var responseString = handler.Receive(30); if (string.IsNullOrEmpty(responseString)) { throw new TimeoutException("接收消费回执超时"); } var response = JsonHelper.Deserialize <Contract>(responseString); return(response); }
public override void SendData(Contract data, object sender) { PipeHandler handler = sender as PipeHandler; handler.Send(data); }