lapin_futures/
channel.rs

1use crate::{
2    message::{BasicGetMessage, BasicReturnMessage},
3    options::*,
4    types::{Boolean, FieldTable, LongUInt, ShortUInt},
5    BasicProperties, ConfirmationFuture, Consumer, Error, ExchangeKind, Queue, Result,
6};
7use futures::Future;
8use lapin::{Channel as InnerChannel, Connection};
9
10/// `Channel` provides methods to act on a channel, such as managing queues
11#[derive(Clone)]
12#[deprecated(note = "use lapin instead")]
13pub struct Channel {
14    inner: InnerChannel,
15}
16
17impl Channel {
18    /// create a channel
19    #[deprecated(note = "use lapin instead")]
20    pub fn create(conn: &Connection) -> impl Future<Item = Self, Error = Error> {
21        let confirmation: ConfirmationFuture<InnerChannel> = conn.create_channel().into();
22        confirmation.map(|inner| Channel { inner })
23    }
24
25    #[deprecated(note = "use lapin instead")]
26    pub fn id(&self) -> u16 {
27        self.inner.id()
28    }
29
30    /// request access
31    ///
32    /// returns a future that resolves once the access is granted
33    #[deprecated(note = "use lapin instead")]
34    pub fn access_request(
35        &self,
36        realm: &str,
37        options: AccessRequestOptions,
38    ) -> ConfirmationFuture<()> {
39        self.inner.access_request(realm, options).into()
40    }
41
42    /// declares an exchange
43    ///
44    /// returns a future that resolves once the exchange is available
45    #[deprecated(note = "use lapin instead")]
46    pub fn exchange_declare(
47        &self,
48        name: &str,
49        exchange_type: ExchangeKind,
50        options: ExchangeDeclareOptions,
51        arguments: FieldTable,
52    ) -> ConfirmationFuture<()> {
53        self.inner
54            .exchange_declare(name, exchange_type, options, arguments)
55            .into()
56    }
57
58    /// deletes an exchange
59    ///
60    /// returns a future that resolves once the exchange is deleted
61    #[deprecated(note = "use lapin instead")]
62    pub fn exchange_delete(
63        &self,
64        name: &str,
65        options: ExchangeDeleteOptions,
66    ) -> ConfirmationFuture<()> {
67        self.inner.exchange_delete(name, options).into()
68    }
69
70    /// binds an exchange to another exchange
71    ///
72    /// returns a future that resolves once the exchanges are bound
73    #[deprecated(note = "use lapin instead")]
74    pub fn exchange_bind(
75        &self,
76        destination: &str,
77        source: &str,
78        routing_key: &str,
79        options: ExchangeBindOptions,
80        arguments: FieldTable,
81    ) -> ConfirmationFuture<()> {
82        self.inner
83            .exchange_bind(destination, source, routing_key, options, arguments)
84            .into()
85    }
86
87    /// unbinds an exchange from another one
88    ///
89    /// returns a future that resolves once the exchanges are unbound
90    #[deprecated(note = "use lapin instead")]
91    pub fn exchange_unbind(
92        &self,
93        destination: &str,
94        source: &str,
95        routing_key: &str,
96        options: ExchangeUnbindOptions,
97        arguments: FieldTable,
98    ) -> ConfirmationFuture<()> {
99        self.inner
100            .exchange_unbind(destination, source, routing_key, options, arguments)
101            .into()
102    }
103
104    /// declares a queue
105    ///
106    /// returns a future that resolves once the queue is available
107    ///
108    /// the `mandatory` and `ìmmediate` options can be set to true,
109    /// but the return message will not be handled
110    #[deprecated(note = "use lapin instead")]
111    pub fn queue_declare(
112        &self,
113        name: &str,
114        options: QueueDeclareOptions,
115        arguments: FieldTable,
116    ) -> ConfirmationFuture<Queue> {
117        self.inner.queue_declare(name, options, arguments).into()
118    }
119
120    /// binds a queue to an exchange
121    ///
122    /// returns a future that resolves once the queue is bound to the exchange
123    #[deprecated(note = "use lapin instead")]
124    pub fn queue_bind(
125        &self,
126        name: &str,
127        exchange: &str,
128        routing_key: &str,
129        options: QueueBindOptions,
130        arguments: FieldTable,
131    ) -> ConfirmationFuture<()> {
132        self.inner
133            .queue_bind(name, exchange, routing_key, options, arguments)
134            .into()
135    }
136
137    /// unbinds a queue from the exchange
138    ///
139    /// returns a future that resolves once the queue is unbound from the exchange
140    #[deprecated(note = "use lapin instead")]
141    pub fn queue_unbind(
142        &self,
143        name: &str,
144        exchange: &str,
145        routing_key: &str,
146        arguments: FieldTable,
147    ) -> ConfirmationFuture<()> {
148        self.inner
149            .queue_unbind(name, exchange, routing_key, arguments)
150            .into()
151    }
152
153    /// sets up confirm extension for this channel
154    #[deprecated(note = "use lapin instead")]
155    pub fn confirm_select(&self, options: ConfirmSelectOptions) -> ConfirmationFuture<()> {
156        self.inner.confirm_select(options).into()
157    }
158
159    /// specifies quality of service for a channel
160    #[deprecated(note = "use lapin instead")]
161    pub fn basic_qos(
162        &self,
163        prefetch_count: ShortUInt,
164        options: BasicQosOptions,
165    ) -> ConfirmationFuture<()> {
166        self.inner.basic_qos(prefetch_count, options).into()
167    }
168
169    /// publishes a message on a queue
170    #[deprecated(note = "use lapin instead")]
171    pub fn basic_publish(
172        &self,
173        exchange: &str,
174        routing_key: &str,
175        payload: Vec<u8>,
176        options: BasicPublishOptions,
177        properties: BasicProperties,
178    ) -> ConfirmationFuture<()> {
179        self.inner
180            .basic_publish(exchange, routing_key, options, payload, properties)
181            .into()
182    }
183
184    /// creates a consumer stream
185    ///
186    /// returns a future of a `Consumer` that resolves once the method succeeds
187    ///
188    /// `Consumer` implements `futures::Stream`, so it can be used with any of
189    /// the usual combinators
190    #[deprecated(note = "use lapin instead")]
191    pub fn basic_consume(
192        &self,
193        queue: &str,
194        consumer_tag: &str,
195        options: BasicConsumeOptions,
196        arguments: FieldTable,
197    ) -> impl Future<Item = Consumer, Error = Error> {
198        let confirmation: ConfirmationFuture<lapin::Consumer> = self
199            .inner
200            .basic_consume(queue, consumer_tag, options, arguments)
201            .into();
202        confirmation.map(Consumer)
203    }
204
205    #[deprecated(note = "use lapin instead")]
206    pub fn basic_cancel(
207        &self,
208        consumer_tag: &str,
209        options: BasicCancelOptions,
210    ) -> ConfirmationFuture<()> {
211        self.inner.basic_cancel(consumer_tag, options).into()
212    }
213
214    #[deprecated(note = "use lapin instead")]
215    pub fn basic_recover(&self, options: BasicRecoverOptions) -> ConfirmationFuture<()> {
216        self.inner.basic_recover(options).into()
217    }
218
219    #[deprecated(note = "use lapin instead")]
220    pub fn basic_recover_async(&self, options: BasicRecoverAsyncOptions) -> ConfirmationFuture<()> {
221        self.inner.basic_recover_async(options).into()
222    }
223
224    /// acks a message
225    #[deprecated(note = "use lapin instead")]
226    pub fn basic_ack(&self, delivery_tag: u64, multiple: bool) -> ConfirmationFuture<()> {
227        self.inner
228            .basic_ack(delivery_tag, BasicAckOptions { multiple })
229            .into()
230    }
231
232    /// nacks a message
233    #[deprecated(note = "use lapin instead")]
234    pub fn basic_nack(
235        &self,
236        delivery_tag: u64,
237        multiple: bool,
238        requeue: bool,
239    ) -> ConfirmationFuture<()> {
240        self.inner
241            .basic_nack(delivery_tag, BasicNackOptions { multiple, requeue })
242            .into()
243    }
244
245    /// rejects a message
246    #[deprecated(note = "use lapin instead")]
247    pub fn basic_reject(
248        &self,
249        delivery_tag: u64,
250        options: BasicRejectOptions,
251    ) -> ConfirmationFuture<()> {
252        self.inner.basic_reject(delivery_tag, options).into()
253    }
254
255    /// gets a message
256    #[deprecated(note = "use lapin instead")]
257    pub fn basic_get(
258        &self,
259        queue: &str,
260        options: BasicGetOptions,
261    ) -> ConfirmationFuture<Option<BasicGetMessage>> {
262        self.inner.basic_get(queue, options).into()
263    }
264
265    /// Purge a queue.
266    ///
267    /// This method removes all messages from a queue which are not awaiting acknowledgment.
268    #[deprecated(note = "use lapin instead")]
269    pub fn queue_purge(
270        &self,
271        queue_name: &str,
272        options: QueuePurgeOptions,
273    ) -> ConfirmationFuture<LongUInt> {
274        self.inner.queue_purge(queue_name, options).into()
275    }
276
277    /// Delete a queue.
278    ///
279    /// This method deletes a queue. When a queue is deleted any pending messages are sent to a dead-letter queue
280    /// if this is defined in the server configuration, and all consumers on the queue are cancelled.
281    ///
282    /// If `if_unused` is set, the server will only delete the queue if it has no consumers.
283    /// If the queue has consumers the server does not delete it but raises a channel exception instead.
284    ///
285    /// If `if_empty` is set, the server will only delete the queue if it has no messages.
286    #[deprecated(note = "use lapin instead")]
287    pub fn queue_delete(
288        &self,
289        queue_name: &str,
290        options: QueueDeleteOptions,
291    ) -> ConfirmationFuture<LongUInt> {
292        self.inner.queue_delete(queue_name, options).into()
293    }
294
295    /// closes the channel
296    #[deprecated(note = "use lapin instead")]
297    pub fn close(&self, code: u16, message: &str) -> ConfirmationFuture<()> {
298        self.inner.close(code, message).into()
299    }
300
301    /// update a channel flow
302    #[deprecated(note = "use lapin instead")]
303    pub fn channel_flow(&self, options: ChannelFlowOptions) -> ConfirmationFuture<Boolean> {
304        self.inner.channel_flow(options).into()
305    }
306
307    #[deprecated(note = "use lapin instead")]
308    pub fn tx_select(&self) -> ConfirmationFuture<()> {
309        self.inner.tx_select().into()
310    }
311
312    #[deprecated(note = "use lapin instead")]
313    pub fn tx_commit(&self) -> ConfirmationFuture<()> {
314        self.inner.tx_commit().into()
315    }
316
317    #[deprecated(note = "use lapin instead")]
318    pub fn tx_rollback(&self) -> ConfirmationFuture<()> {
319        self.inner.tx_rollback().into()
320    }
321
322    /// When publishers confirm is enabled, wait for pending confirmations and return the nacked
323    /// messages
324    #[deprecated(note = "use lapin instead")]
325    pub fn wait_for_confirms(&self) -> ConfirmationFuture<Vec<BasicReturnMessage>, Result<()>> {
326        self.inner.wait_for_confirms().into()
327    }
328}