-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from hit-box/tokio-backend
Tokio backend
- Loading branch information
Showing
62 changed files
with
1,649 additions
and
603 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use actix::prelude::*; | ||
use actix_derive::MessageResponse; | ||
use hitbox::{hitbox_serializer, CachePolicy, Cacheable, CacheableResponse}; | ||
use hitbox_actix::{Cache, CacheError, IntoCache}; | ||
use metrics_exporter_prometheus::PrometheusBuilder; | ||
|
||
#[derive(Default)] | ||
struct UpstreamActor; | ||
|
||
impl Actor for UpstreamActor { | ||
type Context = Context<Self>; | ||
} | ||
|
||
#[derive(Message, Cacheable, serde::Serialize)] | ||
#[rtype(result = "Pong")] | ||
struct Ping { | ||
number: u8, | ||
} | ||
|
||
impl Ping { | ||
fn new(number: u8) -> Self { | ||
Self { number } | ||
} | ||
} | ||
|
||
#[derive(Debug, serde::Serialize, serde::Deserialize, MessageResponse, CacheableResponse)] | ||
struct Pong { | ||
number: u8, | ||
} | ||
|
||
impl Handler<Ping> for UpstreamActor { | ||
type Result = MessageResult<Ping>; | ||
|
||
fn handle(&mut self, msg: Ping, _: &mut Self::Context) -> Self::Result { | ||
MessageResult(Pong { number: msg.number }) | ||
} | ||
} | ||
|
||
#[actix::main] | ||
async fn main() { | ||
let upstream = UpstreamActor::default().start(); | ||
let cache = Cache::new().await.unwrap().start(); | ||
let recorder = PrometheusBuilder::new() | ||
.install_recorder() | ||
.expect("failed to install recorder"); | ||
|
||
let _pong_0 = cache | ||
.send(Ping::new(0).into_cache(&upstream)) | ||
.await | ||
.expect("actix mailbox timeout/closed") | ||
.expect("cache actor error"); | ||
|
||
let _again_pong_0 = cache | ||
.send(Ping::new(0).into_cache(&upstream)) | ||
.await | ||
.expect("actix mailbox timeout/closed") | ||
.expect("cache actor error"); | ||
|
||
let _pong_1 = cache | ||
.send(Ping::new(1).into_cache(&upstream)) | ||
.await | ||
.expect("actix mailbox timeout/closed") | ||
.expect("cache actor error"); | ||
|
||
println!("{}", recorder.render()); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use std::{convert::Infallible, net::SocketAddr}; | ||
use hyper::{Body, Server}; | ||
|
||
use tower::make::Shared; | ||
use http::{Request, Response}; | ||
|
||
async fn handle(_: Request<Body>) -> Result<Response<Body>, Infallible> { | ||
Ok(Response::new("Hello, World!".into())) | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let service = tower::ServiceBuilder::new() | ||
.layer(tower_http::trace::TraceLayer::new_for_http()) | ||
.service_fn(handle); | ||
|
||
let addr = SocketAddr::from(([127, 0, 0, 1], 3000)); | ||
Server::bind(&addr) | ||
.serve(Shared::new(service)) | ||
.await | ||
.expect("server error"); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ name = "hitbox-actix" | |
version = "0.1.0" | ||
authors = ["Belousow Makc <[email protected]>", "Andrey Ermilov <[email protected]>"] | ||
license = "MIT" | ||
edition = "2018" | ||
edition = "2021" | ||
description = "Asynchronous caching framework for Actix." | ||
readme = "README.md" | ||
repository = "https://github.com/hit-box/hitbox/" | ||
|
@@ -16,10 +16,11 @@ keywords = ["cache", "actix", "async", "cache-backend", "hitbox"] | |
hitbox = { path = "../hitbox", version = "0.1.0" } | ||
hitbox-backend = { path = "../hitbox-backend", version = "0.1.0" } | ||
hitbox-redis = { path = "../hitbox-redis", version = "0.1.0", optional = true } | ||
actix = { version = "0.12" } | ||
actix = { version = "0.13" } | ||
serde = { version = "1", features = ["derive"] } | ||
tracing = "0.1" | ||
serde_json = "1.0.64" | ||
async-trait = "0.1.52" | ||
|
||
[features] | ||
default = ["redis", "derive"] | ||
|
Oops, something went wrong.