private async Task RpcReturnChannelConsumerOnReceivedAsync(object sender, BasicDeliverEventArgs ea)
        {
            await Task.Delay(0);

            VerboseLoggingHandler.Log($"Event RpcReturnChannelConsumerOnReceivedAsync triggered Exchange='{ea.Exchange}', routingKeyOrTopicName='{ea.RoutingKey}', replyText='{ea.DeliveryTag}', consumerTag='{ea.ConsumerTag}'");
            ReturnData = ea.Body.ToArray();
            ReturnChannelLatch.Release(1);
        }
コード例 #2
0
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                DisposeChannel(Channel);
                DisposeChannel(ReturnChannel);
                DisposeChannel(ReturnChannel);

                ReturnChannelLatch?.Dispose();
            }

            _disposed = true;
コード例 #3
0
        private async Task <byte[]> SendMessageInternal(string routingKeyOrTopicName, byte[] message, IDictionary <string, object> headers, MessageType messageType, MessageParameters p = null)
        {
            if (EndpointType != EndpointTypeEnum.Publisher)
            {
                var e = new InvalidOperationException("Attempt to send a message on a consumer prohibited.");
                VerboseLoggingHandler.Log(e);
                throw e;
            }

            p ??= DefaultMessageParameters;
            if (string.IsNullOrEmpty(routingKeyOrTopicName))
            {
                routingKeyOrTopicName = RoutingKeyOrTopicName;
            }
            VerboseLoggingHandler.Log($"SendMessageInternal sending message, type='{messageType}', routingKeyOrTopicName='{routingKeyOrTopicName}', durable='{p.Durable}', mandatory='{p.Mandatory}', persistent='{p.Persistent}', priority='{p.Priority}', autoAck='{p.AutoAck}', resilient='{p.Resilient}', timeout='{p.TimeOut}' (ms)");
            headers ??= new Dictionary <string, object>();


            byte[] ret = null;

            var messageTypeText = new StringBuilder();

            var messageProperties = Channel.CreateBasicProperties();

            messageProperties.Type       = MessageTypeFragmentsChat;
            messageProperties.Timestamp  = AmqpTimestampNow;
            messageProperties.Priority   = p.Priority;
            messageProperties.Persistent = p.Persistent;
            messageProperties.Expiration = p.TimeOut.ToString();
            if (p.Durable)
            {
                messageProperties.DeliveryMode = 2;
            }

            messageProperties.CorrelationId = ConversationId.ToString();

            if (!p.AutoAck)
            {
                messageTypeText.Append((MessageTypeFragmentsRequestAmqAck));
            }

            if ((messageType & MessageType.RequireAck) == MessageType.RequireAck)
            {
                messageTypeText.Append(MessageTypeFragmentsRequestAck);
            }
            if ((messageType & MessageType.RequireResponse) == MessageType.RequireResponse)
            {
                messageTypeText.Append(MessageTypeFragmentsRequestReply);
            }
            headers.Add(DictionaryKey_PassedQueueTtl, ReturnChannelQueueTtl);

            messageProperties.Type    = messageTypeText.ToString();
            messageProperties.Headers = headers;

            try
            {
                ReturnData = null;
                messageProperties.ReplyTo = ReturnChannelQueueName;
                VerboseLoggingHandler.Log($"Publishing now");
                Channel.BasicPublish(ExchangeName, routingKeyOrTopicName, p.Mandatory, messageProperties, message);
                //_channel.WaitForConfirmsOrDie(new TimeSpan(0, 0, 0, 0, timeout.Value));
                if (((PublisherParameters)(ChannelParameters)).EnableConfirmSelect)
                {
                    try
                    {
                        Channel.WaitForConfirms();
                    }
                    catch (InvalidOperationException e1)
                    {
                        if (e1.Message == "Confirms not selected")
                        {
                            var e = new InvalidOperationException("Invalid configuration. WaitForConfirms behavior requested, but Exchange not configured for them.", e1);
                            VerboseLoggingHandler.Log(e);
                            throw e;
                        }
                        else
                        {
                            VerboseLoggingHandler.Log(e1);
                            throw e1;
                        }
                    }
                }

                if (messageType == MessageType.Normal)
                {
                    return(null);
                }

                VerboseLoggingHandler.Log($"Published. LatchCount='{ReturnChannelLatch.CurrentCount}', timeout='{p.TimeOut}' (ms)");
                await ReturnChannelLatch.WaitAsync(p.TimeOut, LocalCancellationToken);

                VerboseLoggingHandler.Log($"Released. LatchCount='{ReturnChannelLatch.CurrentCount}'");
            }
            finally
            {
                if (messageType != MessageType.Normal)
                {
                    VerboseLoggingHandler.Log($"Completed. LatchCount='{ReturnChannelLatch.CurrentCount}'");
                    ret = ReturnData;
                }
            }

            return(ret);
        }