Пример #1
0
        private static void SendMultipleMessages(IRpcMethodQueue queue, int number, Guid id, int runTime, LinqMethodTypes linqMethodTypes)
        {
            switch (linqMethodTypes)
            {
            case LinqMethodTypes.Compiled:
            {
                var numberOfJobs = number;
                var jobs         = Enumerable.Range(0, numberOfJobs)
                                   .Select(i => GenerateMethod.CreateRpcCompiled(id, runTime));
                SendMultipleMessages(queue, jobs);
            }
            break;

#if NETFULL
            case LinqMethodTypes.Dynamic:
            {
                var numberOfJobs = number;
                var jobs         = Enumerable.Range(0, numberOfJobs)
                                   .Select(i => GenerateMethod.CreateRpcDynamic(id, runTime));
                SendMultipleMessages(queue, jobs);
            }
            break;
#endif
            }
        }
Пример #2
0
 private static void SendMultipleMessages(IRpcMethodQueue queue,
                                          IEnumerable <LinqExpressionToRun> jobs)
 {
     Parallel.ForEach(jobs, job =>
     {
         try
         {
             var message = queue.Send(job, TimeSpan.FromSeconds(60));
             if (message == null)
             {
                 throw new DotNetWorkQueueException("The response timed out");
             }
             if (message.Body == null)
             { //RPC call failed
                 //do we have an exception?
                 var error =
                     message.GetHeader(queue.Configuration.HeaderNames.StandardHeaders.RpcConsumerException);
                 if (error != null)
                 {
                     throw new DotNetWorkQueueException("The consumer encountered an error trying to process our request");
                 }
                 throw new DotNetWorkQueueException("A null reply was received, but no error information was found. Examine the log to see if additional information can be found");
             }
         }
         catch (TimeoutException)
         {
             throw new DotNetWorkQueueException("The request has timed out");
         }
     });
 }
Пример #3
0
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
        private static async Task SendMultipleMessagesAsync(IRpcMethodQueue queue, IEnumerable <LinqExpressionToRun> jobs)
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
        {
            Parallel.ForEach(jobs, async job =>
            {
                try
                {
                    var message = await queue.SendAsync(job, TimeSpan.FromSeconds(60)).ConfigureAwait(false);
                    if (message == null)
                    {
                        throw new DotNetWorkQueueException("The response timed out");
                    }
                    if (message.Body == null)
                    { //RPC call failed
                        //do we have an exception?
                        var error =
                            message.GetHeader(queue.Configuration.HeaderNames.StandardHeaders.RpcConsumerException);
                        if (error != null)
                        {
                            throw new DotNetWorkQueueException("The consumer encountered an error trying to process our request");
                        }
                        throw new DotNetWorkQueueException("A null reply was received, but no error information was found. Examine the log to see if additional information can be found");
                    }
                }
                catch (TimeoutException)
                {
                    throw new DotNetWorkQueueException("The request has timed out");
                }
            });
        }