Esempio n. 1
0
        private void btnSendDatabaseSyncCommand_Click(object sender, EventArgs e)
        {
            DatabaseSyncCommand cmd = new DatabaseSyncCommand();

            DatabaseSyncItem item1 = new DatabaseSyncItem()
            {
                Action          = DatabaseSyncAction.Add,
                Table           = "Customers",
                PrimaryKeyValue = "062B54F5-69AA-A108-09F8-39DB9C2F58C4"
            };

            DatabaseSyncItem item2 = new DatabaseSyncItem()
            {
                Action          = DatabaseSyncAction.Update,
                Table           = "Customers",
                PrimaryKeyValue = "062B54F5-69AA-A108-09F8-39DB9C2F58C4"
            };

            DatabaseSyncItem item3 = new DatabaseSyncItem()
            {
                Action          = DatabaseSyncAction.Delete,
                Table           = "Customers",
                PrimaryKeyValue = "062B54F5-69AA-A108-09F8-39DB9C2F58C4"
            };

            cmd.SyncItemList.Add(item1);
            cmd.SyncItemList.Add(item2);
            cmd.SyncItemList.Add(item3);

            string json = JsonConvert.SerializeObject(cmd);

            _rabbitMQService.Send("exchangeName_A", "routingKey_A", json);

            MessageBox.Show("DatabaseSyncCommand 命令已发送。 Command 需要通过 CommandExecuterService 去解析和消费。");
        }
Esempio n. 2
0
        public void RabbitMQ()
        {
            var builder = new ConfigurationBuilder()
                          .AddConfigurationFile("appsettings.json", optional: true, reloadOnChange: true);
            var Configuration = builder.Build();

            var mq  = new RabbitMQService(AppConfig.GetSection("RabbitMQConnectionString")?.Value);
            var con = new ContainerBuilder();

            con.AddRabbitMQService();
            var icon = con.Build();

            var mq1 = icon.Resolve <IRabbitMQService>();
            //·¢ËÍ
            var originObject = new testclass()
            {
                id   = 1,
                name = "ÐÕÃû1"
            };

            mq.Send("changeNametest3", "direct", originObject);


            //½ÓÊÜ
            var mq2 = icon.Resolve <IRabbitMQService>();

            mq2.Receive("aaa", "changeNametest3", "direct", q =>
            {
                Assert.Equal(q, Serializer.Serialize(originObject));
            });
        }
Esempio n. 3
0
        //public bool sendCommand([FromBody] string command)
        public bool sendCommand(int deviceId, string commandName)
        {
            bool is_command_success = true;

            // Note: no need to format the message, if the command
            //string message = "{'deviceId': " + deviceId + ", 'commandName': " + commandName + "}";
            string message = deviceId + ";" + commandName;

            /* bool is_command_success = */ _rabbitMQService.Send(IOT_URL, IOT_QUEUE_NAME, message);

            return(is_command_success);
        }
        public override void InnerRun(Dictionary <string, object> vars, Dictionary <string, object> outputVars, Dictionary <string, object> InvertedInputVars, Message message)
        {
            COREobject core    = COREobject.i;
            DBEntities context = core.Context;

            try
            {
                string rabbitMQName  = (string)vars["rabbitMQ"];
                object messageObject = vars["Message"];

                if (string.IsNullOrEmpty(rabbitMQName))
                {
                    throw new Exception($"{Name}: Please attach RabbitMQ integration.");
                }

                if (messageObject == null)
                {
                    throw new Exception($"{Name}: Message must not be null.");
                }

                N.RabbitMQ mq = context.RabbitMQs.SingleOrDefault(q => q.Name == rabbitMQName);
                if (mq == null)
                {
                    throw new Exception($"{Name}: Requested RabbitMQ {rabbitMQName} was not found");
                }

                RabbitMQService service = new RabbitMQService(mq);

                string body;
                if (messageObject is JToken)
                {
                    body = messageObject.ToString();
                }
                else
                {
                    body = Convert.ToString(messageObject);
                }

                service.Send(body);
                service.Close();

                outputVars["Result"] = true;
                outputVars["Error"]  = "";
            }
            catch (Exception e) {
                outputVars["Result"] = false;
                outputVars["Error"]  = e.Message;
            }
        }
        /// <summary>
        /// 发送指令
        /// </summary>
        /// <param name="Queue"></param>
        /// <param name="ShelfCode"></param>
        /// <returns></returns>
        public static void SendMessage(string Queue, string Operation, BaseAction ActionData, bool IsRabbit = false)
        {
            System.Console.WriteLine("开始执行发布\n");
            BaseResult cabinet = Config.Bind <BaseResult>("Device.json", Operation);

            ActionData.Msg     = string.Format(cabinet.Message, ActionData.Msg);
            cabinet.ActionData = ActionData;
            cabinet.Message    = ActionData.Msg;
            if (IsRabbit)
            {
                System.Console.WriteLine("发送RabbitMq\n");
                RabbitMQService.Send(Queue, cabinet);
            }
            System.Console.WriteLine("发送MqTT\n");
            MqttHelp <MqttClientTcpOptions> .Publish <BaseResult>(Queue, cabinet);
        }
        /// <summary>
        /// 记录请求参数日志
        /// </summary>
        /// <param name="context"></param>
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            HttpContext httpc = context.HttpContext;
            LogEntity   log   = new LogEntity()
            {
                TrackId = httpc.TraceIdentifier,
                Method  = httpc.Request.Method,
                Param   = context.ActionArguments.Count == 0 ? new object() : context.ActionArguments.FirstOrDefault(),
                Result  = "",
                BegTime = DateTime.Now,
                Url     = string.Format("{0}://{1}{2}", httpc.Request.Scheme, httpc.Request.Host.Value, httpc.Request.Path.Value)
            };

            RabbitMQService.Send("Log", log, true);
            Log.Info(log);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        public override void OnActionExecuted(ActionExecutedContext context)
        {
            HttpContext httpc = context.HttpContext;

            LogEntity log = new LogEntity()
            {
                TrackId = httpc.TraceIdentifier,
                Method  = httpc.Request.Method,
                Param   = "",
                EndTime = DateTime.Now,
                Url     = string.Format("{0}://{1}{2}", httpc.Request.Scheme, httpc.Request.Host.Value, httpc.Request.Path.Value),
                Result  = context.Result == null ? "" : ((ObjectResult)context.Result).Value,
            };

            RabbitMQService.Send("Log", log);
            Log.Info(log);
            base.OnActionExecuted(context);
        }
Esempio n. 8
0
 public DeviceController()
 {
     _requestService  = new RequestService();
     _rabbitMQService = new RabbitMQService();
     _rabbitMQService.Send("localhost", "command_queue", "ALLO");
 }
Esempio n. 9
0
 public void SendWord([FromBody] WordMessage word) => _producer.Send(word.Message);