1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
// Copyright {{.Year}} Conductor OSS
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
use crate::error::Result;
use crate::http::{ApiClient, ApiPath};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
/// Client for event operations (queue configurations).
#[derive(Clone)]
pub struct EventClient {
api: ApiClient,
}
/// Queue configuration for event handling.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct QueueConfiguration {
/// Queue name (e.g., topic name for Kafka).
pub queue_name: String,
/// Queue type (e.g., "kafka", "sqs", "amqp").
pub queue_type: String,
/// Queue-specific configuration.
#[serde(default)]
pub configuration: serde_json::Value,
}
impl QueueConfiguration {
/// Create a new queue configuration.
pub fn new(queue_type: impl Into<String>, queue_name: impl Into<String>) -> Self {
Self {
queue_name: queue_name.into(),
queue_type: queue_type.into(),
configuration: serde_json::Value::Null,
}
}
/// Create a Kafka queue configuration.
pub fn kafka(topic: impl Into<String>) -> Self {
Self::new("kafka", topic)
}
/// Create an SQS queue configuration.
pub fn sqs(queue_url: impl Into<String>) -> Self {
Self::new("sqs", queue_url)
}
/// Create an AMQP queue configuration.
pub fn amqp(queue_name: impl Into<String>) -> Self {
Self::new("amqp_queue", queue_name)
}
/// Set the configuration.
#[must_use]
pub fn with_configuration(mut self, config: serde_json::Value) -> Self {
self.configuration = config;
self
}
}
impl EventClient {
/// Create a new event client.
#[must_use]
pub fn new(api: ApiClient) -> Self {
Self { api }
}
/// Delete a queue configuration.
///
/// # Errors
///
/// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, or an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status.
pub async fn delete_queue_configuration(
&self,
queue_config: &QueueConfiguration,
) -> Result<()> {
let path = format!(
"/event/queue/config/{}/{}",
queue_config.queue_type, queue_config.queue_name
);
self.api
.delete_no_content(ApiPath::templated(
&path,
"/event/queue/config/{queueType}/{queueName}",
))
.await
}
/// Get a Kafka queue configuration by topic.
///
/// # Errors
///
/// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
pub async fn get_kafka_queue_configuration(
&self,
queue_topic: &str,
) -> Result<QueueConfiguration> {
self.get_queue_configuration("kafka", queue_topic).await
}
/// Get a queue configuration by type and name.
///
/// # Errors
///
/// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
pub async fn get_queue_configuration(
&self,
queue_type: &str,
queue_name: &str,
) -> Result<QueueConfiguration> {
let path = format!("/event/queue/config/{queue_type}/{queue_name}");
self.api
.get(ApiPath::templated(
&path,
"/event/queue/config/{queueType}/{queueName}",
))
.await
}
/// Create or update a queue configuration.
///
/// # Errors
///
/// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, or an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status.
pub async fn put_queue_configuration(&self, queue_config: &QueueConfiguration) -> Result<()> {
let path = format!(
"/event/queue/config/{}/{}",
queue_config.queue_type, queue_config.queue_name
);
self.api
.put_no_response(
ApiPath::templated(&path, "/event/queue/config/{queueType}/{queueName}"),
&queue_config.configuration,
)
.await
}
/// Get all queue configurations
///
/// Unlike `get_queue_configuration`, the server's "get all" endpoint
/// (`GET /event/queue/config`) returns a `{queueIdentifier: value}` object
/// rather than a list of `QueueConfiguration`. The `HashMap<String, String>`
/// here matches the server signature exactly: Orkes declares
/// `Map<String, String> getQueueNames()` in `EventResource`.
///
/// That method returns a hardcoded `Map.of()` -- queue/broker integrations
/// moved to the Integrations API and the sibling `putQueueConfig` is
/// `@Deprecated(forRemoval = true)` -- so in practice this is always empty on
/// Orkes. Plain OSS Conductor has no queue-config routes at all
/// (`rest/.../EventResource.java` maps only the event-handler endpoints), so
/// it answers 404.
///
/// # Errors
///
/// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
pub async fn get_all_queue_configurations(&self) -> Result<HashMap<String, String>> {
self.api.get("/event/queue/config").await
}
/// Get event handlers for a specific event.
///
/// # Errors
///
/// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status, or [`crate::error::ConductorError::Json`] if the response body can't be deserialized.
pub async fn get_event_handlers(
&self,
event: &str,
active_only: bool,
) -> Result<Vec<serde_json::Value>> {
let path = format!(
"/event/{}?activeOnly={}",
urlencoding::encode(event),
active_only
);
self.api
.get(ApiPath::templated(&path, "/event/{event}"))
.await
}
/// Get all event handlers.
///
/// # Errors
///
/// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, or an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status.
pub async fn get_all_event_handlers(&self) -> Result<Vec<serde_json::Value>> {
self.api.get("/event").await
}
/// Register an event handler.
///
/// # Errors
///
/// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, or an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status.
pub async fn register_event_handler(&self, event_handler: &serde_json::Value) -> Result<()> {
self.api.post_no_response("/event", event_handler).await
}
/// Update an event handler.
///
/// # Errors
///
/// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, or an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status.
pub async fn update_event_handler(&self, event_handler: &serde_json::Value) -> Result<()> {
self.api.put_no_response("/event", event_handler).await
}
/// Remove an event handler.
///
/// # Errors
///
/// Returns [`crate::error::ConductorError::Http`] if the request fails at the transport level, or an [`crate::error::ConductorError::Auth`]/[`crate::error::ConductorError::Api`]/[`crate::error::ConductorError::Server`] variant if the server responds with a non-2xx status.
pub async fn remove_event_handler(&self, name: &str) -> Result<()> {
let path = format!("/event/{name}");
self.api
.delete_no_content(ApiPath::templated(&path, "/event/{event}"))
.await
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::Configuration;
#[test]
fn test_event_client_creation() {
let config = Configuration::new("http://localhost:8080/api");
let api = ApiClient::new(config).unwrap();
let _client = EventClient::new(api);
}
#[test]
fn test_queue_configuration() {
let kafka_config = QueueConfiguration::kafka("my-topic");
assert_eq!(kafka_config.queue_type, "kafka");
assert_eq!(kafka_config.queue_name, "my-topic");
let sqs_config =
QueueConfiguration::sqs("https://sqs.us-east-1.amazonaws.com/123/my-queue");
assert_eq!(sqs_config.queue_type, "sqs");
}
}