basilisk_rust_client/
protocol.rs1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use std::collections::HashMap;
4
5pub mod protocol_types {
7 pub const CONNECT: &str = "connect";
9
10 pub const SUBSCRIBE: &str = "subscribe";
12 pub const UNSUBSCRIBE: &str = "unsubscribe";
14 pub const PUBLISH: &str = "publish";
16 pub const FORWARD: &str = "forward";
18 pub const FORWARD_RESPONSE: &str = "forward_response";
20 pub const EVENT: &str = "event";
22 pub const ACK: &str = "ack";
24 pub const ERROR: &str = "error";
26}
27
28#[derive(Debug, Serialize, Deserialize, Clone)]
30pub struct ServiceBusEventEnvelope {
31 #[serde(rename = "eventId")]
33 pub event_id: String,
34 #[serde(rename = "emittedAtUtc")]
36 pub emitted_at_utc: DateTime<Utc>,
37 #[serde(rename = "serviceId")]
39 pub service_id: String,
40 #[serde(rename = "instanceId")]
42 pub instance_id: String,
43 pub topic: String,
45 #[serde(rename = "messageType")]
47 pub message_type: String,
48 #[serde(rename = "correlationId")]
50 pub correlation_id: i64,
51 #[serde(rename = "causationId")]
53 pub causation_id: Option<String>,
54 #[serde(default)]
56 pub payload: HashMap<String, serde_json::Value>,
57}
58
59#[derive(Debug, Serialize, Deserialize, Clone)]
61pub struct ServiceBusForwardRequest {
62 #[serde(rename = "targetServiceId")]
64 pub target_service_id: String,
65 #[serde(rename = "messageType")]
67 pub message_type: String,
68 #[serde(default)]
70 pub payload: HashMap<String, serde_json::Value>,
71 #[serde(rename = "timeoutMs")]
73 pub timeout_ms: Option<u64>,
74}
75
76#[derive(Debug, Serialize, Deserialize, Clone)]
78pub struct ServiceBusForwardResponse {
79 #[serde(rename = "messageType")]
81 pub message_type: String,
82 #[serde(default)]
84 pub payload: HashMap<String, serde_json::Value>,
85}
86
87#[derive(Debug, Serialize, Deserialize, Clone, Default)]
89pub struct ServiceBusProtocolMessage {
90 pub r#type: String,
92 #[serde(rename = "serviceId")]
94 pub service_id: Option<String>,
95 #[serde(rename = "instanceId")]
97 pub instance_id: Option<String>,
98 pub token: Option<String>,
100 pub topics: Option<Vec<String>>,
102 pub event: Option<ServiceBusEventEnvelope>,
104 #[serde(rename = "forwardRequest")]
106 pub forward_request: Option<ServiceBusForwardRequest>,
107 #[serde(rename = "forwardResponse")]
109 pub forward_response: Option<ServiceBusForwardResponse>,
110 pub message: Option<String>,
112 #[serde(rename = "errorCode")]
114 pub error_code: Option<String>,
115 #[serde(rename = "subscriberCount")]
117 pub subscriber_count: Option<i32>,
118}