Closed zhaoyul closed 1 year ago
NetMQ Version: tested on "4.0.1.6" and 4.0.1.12 Operating System: win10, win11, osx .NET Version: . net 6.0
topic2|content2 topic2|content2 topic2|content2 topic2|content2 topic2|content2 topic1|content1 topic1|content1 topic2|content2 topic2|content2 topic2|content2 topic1|content1 topic2|content2 topic1|content1 topic2|content2 topic2|content2 topic2|content2 topic2|content2 topic2|content2 topic1|content1 ....
topic2|content2 topic2|content2 topic2|content2 topic2|content2 topic2|content2 topic1|content1 topic1|content1 topic2|content2 topic2|content2 topic2|content2 topic1|content1 topic2|content2 topic1|content1 topic2|content2 topic2|content2 topic2|content2 topic2|content2 topic2|content2 topic1|content1 topic2|topic1|content2 <== Error content1 <== Error topic1|content1
using NUnit.Framework; using NetMQ; using NetMQ.Sockets; using System; using System.Threading.Tasks; using System.Threading; namespace projectName; public class Tests { [SetUp] public void Setup() { } [Test] public void TestInprocPubSub() { PublisherSocket req = new PublisherSocket(); SubscriberSocket rsp = new SubscriberSocket(); req.Bind("inproc://good"); rsp.Connect("inproc://good"); rsp.Subscribe(""); var rand = new Random(); Task.Run(() => { while(true) { Thread.Sleep(rand.Next(5)); req.SendMoreFrame("topic1").SendFrame("content1"); } } ); Task.Run(() => { while(true) { Thread.Sleep(rand.Next(3)); req.SendMoreFrame("topic2").SendFrame("content2"); } } ); Task.Run(() => { while(true) Console.WriteLine(string.Join("|", rsp.ReceiveMultipartStrings())); }); Thread.Sleep(10000); } }
Sockets are not threadsafe, see https://stackoverflow.com/questions/35245387/netmq-sockets-are-thread-safe
Environment
Expected behaviour
Actual behaviour
Steps to reproduce the behaviour