Skip to main content

alien_core/bindings/
queue.rs

1use super::BindingValue;
2use serde::{Deserialize, Serialize};
3
4/// Binding parameters for Queue at runtime or in templates.
5#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
6#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
7#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
8#[serde(tag = "service", rename_all = "lowercase")]
9pub enum QueueBinding {
10    /// AWS SQS binding
11    #[serde(rename_all = "camelCase")]
12    Sqs(SqsQueueBinding),
13    /// GCP Pub/Sub binding
14    #[serde(rename_all = "camelCase")]
15    Pubsub(PubSubQueueBinding),
16    /// Azure Service Bus binding
17    #[serde(rename_all = "camelCase")]
18    Servicebus(ServiceBusQueueBinding),
19    /// Local development queue binding
20    #[serde(rename = "local-queue", rename_all = "camelCase")]
21    Local(LocalQueueBinding),
22}
23
24impl QueueBinding {
25    pub fn sqs(queue_url: impl Into<BindingValue<String>>) -> Self {
26        Self::Sqs(SqsQueueBinding {
27            queue_url: queue_url.into(),
28        })
29    }
30
31    pub fn pubsub(
32        topic: impl Into<BindingValue<String>>,
33        subscription: impl Into<BindingValue<String>>,
34    ) -> Self {
35        Self::Pubsub(PubSubQueueBinding {
36            topic: topic.into(),
37            subscription: subscription.into(),
38        })
39    }
40
41    pub fn service_bus(
42        namespace: impl Into<BindingValue<String>>,
43        queue_name: impl Into<BindingValue<String>>,
44    ) -> Self {
45        Self::Servicebus(ServiceBusQueueBinding {
46            namespace: namespace.into(),
47            queue_name: queue_name.into(),
48        })
49    }
50
51    pub fn local(queue_path: impl Into<BindingValue<String>>) -> Self {
52        Self::Local(LocalQueueBinding {
53            queue_path: queue_path.into(),
54        })
55    }
56}
57
58/// AWS SQS queue parameters
59#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
60#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
61#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
62#[serde(rename_all = "camelCase")]
63pub struct SqsQueueBinding {
64    /// Full SQS queue URL
65    pub queue_url: BindingValue<String>,
66}
67
68/// GCP Pub/Sub parameters
69#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
70#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
71#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
72#[serde(rename_all = "camelCase")]
73pub struct PubSubQueueBinding {
74    /// Full topic name: projects/{project}/topics/{topic}
75    pub topic: BindingValue<String>,
76    /// Full subscription name: projects/{project}/subscriptions/{subscription}
77    pub subscription: BindingValue<String>,
78}
79
80/// Azure Service Bus parameters
81#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
82#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
83#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
84#[serde(rename_all = "camelCase")]
85pub struct ServiceBusQueueBinding {
86    /// Namespace name
87    pub namespace: BindingValue<String>,
88    /// Queue name
89    pub queue_name: BindingValue<String>,
90}
91
92/// Local queue parameters
93#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
94#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
95#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
96#[serde(rename_all = "camelCase")]
97pub struct LocalQueueBinding {
98    /// Path to the sled database directory for the queue
99    pub queue_path: BindingValue<String>,
100}