public void OnNext(MessageEnvelope newMsg) { var incomingMsgProperties = newMsg.Properties; var replyQueue = incomingMsgProperties.ReplyTo; var correlationId = incomingMsgProperties.CorrelationId; IBasicProperties replyProperties = null; byte[] replyData = new byte[0]; var msgAcker = CreateAcker(newMsg); try { var response = _onRespond(newMsg, msgAcker); response = response ?? new MessageEnvelope(new BasicProperties(), new byte[0]); replyData = response.Body; replyProperties = response.Properties ?? new BasicProperties(); } catch (Exception e) { replyProperties = replyProperties ?? new BasicProperties(); if (LogAdapter.LogEnabled) { LogAdapter.LogError("Rpc", "OnNext error", e); } // Empty data if (_shouldSerializeExceptions) { replyData = _serializer.Serialize(new ErrorResponse() { Exception = e }, replyProperties); } ErrorResponse.FlagHeaders(replyProperties); } // which call is which replyProperties.CorrelationId = correlationId; // Rabbit client will explode if this is not true (replyProperties is RabbitMQ.Client.Impl.BasicProperties) .AssertIsTrue("expected BasicProperties implementation of IBasicProperties"); lock (_model) { _model.BasicPublish("", replyQueue, replyProperties, replyData); } }
private void OnProc() { try { while (!_closed) { var args = base.Queue.Dequeue(); if (args == null) { continue; } if (_consumers.Count == 0) { // throwing out messages due to lack of consumers if (LogAdapter.LogEnabled) { LogAdapter.LogDebug(this.GetType().FullName, "SharedQueueConsumer dropping message due to lack of consumers subscribed"); } continue; } PublishToConsumers(args); } } catch (Exception e) { if (LogAdapter.LogEnabled) { LogAdapter.LogError(this.GetType().FullName, "SharedQueueConsumer error ", e); } } }