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    /// Manager-owned local queue, accessed directly over HTTP.
23    #[serde(rename = "local-queue-http")]
24    LocalHttp(LocalHttpQueueBinding),
25}
26
27impl QueueBinding {
28    pub fn sqs(queue_url: impl Into<BindingValue<String>>) -> Self {
29        Self::Sqs(SqsQueueBinding {
30            queue_url: queue_url.into(),
31        })
32    }
33
34    pub fn pubsub(
35        topic: impl Into<BindingValue<String>>,
36        subscription: impl Into<BindingValue<String>>,
37    ) -> Self {
38        Self::Pubsub(PubSubQueueBinding {
39            topic: topic.into(),
40            subscription: subscription.into(),
41        })
42    }
43
44    pub fn service_bus(
45        namespace: impl Into<BindingValue<String>>,
46        queue_name: impl Into<BindingValue<String>>,
47    ) -> Self {
48        Self::Servicebus(ServiceBusQueueBinding {
49            namespace: namespace.into(),
50            queue_name: queue_name.into(),
51        })
52    }
53
54    pub fn local(queue_path: impl Into<BindingValue<String>>) -> Self {
55        Self::Local(LocalQueueBinding {
56            queue_path: queue_path.into(),
57        })
58    }
59}
60
61/// AWS SQS queue parameters
62#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
63#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
64#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
65#[serde(rename_all = "camelCase")]
66pub struct SqsQueueBinding {
67    /// Full SQS queue URL
68    pub queue_url: BindingValue<String>,
69}
70
71/// GCP Pub/Sub parameters
72#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
73#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
74#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
75#[serde(rename_all = "camelCase")]
76pub struct PubSubQueueBinding {
77    /// Full topic name: projects/{project}/topics/{topic}
78    pub topic: BindingValue<String>,
79    /// Full subscription name: projects/{project}/subscriptions/{subscription}
80    pub subscription: BindingValue<String>,
81}
82
83/// Azure Service Bus parameters
84#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
85#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
86#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
87#[serde(rename_all = "camelCase")]
88pub struct ServiceBusQueueBinding {
89    /// Namespace name
90    pub namespace: BindingValue<String>,
91    /// Queue name
92    pub queue_name: BindingValue<String>,
93}
94
95/// Local queue parameters
96#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
97#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
98#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
99#[serde(rename_all = "camelCase")]
100pub struct LocalQueueBinding {
101    /// Path to the queue's data directory; the `localqueue.v1` SQLite database
102    /// (`localqueue.sqlite`) lives inside it
103    pub queue_path: BindingValue<String>,
104}
105
106/// Connection to one manager-owned local queue. Old SDKs reject its distinct service tag.
107#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
108#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
109#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
110#[serde(rename_all = "camelCase")]
111pub struct LocalHttpQueueBinding {
112    /// Queue operation endpoint on the existing manager listener.
113    pub endpoint: BindingValue<String>,
114    /// Queue-scoped credential, injected at process start rather than persisted in stack state.
115    #[serde(default, skip_serializing_if = "Option::is_none")]
116    pub token: Option<String>,
117}