本文整理汇总了C#中IConnection.Publish方法的典型用法代码示例。如果您正苦于以下问题:C# IConnection.Publish方法的具体用法?C# IConnection.Publish怎么用?C# IConnection.Publish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IConnection
的用法示例。
在下文中一共展示了IConnection.Publish方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: receiveAsyncSubscriber
private TimeSpan receiveAsyncSubscriber(IConnection c)
{
Stopwatch sw = new Stopwatch();
using (IAsyncSubscription s = c.SubscribeAsync(subject))
{
Object testLock = new Object();
s.MessageHandler += (sender, args) =>
{
if (received == 0)
sw.Start();
received++;
if (verbose)
Console.WriteLine("Received: " + args.Message);
replyMsg.Subject = args.Message.Reply;
c.Publish(replyMsg);
if (received >= count)
{
sw.Stop();
lock (testLock)
{
Monitor.Pulse(testLock);
}
}
};
lock (testLock)
{
s.Start();
Monitor.Wait(testLock);
}
}
return sw.Elapsed;
}
示例2: sendAndCheckMsgs
void sendAndCheckMsgs(IConnection ec, string subject, int numToSend)
{
for (int i = 0; i < numToSend; i++)
{
ec.Publish(subject, Encoding.UTF8.GetBytes(Convert.ToString(i)));
}
ec.Flush();
Thread.Sleep(500);
checkResults(numToSend);
}
示例3: receiveSyncSubscriber
private TimeSpan receiveSyncSubscriber(IConnection c)
{
using (ISyncSubscription s = c.SubscribeSync(subject))
{
Stopwatch sw = new Stopwatch();
while (received < count)
{
if (received == 0)
sw.Start();
Msg m = s.NextMessage();
received++;
if (verbose)
Console.WriteLine("Received: " + m);
replyMsg.Subject = m.Reply;
c.Publish(replyMsg);
}
sw.Stop();
return sw.Elapsed;
}
}
示例4: receiveAsyncSubscriber
private TimeSpan receiveAsyncSubscriber(IConnection c)
{
Stopwatch sw = null;
AutoResetEvent subDone = new AutoResetEvent(false);
EventHandler<MsgHandlerEventArgs> msgHandler = (sender, args) =>
{
if (received == 0)
{
sw = new Stopwatch();
sw.Start();
}
received++;
if (verbose)
Console.WriteLine("Received: " + args.Message);
replyMsg.Subject = args.Message.Reply;
c.Publish(replyMsg);
c.Flush();
if (received == count)
{
sw.Stop();
subDone.Set();
}
};
using (IAsyncSubscription s = c.SubscribeAsync(subject, msgHandler))
{
// just wait to complete
subDone.WaitOne();
}
return sw.Elapsed;
}
示例5: receiveAsyncSubscriber
private TimeSpan receiveAsyncSubscriber(IConnection c)
{
Stopwatch sw = null;
Object testLock = new Object();
EventHandler<MsgHandlerEventArgs> msgHandler = (sender, args) =>
{
if (received == 0)
sw.Start();
received++;
if (verbose)
Console.WriteLine("Received: " + args.Message);
replyMsg.Subject = args.Message.Reply;
c.Publish(replyMsg);
if (received >= count)
{
sw.Stop();
lock (testLock)
{
Monitor.Pulse(testLock);
}
}
};
using (IAsyncSubscription s = c.SubscribeAsync(subject, msgHandler))
{
// just wait to complete
lock (testLock)
{
Monitor.Wait(testLock);
}
}
return sw.Elapsed;
}