amqpr_api/queue/
bind.rs

1use amqpr_codec::{Frame, FrameHeader, FramePayload, AmqpString};
2use amqpr_codec::method::MethodPayload;
3use amqpr_codec::method::queue::{QueueClass, BindMethod};
4
5use futures::sink::{Sink, Send};
6
7use std::collections::HashMap;
8
9
10pub type QueueBound<S> = Send<S>;
11
12
13/// Bind a queue asynchronously.
14/// That means we won't wait to receive `Declare-Ok` method after send `Declare` method.
15pub fn bind_queue<S>(channel_id: u16, socket: S, option: BindQueueOption) -> QueueBound<S>
16where
17    S: Sink<SinkItem = Frame>,
18{
19    let bind = BindMethod {
20        reserved1: 0,
21        queue: option.queue,
22        exchange: option.exchange,
23        routing_key: option.routing_key,
24        no_wait: true,
25        arguments: HashMap::new(),
26    };
27
28    let frame = Frame {
29        header: FrameHeader { channel: channel_id },
30        payload: FramePayload::Method(MethodPayload::Queue(QueueClass::Bind(bind))),
31    };
32
33    socket.send(frame)
34}
35
36
37
38pub struct BindQueueOption {
39    pub queue: AmqpString,
40    pub exchange: AmqpString,
41    pub routing_key: AmqpString,
42}