public static void Main(string[] args) { Console.WriteLine("MultipleProducers test"); if (args.Length == 0) { System.Console.WriteLine(CommandLineArguments.Usage()); return; } log4net.Config.BasicConfigurator.Configure(); CommandLineArguments cliArgs = new CommandLineArguments(); Parser parser = new Parser(System.Environment.CommandLine, cliArgs); parser.Parse(); BrokerClient brokerClient = new BrokerClient(new HostInfo(cliArgs.Hostname, cliArgs.PortNumber)); int numberOfMessages = 500000; Thread[] threads = new System.Threading.Thread[NR_THREADS]; for (int i = 0; i != threads.Length; ++i) { threads[i] = new Thread( new ThreadStart(() => { int msgs = numberOfMessages; int threadId = i; while ((--msgs) != 0) { int msgId = Interlocked.Increment(ref message_id); string message = String.Format("{0} - Thread id: {1}", msgId, threadId); NetBrokerMessage brokerMessage = new NetBrokerMessage(System.Text.Encoding.UTF8.GetBytes(message)); System.Console.WriteLine(message); if (cliArgs.DestinationType == NetAction.DestinationType.TOPIC) { brokerClient.Publish(brokerMessage, cliArgs.DestinationName); } else { brokerClient.Enqueue(brokerMessage, cliArgs.DestinationName); } } } ) ); threads[i].Start(); } Console.WriteLine("Write X to unsbscribe and exit"); while (!System.Console.Read().Equals('X')) { ; } }
private static void LoopPublish() { while (true) { SensorInfo value = SensorFaker.Generate(); CurrValue = JsonConvert.SerializeObject(value, Formatting.Indented); BrokerClient.Publish("home/device/data", Encoding.Default.GetBytes(CurrValue)); Console.WriteLine($"Published: {CurrValue}"); Thread.Sleep(1000); } }
private void LoopPublish() { while (true) { SensorInfo value = SensorFaker.Generate(); CurrValue = JsonConvert.SerializeObject(value, Formatting.Indented); BrokerClient.Publish("home/device/data", Encoding.Default.GetBytes(CurrValue)); this.Invoke(new Action(() => { RtbLog.AppendText($"Published: {CurrValue}\n"); RtbLog.ScrollToCaret(); })); Thread.Sleep(1000); } }
private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { while (true) { SensorInfo ThisValue = SensorFaker.Generate(); CurrValue = JsonConvert.SerializeObject(ThisValue, Formatting.Indented); BrokerClient.Publish("home/device/data/", Encoding.Default.GetBytes(CurrValue)); //Console.WriteLine($"Published : {CurrValue}"); string publishtext = $"Published : {CurrValue}\n\n"; RTBLog.AppendText(publishtext); RTBLog.ScrollToCaret(); Thread.Sleep(1000); } }
private static void PublishMessages(BrokerClient brokerClient, string destination, int numberOfMessages, NetAction.DestinationType destinationType) { //string message = "Hello, how are you?"; int i = 0; while ((numberOfMessages--) != 0) { System.Console.WriteLine("Publishing message"); NetBrokerMessage brokerMessage = new NetBrokerMessage(System.Text.Encoding.UTF8.GetBytes((i++).ToString())); if (destinationType == NetAction.DestinationType.TOPIC) { brokerClient.Publish(brokerMessage, destination); } else { brokerClient.Enqueue(brokerMessage, destination); } System.Threading.Thread.Sleep(50); } }