当前位置: 首页 > news >正文

网站如何备案 流程哪些平台可以建立网站吗

网站如何备案 流程,哪些平台可以建立网站吗,wordpress 上一页,电商平台如何做推广前置条件DockerWin10Dapr 部署本文将采用本地部署的方式。安装 Dapr CLI打开 Windows PowerShell 或 cmd #xff0c;运行以下命令以安装 Dapr CLI#xff0c;并添加安装路径到系统环境变量中。powershell -Command iwr -useb https://raw.githubusercontent.com/dapr/… 前置条件DockerWin10Dapr 部署本文将采用本地部署的方式。安装 Dapr CLI打开 Windows PowerShell 或 cmd 运行以下命令以安装 Dapr CLI并添加安装路径到系统环境变量中。powershell -Command iwr -useb https://raw.githubusercontent.com/dapr/cli/master/install/install.ps1 | iex这里安装可能会失败。如果失败可以手动安装。打开 Dapr 发布页面下载 dapr_windows_amd64.zip解压文件 zip 文件把解压后的文件拷贝到 C:\dapr 中安装 MySqlDocker 启动 Mysqldocker run --name mysqltest -e MYSQL_ROOT_PASSWORD123456 -d mysql使用 Dapr CLI 安装 Darp runtime在 Windows PowerShell 或 cmd 中使用命令 dapr init 以安装 Dapr。同时可以在 Docker 中查看 Dapr 容器。至此一个本地 Dapr 服务搭建完成。使用 Asp.Net Core 搭建 ProductService 服务ProductService 提供两个服务获取所有产品集合添加产品使用 ASP.Net Core 创建 ProductService 具体参考源码Dapr 启动 ProductServicedapr run --app-id productService --app-port 5000 dotnet run获取所有产品集合使用 curl 命令curl -X GET http://localhost:5000/getlist或者curl -X GET http://localhost:54680/v1.0/invoke/productService/method/getlist添加一个产品curl -X POST https://localhost:5001/product -H Content-Type: application/json -d { \id\: \14a3611d-1561-455f-9c72-381eed2f6ee3\ }重点通过 Dapr 添加一个产品先看添加产品的代码 /// summary/// 创建产品/// /summary/// param nameproductCreate产品创建模型/param/// returns/returns[Topic(product)][HttpPost(product)]public async Taskbool CreateProduct(ProductCreate productCreate){_productContext.Products.Add(new Product{ProductID productCreate.ID});return await _productContext.SaveChangesAsync() 1;}使用 Dapr cli 发布事件 dapr invoke -a productService -m product -p {\id\:\b1ccf14a-408a-428e-b0f0-06b97cbe4135\}输出为true App invoked successfully使用 curl 命令直接请求 ProductService 地址curl -X POST http://localhost:5000/product -H Content-Type: application/json -d { \id\: \14a3611d-1561-455f-9c72-381eed2f64e3\ }输出为true使用 curl 命令通过 Dapr runtimecurl -X POST http://localhost:54680/v1.0/invoke/productService/method/product -H Content-Type: application/json -d { \id\: \14a3611d-1561-455f-9c72-381eed2f54e3\ }输出为true注意Dapr 使用 App 端口号应与服务端口号相同例如ASP.Net Core 服务端口号为5000则在使用 Dapr 托管应用程序时的端口号也应使用 5000至此 ProductService 创建完成。使用 Golang 创建 gRPC Server创建 Serverpackage mainimport (contextfmtlognetgithub.com/golang/protobuf/ptypes/anygithub.com/golang/protobuf/ptypes/emptypb github.com/dapr/go-sdk/daprclientgoogle.golang.org/grpc )// server is our user app type server struct { }func main() {// create listinerlis, err : net.Listen(tcp, :4000)if err ! nil {log.Fatalf(failed to listen: %v, err)}// create grpc servers : grpc.NewServer()pb.RegisterDaprClientServer(s, server{})fmt.Println(Client starting...)// and start...if err : s.Serve(lis); err ! nil {log.Fatalf(failed to serve: %v, err)} }// Sample method to invoke func (s *server) MyMethod() string {return Hi there! }// This method gets invoked when a remote service has called the app through Dapr // The payload carries a Method to identify the method, a set of metadata properties and an optional payload func (s *server) OnInvoke(ctx context.Context, in *pb.InvokeEnvelope) (*any.Any, error) {var response stringfmt.Println(fmt.Sprintf(Got invoked with: %s, string(in.Data.Value)))switch in.Method {case MyMethod:response s.MyMethod()}return any.Any{Value: []byte(response),}, nil }// Dapr will call this method to get the list of topics the app wants to subscribe to. In this example, we are telling Dapr // To subscribe to a topic named TopicA func (s *server) GetTopicSubscriptions(ctx context.Context, in *empty.Empty) (*pb.GetTopicSubscriptionsEnvelope, error) {return pb.GetTopicSubscriptionsEnvelope{Topics: []string{TopicA},}, nil }// Dapper will call this method to get the list of bindings the app will get invoked by. In this example, we are telling Dapr // To invoke our app with a binding named storage func (s *server) GetBindingsSubscriptions(ctx context.Context, in *empty.Empty) (*pb.GetBindingsSubscriptionsEnvelope, error) {return pb.GetBindingsSubscriptionsEnvelope{Bindings: []string{storage},}, nil }// This method gets invoked every time a new event is fired from a registerd binding. The message carries the binding name, a payload and optional metadata func (s *server) OnBindingEvent(ctx context.Context, in *pb.BindingEventEnvelope) (*pb.BindingResponseEnvelope, error) {fmt.Println(Invoked from binding)return pb.BindingResponseEnvelope{}, nil }// This method is fired whenever a message has been published to a topic that has been subscribed. Dapr sends published messages in a CloudEvents 0.3 envelope. func (s *server) OnTopicEvent(ctx context.Context, in *pb.CloudEventEnvelope) (*empty.Empty, error) {fmt.Println(Topic message arrived)return empty.Empty{}, nil } 使用 Dapr 命令启动 StorageService dapr run --app-id client --protocol grpc --app-port 4000 go run main.go注意Dapr 使用 App 端口号应与服务端口号相同使用 --protocal grpc 指定通讯协议为 grpc 。此外OnInvoke 中的 switch 方法用于调用者路由。使用 ASP.NET Core 创建 StorageService使用 NuGet 获取程序管理包控制台安装以下包Dapr.AspNetCoreDapr.Client.GrpcGrpc.AspNetCoreGrpc.Net.ClientGrpc.ToolsStartup.cs 文件中修改代码如下/// summary /// This method gets called by the runtime. Use this method to add services to the container. /// /summary /// param nameservicesServices./param public void ConfigureServices(IServiceCollection services) {services.AddControllers().AddDapr();services.AddDbContextPoolStorageContext(options { options.UseMySql(Configuration.GetConnectionString(MysqlConnection)); }); } /// summary /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. /// /summary /// param nameappapp./param /// param nameenvenv./param public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {if (env.IsDevelopment()){app.UseDeveloperExceptionPage();}app.UseRouting();app.UseCloudEvents();app.UseAuthorization();app.UseEndpoints(endpoints {endpoints.MapSubscribeHandler();endpoints.MapControllers();}); }添加 StorageController.cs 文件内容如下using System; using System.Linq; using System.Threading.Tasks; using Dapr.Client.Grpc; using Google.Protobuf; using Grpc.Net.Client; using Microsoft.AspNetCore.Mvc; using StorageService.Api.Entities;namespace StorageService.Api.Controllers {[ApiController]public class StorageController : ControllerBase{private readonly StorageContext _storageContext;public StorageController(StorageContext storageContext){_storageContext storageContext;}/// summary/// 初始化仓库./// /summary/// returns是否成功./returns[HttpGet(InitialStorage)]public async Taskbool InitialStorage(){string defaultPort Environment.GetEnvironmentVariable(DAPR_GRPC_PORT) ?? 54681;// Set correct switch to make insecure gRPC service calls. This switch must be set before creating the GrpcChannel.AppContext.SetSwitch(System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport, true);// Create Clientstring daprUri $http://127.0.0.1:{defaultPort};GrpcChannel channel GrpcChannel.ForAddress(daprUri);var client new Dapr.Client.Grpc.Dapr.DaprClient(channel);Console.WriteLine(daprUri);InvokeServiceResponseEnvelope result await client.InvokeServiceAsync(new InvokeServiceEnvelope{Method MyMethod,Id client,Data new Google.Protobuf.WellKnownTypes.Any{Value ByteString.CopyFromUtf8(Hello ProductService)}});Console.WriteLine(this is call result: result.Data.Value.ToStringUtf8());//var productResult result.Data.UnpackProductList.V1.ProductList();//Console.WriteLine(this is call result: productResult.Results.FirstOrDefault());return true;}/// summary/// 修改库存/// /summary/// param namestorage/param/// returns/returns[HttpPut(Reduce)]public bool Reduce(Storage storage){Storage storageFromDb _storageContext.Storage.FirstOrDefault(q q.ProductID.Equals(storage.ProductID));if (storageFromDb null){return false;}if (storageFromDb.Amount storage.Amount){return false;}storageFromDb.Amount - storage.Amount;return true;}} }使用 Dapr cli 启用 StorageService 服务dapr run --app-id storageService --app-port 5003 dotnet run使用 curl 命令访问 StorageService InitialStorage 方法curl -X GET http://localhost:56349/v1.0/invoke/storageService/method/InitialStorage输入true其中打印信息为this is call result:Hi there!注意Dapr 使用 App 端口号应与服务端口号相同例如ASP.Net Core 服务端口号为5003则在使用 Dapr 托管应用程序时的端口号也应使用 5003在 Client.InvokeServiceAsync 中的 Id 指被调用方的 App-Id ,Method 指被调用方方法名称。参考 Go Server 中 OnInvoke 方法的 Switch 。源码地址https://github.com/SoMeDay-Zhang/DaprDemos
http://www.sadfv.cn/news/383135/

