예제 #1
0
		public void workerpool_distributes_items_to_workers()
		{
			var counter = 0;

			Action<byte[], IZmqSocket> proc = (data, socket) =>
			{
				Interlocked.Increment(ref counter);

				// var data = socket.Recv();
				Thread.Sleep(1); // preparing beverage
				socket.Send("done");
			};

			// Creates a wpool with 10 workers
			using (var pool = new WorkerPool(base.Context, "tcp://0.0.0.0:8000", "inproc://workerp1", proc, 10))
			{
				pool.Start();

				// Sends a 100 request for coffee
				// just like Monday 9am, at any starbucks
				for (int i = 0; i < 100; i++)
					using (var req = base.Context.Req())
					{
						req.Connect("tcp://127.0.0.1:8000");
						req.Send("Venti Mocha please!");
						var res = req.RecvString();
						Assert.AreEqual("done", res);
					}

				Assert.AreEqual(100, counter);
			}
		}
예제 #2
0
		public void Stop()
		{
			if (_workerPool != null)
			{
				_workerPool.Dispose();
				_workerPool = null;
			}
		}
예제 #3
0
		public void Start()
		{
			this.Stop();

			this._workerPool = new WorkerPool(this._context, 
											  this._endpoint, this._localEndpoint, 
											  this.OnRequestReceived, this._workers);
			this._workerPool.Start();
		}