|
11 | 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | 12 | // See the License for the specific language governing permissions and |
13 | 13 | // limitations under the License. |
14 | | -use crate::commons::{ExchangeType, PolicyTarget, QueueType}; |
| 14 | +use crate::commons::{ExchangeType, PolicyTarget, QueueType, ShovelAcknowledgementMode}; |
15 | 15 | use serde::{Deserialize, Serialize}; |
16 | 16 | use serde_json::{json, Map, Value}; |
17 | 17 |
|
@@ -373,10 +373,10 @@ pub type RuntimeParameterValue = Map<String, Value>; |
373 | 373 |
|
374 | 374 | /// Represents a [runtime parameter](https://rabbitmq.com/docs/parameters/). |
375 | 375 | #[derive(Serialize, Deserialize)] |
376 | | -pub struct RuntimeParameterDefinition { |
377 | | - pub name: String, |
378 | | - pub vhost: String, |
379 | | - pub component: String, |
| 376 | +pub struct RuntimeParameterDefinition<'a> { |
| 377 | + pub name: &'a str, |
| 378 | + pub vhost: &'a str, |
| 379 | + pub component: &'a str, |
380 | 380 | pub value: RuntimeParameterValue, |
381 | 381 | } |
382 | 382 |
|
@@ -404,6 +404,136 @@ pub struct Permissions<'a> { |
404 | 404 | pub write: &'a str, |
405 | 405 | } |
406 | 406 |
|
| 407 | +pub(crate) const SHOVEL_COMPONENT: &str = "shovel"; |
| 408 | + |
| 409 | +/// Represents a dynamic shovel definition. |
| 410 | +#[derive(Serialize)] |
| 411 | +pub struct Amqp091ShovelParams<'a> { |
| 412 | + pub name: &'a str, |
| 413 | + pub vhost: &'a str, |
| 414 | + |
| 415 | + pub acknowledgement_mode: ShovelAcknowledgementMode, |
| 416 | + pub reconnect_delay: Option<u16>, |
| 417 | + |
| 418 | + pub source: Amqp091ShovelSourceParams<'a>, |
| 419 | + pub destination: Amqp091ShovelDestinationParams<'a>, |
| 420 | +} |
| 421 | + |
| 422 | +impl<'a> From<Amqp091ShovelParams<'a>> for RuntimeParameterDefinition<'a> { |
| 423 | + fn from(params: Amqp091ShovelParams<'a>) -> Self { |
| 424 | + let mut value = Map::new(); |
| 425 | + |
| 426 | + value.insert("src-uri".to_owned(), json!(params.source.source_uri)); |
| 427 | + if let Some(sq) = params.source.source_queue { |
| 428 | + value.insert("src-queue".to_owned(), json!(sq)); |
| 429 | + } |
| 430 | + if let Some(sx) = params.source.source_exchange { |
| 431 | + value.insert("src-exchange".to_owned(), json!(sx)); |
| 432 | + } |
| 433 | + if let Some(sxrk) = params.source.source_exchange_routing_key { |
| 434 | + value.insert("src-exchange-key".to_owned(), json!(sxrk)); |
| 435 | + } |
| 436 | + |
| 437 | + value.insert( |
| 438 | + "dest-uri".to_owned(), |
| 439 | + json!(params.destination.destination_uri), |
| 440 | + ); |
| 441 | + value.insert("ack-mode".to_owned(), json!(params.acknowledgement_mode)); |
| 442 | + |
| 443 | + if let Some(dq) = params.destination.destination_queue { |
| 444 | + value.insert("dest-queue".to_owned(), json!(dq)); |
| 445 | + } |
| 446 | + if let Some(dx) = params.destination.destination_exchange { |
| 447 | + value.insert("dest-exchange".to_owned(), json!(dx)); |
| 448 | + } |
| 449 | + if let Some(dxrk) = params.destination.destination_exchange_routing_key { |
| 450 | + value.insert("dest-exchange-key".to_owned(), json!(dxrk)); |
| 451 | + } |
| 452 | + |
| 453 | + if let Some(val) = params.reconnect_delay { |
| 454 | + value.insert("reconnect-delay".to_owned(), json!(val)); |
| 455 | + } |
| 456 | + |
| 457 | + Self { |
| 458 | + name: params.name, |
| 459 | + vhost: params.vhost, |
| 460 | + component: SHOVEL_COMPONENT, |
| 461 | + value, |
| 462 | + } |
| 463 | + } |
| 464 | +} |
| 465 | + |
| 466 | +#[derive(Serialize)] |
| 467 | +pub struct Amqp091ShovelSourceParams<'a> { |
| 468 | + pub source_uri: &'a str, |
| 469 | + |
| 470 | + pub source_queue: Option<&'a str>, |
| 471 | + |
| 472 | + pub source_exchange: Option<&'a str>, |
| 473 | + pub source_exchange_routing_key: Option<&'a str>, |
| 474 | +} |
| 475 | + |
| 476 | +impl<'a> Amqp091ShovelSourceParams<'a> { |
| 477 | + pub fn queue_source(source_uri: &'a str, source_queue: &'a str) -> Self { |
| 478 | + Self { |
| 479 | + source_uri, |
| 480 | + source_queue: Some(source_queue), |
| 481 | + |
| 482 | + source_exchange: None, |
| 483 | + source_exchange_routing_key: None, |
| 484 | + } |
| 485 | + } |
| 486 | + |
| 487 | + pub fn exchange_source( |
| 488 | + source_uri: &'a str, |
| 489 | + source_exchange: &'a str, |
| 490 | + source_exchange_routing_key: Option<&'a str>, |
| 491 | + ) -> Self { |
| 492 | + Self { |
| 493 | + source_uri, |
| 494 | + source_exchange: Some(source_exchange), |
| 495 | + source_exchange_routing_key, |
| 496 | + |
| 497 | + source_queue: None, |
| 498 | + } |
| 499 | + } |
| 500 | +} |
| 501 | + |
| 502 | +#[derive(Serialize)] |
| 503 | +pub struct Amqp091ShovelDestinationParams<'a> { |
| 504 | + pub destination_uri: &'a str, |
| 505 | + |
| 506 | + pub destination_queue: Option<&'a str>, |
| 507 | + pub destination_exchange: Option<&'a str>, |
| 508 | + pub destination_exchange_routing_key: Option<&'a str>, |
| 509 | +} |
| 510 | + |
| 511 | +impl<'a> Amqp091ShovelDestinationParams<'a> { |
| 512 | + pub fn queue_destination(destination_uri: &'a str, destination_queue: &'a str) -> Self { |
| 513 | + Self { |
| 514 | + destination_uri, |
| 515 | + destination_queue: Some(destination_queue), |
| 516 | + |
| 517 | + destination_exchange: None, |
| 518 | + destination_exchange_routing_key: None, |
| 519 | + } |
| 520 | + } |
| 521 | + |
| 522 | + pub fn exchange_destination( |
| 523 | + destination_uri: &'a str, |
| 524 | + destination_exchange: &'a str, |
| 525 | + destination_exchange_routing_key: Option<&'a str>, |
| 526 | + ) -> Self { |
| 527 | + Self { |
| 528 | + destination_uri, |
| 529 | + destination_exchange: Some(destination_exchange), |
| 530 | + destination_exchange_routing_key, |
| 531 | + |
| 532 | + destination_queue: None, |
| 533 | + } |
| 534 | + } |
| 535 | +} |
| 536 | + |
407 | 537 | pub type MessageProperties = Map<String, Value>; |
408 | 538 |
|
409 | 539 | #[derive(Serialize, Default)] |
|
0 commit comments