public bool Publish(string topic, ISocketData sendDto) { if (string.IsNullOrWhiteSpace(topic)) { throw new ArgumentNullException(topic); } try { var sendVal = JsonConvert.SerializeObject(sendDto); sendVal = topic + "/" + sendVal; var valBytes = Encoding.UTF8.GetBytes(sendVal); // var isSend = PublisherSocket.SendMoreFrame(topic).TrySendFrameBytes(sendVal); var isSend = PublisherSocket.TrySendFrameBytes(sendVal); if (isSend) { LogWrite.Error("[发布消息]消息已广播出去:" + sendVal); } return(isSend); } catch (Exception e) { LogWrite.Error(e); return(false); } }
//public ConcurrentQueue<> public bool Publish(string topic, ISocketData sendDto) { var result = _netMQManage.Publish(topic, sendDto); _publisherListens.AddListens(topic, sendDto); return(result); }
/// <summary> /// Sends a content to the remote host /// </summary> /// <param name="socketData"></param> public async Task<int> SendAsync(ISocketData socketData) { byte[] data = socketData.Data.ToArray(); logger.DebugFormat("Sending {0} bytes to remote host", data.Length); return await Task.Factory .FromAsync( (callback, state) => socket.BeginSend(data, 0, data.Length, SocketFlags.None, callback, state), ias => socket.EndSend(ias), null); }
/// <summary> /// Receive commands /// </summary> /// <param name="obj"></param> private void IterativeReceiveCommandsFromServer(ISocketData obj) { var command = obj as CommandDto; ExecuteCommand(command); }
public static void AddListens(this List <PublisherListen> listens, string topic, ISocketData sendDto) { //记录发送对象 var first = listens.FirstOrDefault(b => b.Id == sendDto.Id); if (first == null) { listens.Add(new PublisherListen() { Id = sendDto.Id, SendCount = 1, SendData = sendDto, SendDate = DateTime.Now, Topic = topic }); } else { first.SendCount += 1; first.SendDate = DateTime.Now; } }
protected void OnReceiveSubscriberEvent(ISocketData receiveDto) { OnReceiveSubscriber?.Invoke(receiveDto); }