/// <summary> /// Helper event handler. /// </summary> private void ReceiveReady(object sender, NetMQSocketEventArgs e) { try { // Receiving client message. var clientRequest = e.Socket.ReceiveMultipartMessage(); // Parsing client message. var clientAddress = clientRequest[0]; var clientRequestData = MessageQueueCommonItems.DeserializeFromJson <TRequest>(clientRequest[2].ConvertToString()); // Calling handler. OnRequestReady?.Invoke(new ZmqRequestMessage <TRequest, TResponse>(clientAddress, e.Socket, clientRequestData, ref logger)); } catch (QueueException queueException) { #region Logging - Error logger.Fatal(queueException, queueException.Message); #endregion } catch (Exception ex) { MessageQueueCommonItems.PrepareAndLogQueueException( errorCode: QueueErrorCode.FailedToReceiveRequestMessage, message: ErrorMessages.FailedToReceiveRequestMessage, innerException: ex, queueContext: CommonItems.ZeroMqName, address: zmqConfiguration.Address, logger: logger); } }
/// <summary> /// Helper event handler. /// </summary> private void ReceiveReady(object sender, BasicDeliverEventArgs request) { try { // Converting from Json bytes. var convertedMessage = MessageQueueCommonItems.DeserializeFromJsonBytes <TRequest>(request.Body); // Getting other required fields for response. var replyProperties = model.CreateBasicProperties(); replyProperties.CorrelationId = request.BasicProperties.CorrelationId; // Calling handler. OnRequestReady?.Invoke(new RmqRequestMessage <TRequest, TResponse>( model, replyProperties, rabbitMqConfiguration.ExchangeName ?? string.Empty, request.BasicProperties.ReplyTo, rabbitMqConfiguration.Acknowledgment, request.DeliveryTag, convertedMessage, ref logger)); } catch (QueueException queueException) { #region Logging - Error logger.Fatal(queueException, queueException.Message); #endregion } catch (Exception ex) { #region Adding Context Data var context = new Dictionary <string, string>(); if (!string.IsNullOrEmpty(rabbitMqConfiguration.ExchangeName)) { context.Add(CommonContextKeys.ExchangeName, rabbitMqConfiguration.ExchangeName); } if (!string.IsNullOrEmpty(rabbitMqConfiguration.RoutingKey)) { context.Add(CommonContextKeys.RoutingKey, rabbitMqConfiguration.RoutingKey); } #endregion MessageQueueCommonItems.PrepareAndLogQueueException( errorCode: QueueErrorCode.FailedToReceiveRequestMessage, message: ErrorMessages.FailedToReceiveRequestMessage, innerException: ex, queueContext: CommonItems.RabbitMqName, queueName: rabbitMqConfiguration.QueueName, address: rabbitMqConfiguration.Address, context: context, logger: logger); } }