{"id":15041006,"url":"https://github.com/hypercube1024/firefly","last_synced_at":"2025-04-04T10:09:52.182Z","repository":{"id":2484876,"uuid":"3458429","full_name":"hypercube1024/firefly","owner":"hypercube1024","description":"Firefly is an asynchronous web framework for rapid development of high-performance web application.","archived":false,"fork":false,"pushed_at":"2024-09-02T05:31:50.000Z","size":30627,"stargazers_count":295,"open_issues_count":1,"forks_count":110,"subscribers_count":57,"default_branch":"main","last_synced_at":"2025-03-28T09:09:23.066Z","etag":null,"topics":["asynchronous","high-performance","http","http-client","http-server","http2","kotlin","oauth2","reactive","reactive-programming","tcp","tls","web","web-framework","websocket"],"latest_commit_sha":null,"homepage":"http://www.fireflysource.com/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hypercube1024.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-02-16T09:04:05.000Z","updated_at":"2025-02-07T11:44:23.000Z","dependencies_parsed_at":"2023-11-13T17:25:16.099Z","dependency_job_id":"1049f15b-3c6d-41e7-ac23-ad15890cdeda","html_url":"https://github.com/hypercube1024/firefly","commit_stats":{"total_commits":3226,"total_committers":3,"mean_commits":"1075.3333333333333","dds":0.001239925604463732,"last_synced_commit":"8b205148cbe8c7e72a341e7cbff17cfe04fdae4c"},"previous_names":[],"tags_count":61,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypercube1024%2Ffirefly","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypercube1024%2Ffirefly/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypercube1024%2Ffirefly/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypercube1024%2Ffirefly/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hypercube1024","download_url":"https://codeload.github.com/hypercube1024/firefly/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247157283,"owners_count":20893220,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asynchronous","high-performance","http","http-client","http-server","http2","kotlin","oauth2","reactive","reactive-programming","tcp","tls","web","web-framework","websocket"],"created_at":"2024-09-24T20:45:23.783Z","updated_at":"2025-04-04T10:09:52.124Z","avatar_url":"https://github.com/hypercube1024.png","language":"Java","readme":"# What is Firefly?\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/hypercube1024/firefly/maven.yml)](https://github.com/hypercube1024/firefly)\n[![Maven Central](https://img.shields.io/maven-central/v/com.fireflysource/firefly-net)](https://search.maven.org/artifact/com.fireflysource/firefly-net/)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\nFirefly framework is an asynchronous Java web framework. It helps you create a web application ***Easy*** and ***Quickly***. \nIt provides asynchronous HTTP, Websocket, TCP Server/Client, and many other useful components for developing\nweb applications, protocol servers, etc. That means you can easy deploy your web without any other java web containers,\nin short, it's containerless. Using Kotlin coroutines, Firefly is truly asynchronous and highly scalable. It taps into\nthe fullest potential of hardware. Use the power of non-blocking development without the callback nightmare.\n\nFirefly core provides functionality for things like:\n\n- HTTP server and client\n- WebSocket server and client\n- HTTP, Socks proxy\n- HTTP Gateway\n- TCP server and client\n- UDP server and client\n\n# Event driven\nThe Firefly APIs are largely event-driven. It means that when things happen in Firefly that you are interested in,\nFirefly will call you by sending you events.\n\nSome example events are:\n- some data has arrived on a socket\n- an HTTP server has received a request\n\nFirefly handles a lot of concurrencies using just a small number of threads, so ***don't block Firefly thread***, you\nmust manage blocking call in the standalone thread pool.\n\nWith a conventional blocking API the calling thread might block when:\n- Thread.sleep()\n- Waiting on a Lock\n- Waiting on a mutex or monitor\n- Doing a long-lived database operation and waiting for a result\n- Call blocking I/O APIs\n\nIn all the above cases, when your thread is waiting for a result it can’t do anything else - it’s effectively useless.\n\nIt means that if you want a lot of concurrencies using blocking APIs, then you need a lot of threads to prevent your\napplication grinding to a halt.\n\nThreads have overhead regarding the memory they require (e.g. for their stack) and in context switching.\n\nFor the levels of concurrency required in many modern applications, a blocking approach just doesn’t scale.\n\n# Quick start\nAdd maven dependency in your pom.xml.\n```xml\n\u003cdependencics\u003e\n    \u003cdependency\u003e\n        \u003cgroupId\u003ecom.fireflysource\u003c/groupId\u003e\n        \u003cartifactId\u003efirefly-net\u003c/artifactId\u003e\n        \u003cversion\u003e5.0.2\u003c/version\u003e\n    \u003c/dependency\u003e\n\n    \u003cdependency\u003e\n        \u003cgroupId\u003ecom.fireflysource\u003c/groupId\u003e\n        \u003cartifactId\u003efirefly-slf4j\u003c/artifactId\u003e\n        \u003cversion\u003e5.0.2\u003c/version\u003e\n    \u003c/dependency\u003e\n\u003c/dependencics\u003e\n```\n\nAdd log configuration file \"firefly-log.xml\" to the classpath.\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003cloggers xmlns=\"http://www.fireflysource.com/loggers\"\n         xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n         xsi:schemaLocation=\"http://www.fireflysource.com/loggers http://www.fireflysource.com/loggers.xsd\"\u003e\n    \u003clogger\u003e\n        \u003cname\u003efirefly-system\u003c/name\u003e\n        \u003clevel\u003eINFO\u003c/level\u003e\n        \u003cpath\u003elogs\u003c/path\u003e\n    \u003c/logger\u003e\n\u003c/loggers\u003e\n```\n\nHTTP server and client example:\n```kotlin\nfun main() {\n    `$`.httpServer()\n        .router().get(\"/\").handler { ctx -\u003e ctx.end(\"Hello http! \") }\n        .listen(\"localhost\", 8090)\n\n    `$`.httpClient().get(\"http://localhost:8090/\").submit()\n        .thenAccept { response -\u003e println(response.stringBody) }\n}\n```\n\nWebSocket server and client example:\n```kotlin\nfun main() {\n    `$`.httpServer().websocket(\"/websocket/hello\")\n        .onServerMessageAsync { frame, _ -\u003e onMessage(frame) }\n        .onAcceptAsync { connection -\u003e sendMessage(\"Server\", connection) }\n        .listen(\"localhost\", 8090)\n\n    val url = \"ws://localhost:8090\"\n    `$`.httpClient().websocket(\"$url/websocket/hello\")\n        .onClientMessageAsync { frame, _ -\u003e onMessage(frame) }\n        .connectAsync { connection -\u003e sendMessage(\"Client\", connection) }\n}\n\nprivate suspend fun sendMessage(data: String, connection: WebSocketConnection) = connection.useAwait {\n    (1..10).forEach {\n        connection.sendText(\"WebSocket ${data}. count: $it, time: ${Date()}\")\n        delay(1000)\n    }\n}\n\nprivate fun onMessage(frame: Frame) {\n    if (frame is TextFrame) {\n        println(frame.payloadAsUTF8)\n    }\n}\n```\n\nTCP server and client example:\n```kotlin\nfun main() {\n    `$`.tcpServer().onAcceptAsync { connection -\u003e\n        launch { writeLoop(\"Server\", connection) }\n        launch { readLoop(connection) }\n    }.listen(\"localhost\", 8090)\n\n    `$`.tcpClient().connectAsync(\"localhost\", 8090) { connection -\u003e\n        launch { writeLoop(\"Client\", connection) }\n        launch { readLoop(connection) }\n    }\n}\n\nprivate suspend fun readLoop(connection: TcpConnection) = connection.useAwait {\n    while (true) {\n        try {\n            val buffer = connection.read().await()\n            println(BufferUtils.toString(buffer))\n        } catch (e: Exception) {\n            println(\"Connection closed.\")\n            break\n        }\n    }\n}\n\nprivate suspend fun writeLoop(data: String, connection: TcpConnection) = connection.useAwait {\n    (1..10).forEach {\n        connection.write(toBuffer(\"TCP ${data}. count: $it, time: ${Date()}\"))\n        delay(1000)\n    }\n}\n```\n\n# Contact information\n- E-mail: qptkk@163.com\n- QQ Group: 126079579\n- Wechat: AlvinQiu\n","funding_links":[],"categories":["开发框架"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhypercube1024%2Ffirefly","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhypercube1024%2Ffirefly","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhypercube1024%2Ffirefly/lists"}