Пример #1
0
        public static async Task <RpcHelper> Create(Channel channel, int maxConcurrentCalls, ConsumeMode mode, int?timeoutInMs)
        {
            var instance = new RpcHelper(channel, maxConcurrentCalls, mode, timeoutInMs);
            await instance.Setup().ConfigureAwait(false);

            return(instance);
        }
Пример #2
0
        public static async Task <RpcHelper> Create(Channel channel, int maxConcurrentCalls, ConsumeMode mode,
                                                    bool captureContext = false, int?timeoutInMs = null)
        {
            var instance = new RpcHelper(channel, maxConcurrentCalls, mode, timeoutInMs)
            {
                CaptureContext = captureContext
            };
            await instance.Setup().ConfigureAwait(captureContext);

            return(instance);
        }
Пример #3
0
        public Task <RpcHelper> CreateRpcHelper(ConsumeMode mode, int?timeoutInMs, int maxConcurrentCalls, bool captureContext)
        {
            EnsureOpen();

            if (_confirmationKeeper != null)
            {
                throw new Exception("This channel is set up for confirmations");
            }

            return(RpcHelper.Create(this, maxConcurrentCalls, mode, captureContext, timeoutInMs));
        }
Пример #4
0
        public async Task <RpcHelper> CreateRpcHelper(ConsumeMode mode, int maxConcurrentCalls = 500)
        {
            if (_confirmationKeeper != null)
            {
                throw new Exception("This channel is set up for confirmations");
            }

            var helper = new RpcHelper(this, maxConcurrentCalls, mode);
            await helper.Setup();

            return(helper);
        }
Пример #5
0
//		private static async Task StartConcurrentRpc()
//		{
//			Connection conn2 = null;
//			try
//			{
//				conn2 = await new ConnectionFactory().Connect(TargetHost,
//					vhost: VHost, username: _username, password: _password);
//
//				Console.WriteLine("[Connected]");
//
//				Console.WriteLine("Starting Rpc Parallel calls...");
//
//				var newChannel2 = await conn2.CreateChannel();
//				Console.WriteLine("[channel created] " + newChannel2.ChannelNumber);
//				await newChannel2.BasicQos(0, Prefetch, false);
//
//				var rpcHelper = await newChannel2.CreateRpcHelper(ConsumeMode.ParallelWithBufferCopy);
//
//				var watch = new Stopwatch();
//				watch.Start();
//
//				var totalReceived = 0;
//
//				
//				var tasks = new Task[ConcurrentCalls];
//
//				for (int i = 0; i < TotalPublish; i += ConcurrentCalls)
//				{
//					for (int j = 0; j < ConcurrentCalls; j++)
//					{
//						var t = MakeCall(rpcHelper, i + j);
//						tasks[j] = t;
//					}
//
//					Task.WaitAll(tasks);
//
//					totalReceived += ConcurrentCalls;
//
////					Console.WriteLine("calls " + totalReceived);
//
//					if (totalReceived >= TotalPublish)
//					{
//						watch.Stop();
//						Console.WriteLine("Rpc stress done. Took " +
//										  watch.Elapsed.TotalMilliseconds +
//										  "ms - rate of " + (TotalPublish / watch.Elapsed.TotalSeconds) + " messages per second");
//						totalReceived = 0;
//					}
//				}
//
//				await Task.Delay(TimeSpan.FromMinutes(5));
//
//				await newChannel2.Close();
//			}
//			catch (AggregateException ex)
//			{
//				Console.WriteLine("[Captured error] " + ex.Message);
//			}
//			catch (Exception ex)
//			{
//				Console.WriteLine("[Captured error 2] " + ex.Message);
//			}
//
//			if (conn2 != null)
//				conn2.Dispose();
//		}

		private static async Task<int> MakeCall(RpcHelper rpcHelper, int y)
		{
			var prop2 = new BasicProperties();
			var req = new byte[4];
			req[3] = (byte)((y & 0xFF000000) >> 24);
			req[2] = (byte)((y & 0x00FF0000) >> 16);
			req[1] = (byte)((y & 0x0000FF00) >> 8);
			req[0] = (byte)((y & 0x000000FF));

			var rpcCallResult = await rpcHelper.Call("test_ex", "rpc1", prop2, new ArraySegment<byte>(req, 0, 4));
			if (rpcCallResult.stream != null)
			{
				var reply = new byte[4];
				rpcCallResult.stream.Read(reply, 0, rpcCallResult.bodySize);
				var x = BitConverter.ToInt32(reply, 0);
				if (x != y) throw new Exception("Invalid result for call");
			}
//			else if (rpcCallResult.Body != null)
//			{
//				var x = BitConverter.ToInt32(rpcCallResult.Body, 0);
//				if (x != y) throw new Exception("Invalid result for call");
//			}

//			Console.WriteLine("Call " + y + " completed");

			return y;
		}
 public static Task <MessageDelivery> Call(this RpcHelper source, string exchange, string routing, BasicProperties properties, byte[] buffer)
 {
     return(source.Call(exchange, routing, properties, new ArraySegment <byte>(buffer)));
 }