public static void Main(string[] args) { Console.WriteLine("UDP Producer 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(); int numberOfMessages = 10; string message = "Hello, how are you?"; while ((numberOfMessages--) != 0) { System.Console.WriteLine("Publishing UDP message"); NetBrokerMessage brokerMessage = new NetBrokerMessage(System.Text.Encoding.UTF8.GetBytes(message)); BrokerClient.PublishMessageOverUdp(brokerMessage, cliArgs.DestinationName, new HostInfo(cliArgs.Hostname, cliArgs.PortNumber), BrokerClient.DefaultMessageSerializer); System.Threading.Thread.Sleep(500); } }
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 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); } }
public virtual void AddAction() { MainAction action = new MainAction("Publish", "producer"); action.Runnable = () => { foreach (TestClientInfo tci in ProducersInfo) { NetBrokerMessage brokerMessage = new NetBrokerMessage(Payload); if (PublishDestinationType.Equals(NetAction.DestinationType.TOPIC)) { tci.brokerClient.Publish(brokerMessage, this.DestinationName); } else { tci.brokerClient.Enqueue(brokerMessage, this.DestinationName); } tci.brokerClient.Close(); } action.Sucess = true; action.Done = true; }; this.SetAction(action); }