symphony v0.1.1
Symphony
Simplifies the startup and safe shutdown of Crystal servers that process inputs (such as queues and HTTP requests) and stream them to various outputs. Unlike traditional HTTP servers that directly respond to requests, this framework is designed for asynchronous processing.
The core idea is to let the application define a list of readers (input) and writers (output), where each reader and writer will run independently.
The framework will take care of the proper startup (first the writers, then the readers) and the safe shutdown (stopping first the readers, then the writers). It will also handle signals like SIGINT or SIGTERM.
Installation
-
Add the dependency to your
shard.yml
:dependencies: symphony: github: philipp-classen/symphony
-
Run
shards install
Usage
Here is a minimal example to illustrate how to set up a basic server. While this example does not include a writer and may not be practically useful, it demonstrates the basic structure of a Symphony application.
require "symphony"
class Application < Symphony::Application
Log = ::Log.for("test-app")
def create_input_readers : Array(Symphony::BackgroundService)
server = Symphony::HttpServer.new do |ctx|
ctx.response.content_type = "text/plain"
ctx.response.print "Hello world, got #{ctx.request.path}!"
end
[server] of Symphony::BackgroundService
end
def create_output_writers : Array(Symphony::BackgroundService)
[] of Symphony::BackgroundService
end
end
Log.setup_from_env
APP = Application.new
APP.run
Development
There are currently no tests.
Contributing
- Fork it (https://github.com/philipp-classen/symphony/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Philipp Claßen - creator and maintainer
symphony
- 0
- 0
- 1
- 0
- 0
- 5 months ago
- July 1, 2024
MIT License
Sun, 22 Dec 2024 06:06:34 GMT