예제 #1
0
        private void SendCore(string message, int partition)
        {
            byte[] buffer = Encoding.UTF8.GetBytes(message);
            var    task   = KafkaProducerHelper._dic[_broker].ProduceAsync(_topic.ToString(), null, 0, 0, buffer, 0, buffer.Length, partition, false);

            task.ContinueWith(p =>
            {
                if (p.Result.Error.HasError)
                {
                    OnSendError.Invoke(p.Result);
                }
                else
                {
                    OnSendComplete.Invoke(p.Result);
                }
            });
        }
예제 #2
0
 private void SocketConn_SendError(SocketConn scktConn, Exception scktExp)
 {
     OnSendError?.Invoke(scktExp);
 }
예제 #3
0
 internal bool SendData(byte[] data)
 {
     if (data == null)
     {
         throw new ArgumentNullException("data");
     }
     try
     {
         m_SendMutex.WaitOne();
         if (Connected)
         {
             SocketError errorCode;
             int         bytesSent = m_Socket.Send(data, 0, data.Length, SocketFlags.None, out errorCode);
             if (errorCode != SocketError.Success)
             {
                 Trace(EventType.Exception,
                       "Socket send error {3}. ConnID: {0} Data.Length: {1} bytesSent: {2}",
                       ConnID,
                       data.Length,
                       bytesSent,
                       errorCode);
                 return(false);
             }
             if (bytesSent < data.Length)
             {
                 Trace(EventType.Exception,
                       "Not all data was putted on the socket buffer. ConnID: {0} Data.Length: {1} bytesSent: {2}",
                       ConnID,
                       data.Length,
                       bytesSent);
                 return(false);
             }
             Trace(EventType.Full,
                   "Socket data sent. ConnID: {0} Length: {1} byte(s)",
                   ConnID,
                   data.Length);
             return(true);
         }
         else
         {
             Trace(EventType.Exception,
                   "Can't send socket data on disconnected connections. ConnID: {0}",
                   ConnID);
             return(false);
         }
     }
     catch (Exception e)
     {
         Trace(EventType.Error,
               "Exception sending socket data for ConnID {0}",
               ConnID);
         try { OnSendError?.Invoke(this, e); }
         catch (Exception exc) { Trace(exc); }
         try
         {
             Trace(EventType.Error,
                   "Starting socket connection closing because of sending error: {0}",
                   ConnID);
             Close();
         }
         catch (Exception exc) { Trace(exc); }
         return(false);
     }
     finally
     {
         m_SendMutex.ReleaseMutex();
     }
 }