コード例 #1
0
ファイル: UdpProducer.cs プロジェクト: carlosefr/sapo-broker
        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);
            }
        }
コード例 #2
0
        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'))
                ;
        }
コード例 #3
0
        private static NetBrokerMessage getBrokerMessage(BrokerMessage brokerMessage)
        {
            NetBrokerMessage netBrokerMessage = new NetBrokerMessage(brokerMessage.Payload);

            netBrokerMessage.Expiration = brokerMessage.Expiration;
            netBrokerMessage.MessageId  = brokerMessage.Message_id;
            netBrokerMessage.Timestamp  = brokerMessage.Timestamp;
            return(netBrokerMessage);
        }
コード例 #4
0
        private static BrokerMessage getBrokerMessage(NetBrokerMessage brokerMessage)
        {
            BrokerMessage brokerMsg = new BrokerMessage();

            brokerMsg.Expiration = brokerMessage.Expiration;
            brokerMsg.Message_id = brokerMessage.MessageId;
            brokerMsg.Payload    = brokerMessage.Payload;
            brokerMsg.Timestamp  = brokerMessage.Timestamp;

            return(brokerMsg);
        }
コード例 #5
0
        /// <summary>
        /// Enqueue a message over UDP.
        /// </summary>
        /// <param name="message">Message content.</param>
        /// <param name="destination">Message destination.</param>
        /// <param name="hostInfo">Agent information.</param>
        /// <param name="messageSerializer">Serialization type.</param>
        public static void EnqueueMessageOverUdp(NetBrokerMessage message, string destination, HostInfo hostInfo, IMessageSerializer messageSerializer)
        {
            NetPublish publish = new NetPublish(destination, NetAction.DestinationType.QUEUE, message);

            NetAction action = new NetAction(NetAction.ActionType.PUBLISH);

            action.PublishMessage = publish;

            NetMessage netMessage = new NetMessage(action, message.Headers);

            BrokerProtocolHandler.SendMessageOverUdp(netMessage, hostInfo, messageSerializer);
        }
コード例 #6
0
 internal NetNotification(string destination, NetAction.DestinationType destinationType, NetBrokerMessage message, string subscription, IDictionary <string, string> headers)
 {
     this.destination     = destination;
     this.destinationType = destinationType;
     this.message         = message;
     if (subscription == null)
     {
         this.subscription = "";
     }
     else
     {
         this.subscription = subscription;
     }
     this.headers = headers;
 }
コード例 #7
0
        /// <summary>
        /// Publish a message (to a topic).
        /// </summary>
        /// <param name="message">A broker message</param>
        /// <param name="destination">A destination (e.g. "/topic/foo")</param>
        /// <param name="acceptRequest">An AcceptRequest instance.</param>
        public void Publish(NetBrokerMessage message, string destination, AcceptRequest acceptRequest)
        {
            if (IsClosed())
            {
                return;
            }

            NetPublish publish = new NetPublish(destination, NetAction.DestinationType.TOPIC, message);

            NetAction action = new NetAction(NetAction.ActionType.PUBLISH);

            action.PublishMessage = publish;

            NetMessage netMessage = new NetMessage(action, message.Headers);

            protocolHandler.HandleOutgoingMessage(netMessage, acceptRequest);
        }
コード例 #8
0
ファイル: Producer.cs プロジェクト: carlosefr/sapo-broker
 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);
     }
 }
コード例 #9
0
 protected override void Send(ManagementReport report, String activityId, String agentId)
 {
     var reportJson = new Dictionary<String, Object>{
         {"ID", report.ID},
         {"SourceID", report.SourceID },
         {"DateTime", report.DateTime},
         {"State", new Dictionary<String, Object> {
                 {"Health", report.State.Health.ToString() },
                 {"Execution", report.State.Execution.ToString()},
                 {"Failures", (from f in report.State.Failures
                       select new Dictionary<String, Object> {
                            {"FailureID", f.FailureID},
                            {"SourceID", f.SourceID},
                            {"Details", f.Details}
                       }).ToArray()}
         }},
         {"Metrics", report.Metrics != null ? (from m in report.Metrics
                       select new Dictionary<String, Object> {
                            {"MetricID", m.MetricID},
                            {"SourceID", m.SourceID},
                            {"Reference", m.Reference},
                            {"Value", m.Value},
                            {"Details", m.Details},
                            {"CategoryID", m.CategoryID},
                            {"DateTime", m.DateTime }
                       }).ToArray() : null},
         {"ActivityID", activityId},
         {"AgentID", agentId},
         };
     
     var str = new StringWriter();
     var jsonSer = new Newtonsoft.Json.JsonSerializer();
     jsonSer.Serialize(str, reportJson);
     NetBrokerMessage brokerMessage = new NetBrokerMessage(str.ToString());
     this.brokerClient.Publish(brokerMessage, this.topic);
 }        
