private void InitConsumer() { ConnectionFactory factory = new ConnectionFactory(); factory.Uri = connString; conn = factory.CreateConnection(); channel = conn.CreateModel(); channel.BasicQos(0, prefetchCount, false); buffer = new BufferQueue(); consumer = new EventingBasicConsumer(channel); channel.BasicConsume(queueName, false, consumer); // when message is recieved do following consumer.Received += (model, message) => { if (buffer.Count() > DEFAULT_ACK_COUNT) { Thread.Sleep(3000); } buffer.Enqueue(message); if (buffer.Count() == 0 || buffer.Count() == ackCount) { channel.BasicAck(message.DeliveryTag, true); } }; }
public bool Send(byte[] data) { if (_sock == null) { return(false); } if (data == null) { return(false); } BufferQueue.Enqueue(data); return(SendComputer()); }
public bool Send(byte[] data) { BufferQueue.Enqueue(data); if (!SendIng) { if (InitData()) { SendIng = true; sock.SendAsync(_send); return(true); } } return(false); }
public void EnqueueBufferQueue(int length, int index = 0) { if (index + length > BufferSize) { throw new Exception("超过Buffer长度"); } BufferQueue.Lock(); try { for (var i = index; i < length; i++) { BufferQueue.Enqueue(Buffer[i], true); } } catch { } BufferQueue.UnLock(); BufferQueue.EnqueueEvent.Set(); }
public int readMore() { int size = 0; try { int available = _uSocket.Available; Byte[] buff; if (available > 0) { buff = new Byte[available]; size = _uSocket.ReceiveFrom(buff, 0, available, SocketFlags.None, ref _remoteEP); } else { buff = _tempRecvBuffer; //available이 0일때는 다음에 도착할 header를 기다린다. _uSocket.Blocking = true; size = _uSocket.ReceiveFrom(buff, ref _remoteEP); } if (size > 0) { if (size == buff.Length) { _queue.Enqueue(buff); } else { _queue.enqueueFrom(buff, 0, size); } } return(size); } catch (Exception e) { Console.WriteLine("socket exception" + e.ToString()); return(-1); } }
internal void Append(char[] buffer, int offset, int size) { BufferQueue.Enqueue(new Buffer(buffer, offset, size)); }