相关文章:

  • 建设银行的网站用户名是什么wordpress插件wordpress小工具
  • 网站优化有哪些类型wordpress修改xmlrpc
  • 网站建设搭建步骤昆明网站设计建设
  • 学做网站和推广要多久vivo官网网站服务
  • 建设部网站拆除资质用html5做课程教学网站
  • 卖东西的网站怎么做软件开发公司优势
  • 九龙坡区建设二校的网站做网站用什么代码编写
  • 株洲网站制作公司网站的建设流程具体有哪些
  • 徐州有办网站的地方吗行业型网站 赢利点
  • 做爰全过程免费网站的视频教程如何建立一个外贸网站
  • 北京网站设计培训机构wordpress orchard
  • php 行业网站静态html转化wordpress主题
  • 淮安j经济开发区建设局网站从什么网站建网站好
  • 个人音乐类网站服务器租借做360手机网站优
  • 怎么做网站二级页面wordpress 子目录
  • 网站做动态还是静态租房信息网站建设
  • 网站建设专家工作内容沈阳人流需要多少钱大概多少钱
  • 沙漠风网站建设lnmp怎么做网站
  • 网站建设用什么教材崇信县门户网站留言首页
  • pc网站是什么网站如何做监控直播
  • 临沂罗庄做网站大连网站制作网页
  • 潍坊哪家网站制作公司好咸宁网站设计公司
  • 网站开发开始阶段的主要任务包括( )开通招聘网站如何做分录
  • 专业企业网站建设报价宁夏网站设计
  • 青海省城乡和住房建设厅网站会员制网站搭建wordpress
  • 网站开发应该先写前端还是后端上海大众汽车网站哪家公司做的
  • 个股期权网站开发班级网页设计素材
  • 合作做网站的总结和心得怎样将qq空间建设为个人网站
  • 站内营销推广方式有哪些店铺推广语
  • 如何设计好酒店网站模板沈阳网站建设的公司