Example #1
0
        protected override void OnStart(string[] args)
        {
            try
            {
                db = new SQLDB(Properties.Settings.Default.MSSQLSRV_ServerName, Properties.Settings.Default.MSSQLSRV_DBName, Properties.Settings.Default.MSSQLSRV_UserName, Properties.Settings.Default.MSSQLSRV_Password);

                rabbit = new RabbitMQ_Connect(
                    Callback,
                    Properties.Settings.Default.RabbitMQ_Hostname,
                    Properties.Settings.Default.RabbitMQ_Port,
                    Properties.Settings.Default.RabbitMQ_Virtualhost,
                    Properties.Settings.Default.RabbitMQ_Username,
                    Properties.Settings.Default.RabbitMQ_Password,
                    Properties.Settings.Default.RabbitMQ_QueueName,
                    Properties.Settings.Default.RabbitMQ_ExchangeName
                    );

                try
                {
                    rabbit.Start(false);
                }
                catch (Exception ex)
                {
                    string conf = "HostName=" + rabbit.HostName +
                                  ", Port=" + rabbit.Port.ToString() +
                                  ", VirtualHost=" + rabbit.VirtualHost +
                                  ", Username="******", Password="******", QueueName=" + rabbit.QueueName +
                                  ", ExchangeName=" + rabbit.ExchangeName;
                    ErrorLog("In rabbit.Start(false) " + ex.Message, new StackTrace(ex, true).ToString(), conf);
                    this.Stop();
                }
            }
            catch (Exception e)
            {
                string conf = "HostName=" + Properties.Settings.Default.RabbitMQ_Hostname +
                              ", Port=" + Properties.Settings.Default.RabbitMQ_Port.ToString() +
                              ", VirtualHost=" + Properties.Settings.Default.RabbitMQ_Virtualhost +
                              ", Username="******", Password="******", QueueName=" + Properties.Settings.Default.RabbitMQ_QueueName +
                              ", ExchangeName=" + Properties.Settings.Default.RabbitMQ_ExchangeName;
                ErrorLog("In new RabbitMQ_Connect() " + e.Message, new StackTrace(e, true).ToString(), conf);
                this.Stop();
            }
        }
Example #2
0
        private void Callback(RabbitMQ_Connect rabbit, object model, BasicDeliverEventArgs ea)
        {
            var    body     = ea.Body;
            string inputStr = Encoding.UTF8.GetString(body);

            try
            {
                string result = rabbit.DB.Execute(inputStr);
                if (null != result)
                {
                    rabbit.Reply(result, ea.BasicProperties);
                }
                rabbit.BasicAck(ea);
            }
            catch (Exception ex)
            {
                ErrorLog(ex.Message, new StackTrace(ex, true).ToString(), rabbit.DB.ConnectionString);
            }
        }
Example #3
0
        private void Callback(RabbitMQ_Connect rabbit, object model, BasicDeliverEventArgs ea)
        {
            var    body     = ea.Body;
            string inputStr = Encoding.UTF8.GetString(body);
            string result   = null;

            try
            {
                result = db.Execute(Properties.Settings.Default.MSSQLSRV_FunctionName, inputStr);
                ErrorLog("success", inputStr);
            }
            catch (Exception ex)
            {
                ErrorLog(ex.Message, new StackTrace(ex, true).ToString());
            }
            if (null != result)
            {
                rabbit.Reply(result, ea.BasicProperties);
            }
            rabbit.BasicAck(ea);
        }
Example #4
0
 protected override void OnStart(string[] args)
 {
     try
     {
         using (StreamReader r = new StreamReader(Properties.Settings.Default.ConfigFilePath))
         {
             string json = r.ReadToEnd();
             this.config = JsonConvert.DeserializeObject <Config>(json);
             this.RabbitMQ_Connections = new RabbitMQ_Connect[config.Routes.Length];
         }
         for (int i = 0; i < RabbitMQ_Connections.Length; i++)
         {
             try
             {
                 RabbitMQ_Connections[i] = new RabbitMQ_Connect(
                     new SQLDB(
                         config.Routes[i].MSSQLSRV_ServerName,
                         config.Routes[i].MSSQLSRV_DBName,
                         config.Routes[i].MSSQLSRV_UserName,
                         config.Routes[i].MSSQLSRV_Password,
                         config.Routes[i].MSSQLSRV_FunctionName,
                         config.Routes[i].MSSQLSRV_UseNvarchar
                         ),
                     Callback,
                     config.Routes[i].RabbitMQ_Hostname,
                     config.Routes[i].RabbitMQ_Port,
                     config.Routes[i].RabbitMQ_Virtualhost,
                     config.Routes[i].RabbitMQ_Username,
                     config.Routes[i].RabbitMQ_Password,
                     config.Routes[i].RabbitMQ_QueueName,
                     config.Routes[i].RabbitMQ_ExchangeName
                     );
                 try
                 {
                     RabbitMQ_Connections[i].Start(false);
                 }
                 catch (Exception ex)
                 {
                     string conf = "HostName=" + RabbitMQ_Connections[i].HostName +
                                   ", Port=" + RabbitMQ_Connections[i].Port.ToString() +
                                   ", VirtualHost=" + RabbitMQ_Connections[i].VirtualHost +
                                   ", Username="******", Password="******", QueueName=" + RabbitMQ_Connections[i].QueueName +
                                   ", ExchangeName=" + RabbitMQ_Connections[i].ExchangeName;
                     ErrorLog("In RabbitMQ_Connections[" + i.ToString() + "].Start(false) " + ex.Message, new StackTrace(ex, true).ToString(), conf);
                     this.Stop();
                 }
             }
             catch (Exception e)
             {
                 string conf = "HostName=" + config.Routes[i].RabbitMQ_Hostname +
                               ", Port=" + config.Routes[i].RabbitMQ_Port.ToString() +
                               ", VirtualHost=" + config.Routes[i].RabbitMQ_Virtualhost +
                               ", Username="******", Password="******", QueueName=" + config.Routes[i].RabbitMQ_QueueName +
                               ", ExchangeName=" + config.Routes[i].RabbitMQ_ExchangeName;
                 ErrorLog("In new RabbitMQ_Connect() " + e.Message, new StackTrace(e, true).ToString(), conf);
                 this.Stop();
             }
         }
     }
     catch (Exception e)
     {
         ErrorLog("In new load config file. With message: " + e.Message, new StackTrace(e, true).ToString());
         this.Stop();
     }
 }