private static void SendMultipleMessages(IRpcQueue <TTResponse, TTMessage> queue, int number) { //send a bunch of messages var numberOfJobs = number; var jobs = Enumerable.Range(0, numberOfJobs) .Select(i => new TTMessage()); 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"); } }); }
/// <summary> /// Sends the specified linqExpression for execution. /// </summary> /// <param name="method">The linqExpression.</param> /// <param name="timeOut">The time out.</param> /// <param name="data">The data.</param> /// <returns></returns> /// <remarks> /// Your expression must return a type of object, or the JSON serializer may throw casting errors /// </remarks> public IReceivedMessage <object> Send(Expression <Func <IReceivedMessage <MessageExpression>, IWorkerNotification, object> > method, TimeSpan timeOut, IAdditionalMessageData data = null) { var message = new MessageExpression(MessageExpressionPayloads.Function, _serializer.ConvertFunctionToBytes(method)); return(_queue.Send(message, timeOut, data)); }