Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
95 additions
and
104 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
|
||
pub mod create; | ||
|
||
pub(crate) mod types; | ||
pub(crate) mod rmq_ops; |
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,64 @@ | ||
use lapin::{Result as LAResult, protocol::basic::AMQPProperties}; | ||
use amq_protocol_types::{FieldTable}; | ||
|
||
use log::info; | ||
|
||
use fabseal_micro_common::{FABSEAL_EXCHANGE, FABSEAL_QUEUE}; | ||
|
||
pub(crate) async fn rmq_declare( | ||
pool: bb8::Pool<bb8_lapin::LapinConnectionManager> | ||
) -> LAResult<()> { | ||
let conn = pool.get().await.unwrap(); | ||
let channel = conn.create_channel() | ||
.await | ||
.unwrap(); | ||
|
||
info!("CONNECTED"); | ||
|
||
let queue = channel | ||
.queue_declare( | ||
FABSEAL_QUEUE, | ||
lapin::options::QueueDeclareOptions::default(), | ||
FieldTable::default(), | ||
) | ||
.await?; | ||
|
||
info!("Declared queue {:?}", queue); | ||
|
||
Ok(()) | ||
} | ||
|
||
|
||
lazy_static::lazy_static! { | ||
static ref PROPS: AMQPProperties = { | ||
lapin::BasicProperties::default() | ||
.with_content_type("application/json".into()) | ||
}; | ||
static ref PUBLISH_OPTIONS: lapin::options::BasicPublishOptions = { | ||
lapin::options::BasicPublishOptions::default() | ||
}; | ||
} | ||
|
||
pub(crate) async fn rmq_publish( | ||
conn: bb8::PooledConnection<'_, bb8_lapin::LapinConnectionManager>, | ||
payload: Vec<u8>, | ||
) -> LAResult<()> { | ||
let channel = conn.create_channel() | ||
.await | ||
.unwrap(); | ||
|
||
let confirm = channel.basic_publish( | ||
FABSEAL_EXCHANGE, | ||
FABSEAL_QUEUE, | ||
*PUBLISH_OPTIONS, | ||
payload, | ||
PROPS.clone() | ||
) | ||
.await? | ||
.await?; | ||
|
||
debug_assert_eq!(confirm, lapin::publisher_confirm::Confirmation::NotRequested); | ||
|
||
|
||
Ok(()) | ||
} |
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,22 @@ | ||
use serde::{Deserialize}; | ||
|
||
#[derive(Deserialize, Debug)] | ||
pub(crate) struct RequestInfo { | ||
request_id: i32, | ||
} | ||
|
||
#[derive(Deserialize, Debug)] | ||
#[serde(rename_all(deserialize = "lowercase"))] | ||
pub(crate) enum ResultType { | ||
Model, | ||
Heightmap | ||
} | ||
|
||
|
||
#[derive(Deserialize, Debug)] | ||
pub(crate) struct ResultRequestInfo { | ||
request_id: i32, | ||
#[serde(rename = "type")] | ||
pub(crate) result_type: ResultType, | ||
} | ||
|