コード例 #10
0
ファイル: BrokerClient.cs プロジェクト: carlosefr/sapo-broker
        /// <summary>
        /// Publish a message (to a topic).
        /// </summary>
        /// <param name="message">A broker message</param>
        /// <param name="destination">A destination (e.g. "/topic/foo")</param>
        /// <param name="acceptRequest">An AcceptRequest instance.</param>
        public void Publish(NetBrokerMessage message, string destination, AcceptRequest acceptRequest)
        {
            if (IsClosed())
                return;

            NetPublish publish = new NetPublish(destination, NetAction.DestinationType.TOPIC, message);

            NetAction action = new NetAction(NetAction.ActionType.PUBLISH);
            action.PublishMessage = publish;

            NetMessage netMessage = new NetMessage(action, message.Headers);

            protocolHandler.HandleOutgoingMessage(netMessage, acceptRequest);
        }
コード例 #11
0
ファイル: BrokerClient.cs プロジェクト: carlosefr/sapo-broker
 /// <summary>
 /// Publish a message (to a topic).
 /// </summary>
 /// <param name="message">A broker message</param>
 /// <param name="destination">A destination (e.g. "/topic/foo")</param>
 public void Publish(NetBrokerMessage message, string destination)
 {
     Publish(message, destination, null);
 }
コード例 #12
0
ファイル: BrokerClient.cs プロジェクト: carlosefr/sapo-broker
 /// <summary>
 /// Enqueue a message.
 /// </summary>
 /// <param name="message">A broker message</param>
 /// <param name="destination">A destination (e.g. "/queue/foo")</param>
 public void Enqueue(NetBrokerMessage message, string destination)
 {
     Enqueue(message, destination, null);
 }
コード例 #13
0
ファイル: BrokerClient.cs プロジェクト: carlosefr/sapo-broker
        /// <summary>
        /// Publish a message over UDP.
        /// </summary>
        /// <param name="message">Message content.</param>
        /// <param name="destination">Message destination.</param>
        /// <param name="hostInfo">Agent information.</param>
        /// <param name="messageSerializer">Serialization type.</param>
        public static void PublishMessageOverUdp(NetBrokerMessage message, string destination, HostInfo hostInfo, IMessageSerializer messageSerializer)
        {
            NetPublish publish = new NetPublish(destination, NetAction.DestinationType.TOPIC, message);

            NetAction action = new NetAction(NetAction.ActionType.PUBLISH);
            action.PublishMessage = publish;

            NetMessage netMessage = new NetMessage(action, message.Headers);

            BrokerProtocolHandler.SendMessageOverUdp(netMessage, hostInfo, messageSerializer);
        }
コード例 #14
0
 private static NetBrokerMessage getBrokerMessage(BrokerMessage brokerMessage)
 {
     NetBrokerMessage netBrokerMessage = new NetBrokerMessage(brokerMessage.Payload);
     netBrokerMessage.Expiration = brokerMessage.Expiration;
     netBrokerMessage.MessageId = brokerMessage.Message_id;
     netBrokerMessage.Timestamp = brokerMessage.Timestamp;
     return netBrokerMessage;
 }
コード例 #15
0
ファイル: Messages.cs プロジェクト: carlosefr/sapo-broker
 internal NetNotification(string destination, NetAction.DestinationType destinationType, NetBrokerMessage message, string subscription, IDictionary<string, string> headers)
 {
     this.destination = destination;
     this.destinationType = destinationType;
     this.message = message;
     if (subscription == null)
         this.subscription = "";
     else
         this.subscription = subscription;
     this.headers = headers;
 }
コード例 #16
0
 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);
 }
コード例 #17
0
 /// <summary>
 /// Publish a message (to a topic).
 /// </summary>
 /// <param name="message">A broker message</param>
 /// <param name="destination">A destination (e.g. "/topic/foo")</param>
 public void Publish(NetBrokerMessage message, string destination)
 {
     Publish(message, destination, null);
 }
コード例 #18
0
 /// <summary>
 /// Enqueue a message.
 /// </summary>
 /// <param name="message">A broker message</param>
 /// <param name="destination">A destination (e.g. "/queue/foo")</param>
 public void Enqueue(NetBrokerMessage message, string destination)
 {
     Enqueue(message, destination, null);
 }
コード例 #19
0
ファイル: Messages.cs プロジェクト: carlosefr/sapo-broker
 public NetPublish(string destination, NetAction.DestinationType destinationType, NetBrokerMessage message)
 {
     this.destinationType = destinationType;
     this.destination = destination;
     this.message = message;
 }
コード例 #20
0
 public NetPublish(string destination, NetAction.DestinationType destinationType, NetBrokerMessage message)
 {
     this.destinationType = destinationType;
     this.destination     = destination;
     this.message         = message;
 }
コード例 #21
0
        private static BrokerMessage getBrokerMessage(NetBrokerMessage brokerMessage)
        {
            BrokerMessage brokerMsg = new BrokerMessage();
            brokerMsg.Expiration = brokerMessage.Expiration;
            brokerMsg.Message_id = brokerMessage.MessageId;
            brokerMsg.Payload = brokerMessage.Payload;
            brokerMsg.Timestamp = brokerMessage.Timestamp;

            return brokerMsg;
        }