Пример #1
0
        static void Main(string[] args)
        {
            var client = DaprClient.CreateInvokeHttpClient(
                appId: APP_ID
                );

            var count = 1;

            while (true)
            {
                System.Console.WriteLine("第 {0} 次创建订单", count);
                try
                {
                    var input = new NewOrderInput
                    {
                        Data = new OrderDto
                        {
                            OrderId = count++.ToString()
                        }
                    };
                    var res = client.PostAsJsonAsync(METHOD_NAME, input)
                              .GetAwaiter().GetResult();

                    Console.WriteLine(res.Content.ReadAsStringAsync().GetAwaiter().GetResult());
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine(ex.ToString());
                }

                Thread.Sleep(3000);
            }
        }
Пример #2
0
        public async Task <string> Create([FromBody] NewOrderInput input)
        {
            using var client = new DaprClientBuilder()
                               .UseHttpEndpoint(DAPR_SIDECAR_HTTP)
                               .Build();

            try
            {
                await client.SaveStateAsync(STATE_STORE_NAME, STATE_KEY, input.Data);

                return("保存订单成功");
            }
            catch (Exception ex)
            {
                this._logger.LogError(ex, "保存订单出错!");
                return(ex.Message);
            }
        }