本文整理汇总了C#中NetMQ.Msg.Put方法的典型用法代码示例。如果您正苦于以下问题:C# Msg.Put方法的具体用法?C# Msg.Put怎么用?C# Msg.Put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetMQ.Msg
的用法示例。
在下文中一共展示了Msg.Put方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
private static void Main()
{
const int messageCount = 1000000;
const int dealerCount = 100;
Console.WriteLine("Sending {0} messages to {1} dealers", messageCount, dealerCount);
//BufferPool.SetBufferManagerBufferPool(1024 * 1024 * 10, 1024);
using (var router = new RouterSocket())
{
router.Options.SendHighWatermark = 0;
router.Bind("tcp://*:5555");
var dealers = new List<DealerSocket>();
var identities = new List<Msg>();
var random = new Random();
var identity = new byte[50];
for (var i = 0; i < dealerCount; i++)
{
random.NextBytes(identity);
var dealer = new DealerSocket
{
Options =
{
Identity = identity.Skip(10).ToArray(),
ReceiveHighWatermark = 0
}
};
dealer.Connect("tcp://localhost:5555");
dealers.Add(dealer);
var msg = new Msg();
msg.InitGC(identity, 10, identity.Length); // test offsets
identities.Add(msg);
}
Thread.Sleep(500);
while (!Console.KeyAvailable)
{
Thread.Sleep(500);
var stopwatch = Stopwatch.StartNew();
for (var i = 0; i < messageCount; i++)
{
var msg = identities[i%identities.Count];
router.Send(ref msg, true);
var msg2 = new Msg();
msg2.InitPool(1);
msg2.Put((byte) 'E');
router.Send(ref msg2, false);
}
stopwatch.Stop();
Console.WriteLine("{0:N1} messages sent per second", messageCount/stopwatch.Elapsed.TotalSeconds);
}
foreach (var dealerSocket in dealers)
dealerSocket.Dispose();
}
}