private static void Main(string[] args) { HorseMq mq = HorseMqBuilder.Create() .AddClientHandler <ClientHandler>() .AddQueueEventHandler <QueueEventHandler>() .UseJustAllowDeliveryHandler() .Build(); var sampleMessageRouter = mq.AddRouter("SAMPLE-MESSAGE-ROUTER", RouteMethod.Distribute); var sampleMessageQueueBinding = new QueueBinding("sample-message-queue-binding", "SAMPLE-MESSAGE-QUEUE", 1, BindingInteraction.Response); var sampleMessageDirectBinding = new DirectBinding("sample-message-direct-binding", "@type:SAMPLE-MESSAGE-CONSUMER", 2, BindingInteraction.Response, RouteMethod.RoundRobin); sampleMessageRouter.AddBinding(sampleMessageQueueBinding); sampleMessageRouter.AddBinding(sampleMessageDirectBinding); var giveMeGuidRequestRouter = mq.AddRouter("GIVE-ME-REQUEST-ROUTER", RouteMethod.Distribute); var giveMeGuidRequestHandler = new DirectBinding("sample-message-direct-binding", "@name:GIVE-ME-GUID-REQUEST-HANDLER-CONSUMER", 2, BindingInteraction.Response); giveMeGuidRequestRouter.AddBinding(giveMeGuidRequestHandler); HorseServer server = new HorseServer(); server.UseHorseMq(mq); server.Run(15500); }
static void Main(string[] args) { HorseMvc mvc = new HorseMvc(); HorseServer server = new HorseServer(); mvc.Init(); server.UseMvc(mvc, HttpOptions.CreateDefault()); server.Run(); }
static void Main(string[] args) { HorseMvc mvc = new HorseMvc(); mvc.IsDevelopment = false; mvc.Init(services => { services.AddScoped <IScopedService, ScopedService>(); services.AddTransient <IFirstService, FirstService>(); services.AddTransient <ISecondService, SecondService>(); services.AddJwt(mvc, options => { options.Key = "Very_very_secret_key"; options.Issuer = "localhost"; options.Audience = "localhost"; options.Lifetime = TimeSpan.FromHours(1); options.ValidateAudience = false; options.ValidateIssuer = false; options.ValidateLifetime = true; }); mvc.Policies.Add(Policy.RequireRole("Admin", "Admin")); mvc.Policies.Add(Policy.RequireClaims("IT", "Database", "Cloud", "Source")); mvc.Policies.Add(Policy.Custom("Custom", (d, c) => true)); mvc.StatusCodeResults.Add(HttpStatusCode.Unauthorized, new JsonResult(new { Message = "Access denied" })); mvc.ErrorHandler = new MvcErrorHandler(); }); CorsMiddleware cors = new CorsMiddleware(); cors.AllowAll(); mvc.Use(app => { app.UseActionRoute("/test-action", request => new StringResult("Hello, Test Action!")); app.UseMiddleware(cors); app.UseMiddleware <TMid>(); app.UseFiles("/download", "/home/mehmet/files"); }); HorseServer server = new HorseServer(); var opt = HttpOptions.CreateDefault(); opt.HttpConnectionTimeMax = 0; server.UseMvc(mvc, opt); server.Run(4410); }
static void Main(string[] args) { IServiceCollection services = new ServiceCollection(); HorseServer server = new HorseServer(); server.AddWebSockets(cfg => cfg.AddBus(services) //.UsePipeModelProvider(new NewtonsoftJsonModelSerializer()) .UsePayloadModelProvider(new SystemJsonModelSerializer()) .AddSingletonHandlers(typeof(Program)) /* * .OnClientConnected((info, data) => * { * WsServerSocket socket = new YourDerivedCustomSocket(info, data); * Task.FromResult(socket); * }) */ .OnClientReady(client => { Console.WriteLine("Client connected"); return(Task.CompletedTask); }) .OnClientDisconnected(client => { Console.WriteLine("Client disconnected"); return(Task.CompletedTask); }) .OnError(exception => Console.WriteLine("Error: " + exception))); server.UseWebSockets(services.BuildServiceProvider()); server.UseHttp((request, response) => { if (request.Path.Equals("/status", StringComparison.InvariantCultureIgnoreCase)) { response.SetToText(); response.StatusCode = HttpStatusCode.OK; response.Write("OK"); } else { response.StatusCode = HttpStatusCode.NotFound; } return(Task.CompletedTask); }); server.Run(26111); }
static void Main(string[] args) { HorseServer server = new HorseServer(); HorseMvc mvc = new HorseMvc(); mvc.Init(services => { }); mvc.Use(app => { IServiceProvider provider = app.GetProvider(); }); server.UseMvc(mvc); server.Run(5000); }
static void Main(string[] args) { HorseMq mq = HorseMqBuilder.Create() .AddOptions(o => o.Status = QueueStatus.Push) .AddClientHandler <ClientHandler>() .AddQueueEventHandler <QueueEventHandler>() .AddPersistentQueues() .UsePersistentDeliveryHandler(DeleteWhen.AfterAcknowledgeReceived, ProducerAckDecision.AfterSaved) .Build(); mq.LoadPersistentQueues(); HorseServer server = new HorseServer(); server.UseHorseMq(mq); server.Run(26222); }
static void Main(string[] args) { HorseServer server = new HorseServer(ServerOptions.CreateDefault()); server.UseHttp((request, response) => { if (request.Path.Equals("/plaintext", StringComparison.InvariantCultureIgnoreCase)) { response.SetToText(); return(response.WriteAsync("Hello, World!")); } response.StatusCode = HttpStatusCode.NotFound; return(Task.CompletedTask); }, HttpOptions.CreateDefault()); server.Run(5000); }
static void Main(string[] args) { HorseServer server = new HorseServer(ServerOptions.CreateDefault()); server.UseHttp(async(request, response) => { if (request.Path.Equals("/plaintext", StringComparison.InvariantCultureIgnoreCase)) { response.SetToText(); await response.WriteAsync("Hello, World!"); } else { response.StatusCode = HttpStatusCode.NotFound; } }); server.Run(22); }
static void Main(string[] args) { HorseServer server = new HorseServer(ServerOptions.CreateDefault()); server.UseHttp(async(request, response) => { if (request.Path.Equals("/json", StringComparison.InvariantCultureIgnoreCase)) { response.SetToJson(new { message = "Hello, World!" }); } else { response.StatusCode = HttpStatusCode.NotFound; } await Task.CompletedTask; }, HttpOptions.CreateDefault()); server.Run(); }