/// <summary> /// Serializes a message, opens a channel and publishes the message asynchronously. /// </summary> public override void SendMessage(IDistributedMessage message) { if (message == null) { SnTrace.Messaging.WriteError("RMQ: Security: Empty message."); return; } // This has to be set before sending the message so that receivers // can decide whether they should process it or not. message.MessageSent = DateTime.UtcNow; byte[] body; try { using (var messageStream = SerializeMessage(message)) { if (messageStream is MemoryStream ms) { body = ms.ToArray(); } else { using (var memoryStream = new MemoryStream()) { messageStream?.CopyTo(memoryStream); body = memoryStream.ToArray(); } } } } catch (Exception ex) { SnLog.WriteException(ex, "Error during security message serialization."); return; } Task.Run(() => { // Create a channel per send request to avoid sharing channels // between threads and be able to dispose the object. try { using (var channel = OpenChannel(Connection)) { channel.BasicPublish(MessageExchange, string.Empty, null, body); channel.Close(); } } catch (Exception ex) { SnLog.WriteException(ex, "Security message SEND ERROR", EventId.Messaging); SnTrace.Messaging.WriteError($"Security message SEND ERROR {ex.Message}"); OnSendException(message, ex); } }).ConfigureAwait(false); }
public override void SendMessage(IDistributedMessage message) { // This has to be set before sending the message so that receivers // can decide whether they should process it or not. message.MessageSent = DateTime.UtcNow; var stream = (MemoryStream)SerializeMessage(message); var buffer = stream.GetBuffer(); _messageQueue.Enqueue(buffer); }
/* ============================================================================== Send */ public void SendMessage(IDistributedMessage message) { try { message.MessageSent = DateTime.UtcNow; Stream messageStream = SerializeMessage(message); InternalSend(messageStream); } catch (Exception e) { SnLog.WriteException(e, EventMessage.Errors.SendError, EventId.Messaging); OnSendException(message, e); } }
/* ============================================================================== Error handling */ private void OnSendException(IDistributedMessage message, Exception exception) { SendException?.Invoke(this, new ExceptionEventArgs(exception, message)); }
public void SendMessage(IDistributedMessage message) { SnLog.WriteInformation("Send: " + message.GetType().Name); MessageReceived?.Invoke(this, new MessageReceivedEventArgs(message)); }
/// <inheritdoc /> public abstract void SendMessage(IDistributedMessage message);
/// <summary> /// Initializes a new instance of the ExceptionEventArgs /// </summary> public ExceptionEventArgs(Exception exception, IDistributedMessage message) { Exception = exception; Message = message; }
/// <summary> /// Initializes a new instance of the MessageReceivedEventArgs /// </summary> public MessageReceivedEventArgs(IDistributedMessage message) { Message = message; }
/// <summary> /// Sends the passed message to all other AppDomains. /// </summary> public void SendMessage(IDistributedMessage message) /* do nothing */ }