5151
5252#import " RMQBasicProperties+MergeDefaults.h"
5353#import " RMQErrors.h"
54- #import " RMQMethods.h"
54+ #import " RMQMethods+Convenience .h"
5555#import " RMQAllocatedChannel.h"
5656#import " RMQConnectionDelegate.h"
5757
@@ -123,26 +123,18 @@ - (void)activateWithDelegate:(id<RMQConnectionDelegate>)delegate {
123123}
124124
125125- (void )open {
126- RMQChannelOpen *outgoingMethod = [[RMQChannelOpen alloc ] initWithReserved1: [[RMQShortstr alloc ] init: @" " ]];
127- [self .dispatcher sendSyncMethod: outgoingMethod];
126+ [self .dispatcher sendSyncMethod: [RMQChannelOpen new ]];
128127}
129128
130129- (void )close {
131- [self .dispatcher sendSyncMethod: [[RMQChannelClose alloc ] initWithReplyCode: [[RMQShort alloc ] init: 200 ]
132- replyText: [[RMQShortstr alloc ] init: @" Goodbye" ]
133- classId: [[RMQShort alloc ] init: 0 ]
134- methodId: [[RMQShort alloc ] init: 0 ]]
130+ [self .dispatcher sendSyncMethod: [RMQChannelClose new ]
135131 completionHandler: ^(RMQFrameset *frameset) {
136132 [self .allocator releaseChannelNumber: self .channelNumber];
137133 }];
138134}
139135
140136- (void )blockingClose {
141- RMQChannelClose *close = [[RMQChannelClose alloc ] initWithReplyCode: [[RMQShort alloc ] init: 200 ]
142- replyText: [[RMQShortstr alloc ] init: @" Goodbye" ]
143- classId: [[RMQShort alloc ] init: 0 ]
144- methodId: [[RMQShort alloc ] init: 0 ]];
145- [self .dispatcher sendSyncMethodBlocking: close];
137+ [self .dispatcher sendSyncMethodBlocking: [RMQChannelClose new ]];
146138 [self .allocator releaseChannelNumber: self .channelNumber];
147139}
148140
@@ -172,7 +164,7 @@ - (void)blockingWaitOn:(Class)method {
172164
173165- (void )confirmSelect {
174166 [self .confirmations enable ];
175- [self .dispatcher sendSyncMethod: [[ RMQConfirmSelect alloc ] initWithOptions: RMQConfirmSelectNoOptions ]];
167+ [self .dispatcher sendSyncMethod: [RMQConfirmSelect new ]];
176168}
177169
178170- (void )afterConfirmed : (RMQConfirmationCallback)handler {
@@ -202,32 +194,26 @@ - (RMQQueue *)queue:(NSString *)queueName {
202194- (void )queueDelete : (NSString *)queueName
203195 options : (RMQQueueDeleteOptions)options {
204196 [self .queues removeObjectForKey: queueName];
205- [self .dispatcher sendSyncMethod: [[RMQQueueDelete alloc ] initWithReserved1: [[RMQShort alloc ] init: 0 ]
206- queue: [[RMQShortstr alloc ] init: queueName]
207- options: options]];
197+ [self .dispatcher sendSyncMethod: [[RMQQueueDelete alloc ] initWithQueue: queueName
198+ options: options]];
208199}
209200
210201- (void )queueBind : (NSString *)queueName
211202 exchange : (NSString *)exchangeName
212203 routingKey : (nonnull NSString *)routingKey {
213- [self .dispatcher sendSyncMethod: [[RMQQueueBind alloc ] initWithReserved1: [[RMQShort alloc ] init: 0 ]
214- queue: [[RMQShortstr alloc ] init: queueName]
215- exchange: [[RMQShortstr alloc ] init: exchangeName]
216- routingKey: [[RMQShortstr alloc ] init: routingKey]
217- options: RMQQueueBindNoOptions
218- arguments: [[RMQTable alloc ] init: @{}]]];
204+ [self .dispatcher sendSyncMethod: [[RMQQueueBind alloc ] initWithQueue: queueName
205+ exchange: exchangeName
206+ routingKey: routingKey]];
219207 [self .queueBindings[queueName] addObject: @{@" exchange" : exchangeName,
220208 @" routing-key" : routingKey}];
221209}
222210
223211- (void )queueUnbind : (NSString *)queueName
224212 exchange : (NSString *)exchangeName
225213 routingKey : (NSString *)routingKey {
226- [self .dispatcher sendSyncMethod: [[RMQQueueUnbind alloc ] initWithReserved1: [[RMQShort alloc ] init: 0 ]
227- queue: [[RMQShortstr alloc ] init: queueName]
228- exchange: [[RMQShortstr alloc ] init: exchangeName]
229- routingKey: [[RMQShortstr alloc ] init: routingKey]
230- arguments: [[RMQTable alloc ] init: @{}]]];
214+ [self .dispatcher sendSyncMethod: [[RMQQueueUnbind alloc ] initWithQueue: queueName
215+ exchange: exchangeName
216+ routingKey: routingKey]];
231217 [self .queueBindings[queueName] removeObject: @{@" exchange" : exchangeName,
232218 @" routing-key" : routingKey}];
233219}
@@ -241,11 +227,9 @@ - (RMQConsumer *)basicConsume:(NSString *)queueName
241227 consumerTag: consumerTag
242228 handler: handler
243229 channel: self ];
244- [self .dispatcher sendSyncMethod: [[RMQBasicConsume alloc ] initWithReserved1: [[RMQShort alloc ] init: 0 ]
245- queue: [[RMQShortstr alloc ] init: queueName]
246- consumerTag: [[RMQShortstr alloc ] init: consumerTag]
247- options: options
248- arguments: [[RMQTable alloc ] init: @{}]]
230+ [self .dispatcher sendSyncMethod: [[RMQBasicConsume alloc ] initWithQueue: queueName
231+ consumerTag: consumerTag
232+ options: options]
249233 completionHandler: ^(RMQFrameset *frameset) {
250234 self.consumers [consumerTag] = consumer;
251235 }];
@@ -313,12 +297,8 @@ - (void)basicGet:(NSString *)queue
313297
314298- (void )basicQos : (NSNumber *)count
315299 global : (BOOL )isGlobal {
316- RMQBasicQosOptions options = RMQBasicQosNoOptions;
317- if (isGlobal) options |= RMQBasicQosGlobal;
318-
319- [self .dispatcher sendSyncMethod: [[RMQBasicQos alloc ] initWithPrefetchSize: [[RMQLong alloc ] init: 0 ]
320- prefetchCount: [[RMQShort alloc ] init: count.integerValue]
321- options: options]
300+ [self .dispatcher sendSyncMethod: [[RMQBasicQos alloc ] initWithPrefetchCount: count
301+ global: isGlobal]
322302 completionHandler: ^(RMQFrameset *frameset) {
323303 if (isGlobal) {
324304 self.prefetchCountPerChannel = count;
@@ -361,35 +341,27 @@ - (void)nack:(NSNumber *)deliveryTag {
361341- (void )exchangeDeclare : (NSString *)name
362342 type : (NSString *)type
363343 options : (RMQExchangeDeclareOptions)options {
364- [self .dispatcher sendSyncMethod: [[RMQExchangeDeclare alloc ] initWithReserved1: [[RMQShort alloc ] init: 0 ]
365- exchange: [[RMQShortstr alloc ] init: name]
366- type: [[RMQShortstr alloc ] init: type]
367- options: options
368- arguments: [[RMQTable alloc ] init: @{}]]];
344+ [self .dispatcher sendSyncMethod: [[RMQExchangeDeclare alloc ] initWithExchange: name
345+ type: type
346+ options: options]];
369347}
370348
371349- (void )exchangeBind : (NSString *)sourceName
372350 destination : (NSString *)destinationName
373351 routingKey : (NSString *)routingKey {
374- [self .dispatcher sendSyncMethod: [[RMQExchangeBind alloc ] initWithReserved1: [[RMQShort alloc ] init: 0 ]
375- destination: [[RMQShortstr alloc ] init: destinationName]
376- source: [[RMQShortstr alloc ] init: sourceName]
377- routingKey: [[RMQShortstr alloc ] init: routingKey]
378- options: RMQExchangeBindNoOptions
379- arguments: [[RMQTable alloc ] init: @{}]]];
352+ [self .dispatcher sendSyncMethod: [[RMQExchangeBind alloc ] initWithDestination: destinationName
353+ source: sourceName
354+ routingKey: routingKey]];
380355 [self .exchangeBindings[sourceName] addObject: @{@" destination" : destinationName,
381356 @" routing-key" : routingKey}];
382357}
383358
384359- (void )exchangeUnbind : (NSString *)sourceName
385360 destination : (NSString *)destinationName
386361 routingKey : (NSString *)routingKey {
387- [self .dispatcher sendSyncMethod: [[RMQExchangeUnbind alloc ] initWithReserved1: [[RMQShort alloc ] init: 0 ]
388- destination: [[RMQShortstr alloc ] init: destinationName]
389- source: [[RMQShortstr alloc ] init: sourceName]
390- routingKey: [[RMQShortstr alloc ] init: routingKey]
391- options: RMQExchangeUnbindNoOptions
392- arguments: [[RMQTable alloc ] init: @{}]]];
362+ [self .dispatcher sendSyncMethod: [[RMQExchangeUnbind alloc ] initWithDestination: destinationName
363+ source: sourceName
364+ routingKey: routingKey]];
393365 [self .exchangeBindings[sourceName] removeObject: @{@" destination" : destinationName,
394366 @" routing-key" : routingKey}];
395367}
@@ -522,27 +494,18 @@ - (RMQQueue *)memoizedQueueDeclare:(NSString *)originalQueueName
522494 options: options
523495 arguments: arguments
524496 channel: (id <RMQChannel>)self ];
525- [self queueDeclare: declaredQueueName
526- options: options
527- arguments: arguments];
497+
498+ RMQQueueDeclare *method = [[RMQQueueDeclare alloc ] initWithQueue: declaredQueueName
499+ options: options
500+ arguments: arguments];
501+ [self .dispatcher sendSyncMethod: method];
502+
528503 self.queues [q.name] = q;
529504 self.queueBindings [q.name] = [NSMutableSet new ];
530505 return q;
531506 }
532507}
533508
534- - (void )queueDeclare : (NSString *)declaredQueueName
535- options : (RMQQueueDeclareOptions)options
536- arguments : (RMQTable *)arguments {
537- RMQShort *ticket = [[RMQShort alloc ] init: 0 ];
538- RMQShortstr *amqQueueName = [[RMQShortstr alloc ] init: declaredQueueName];
539- RMQQueueDeclare *method = [[RMQQueueDeclare alloc ] initWithReserved1: ticket
540- queue: amqQueueName
541- options: options
542- arguments: arguments];
543- [self .dispatcher sendSyncMethod: method];
544- }
545-
546509- (NSArray *)contentBodiesFromData : (NSData *)data inChunksOf : (NSUInteger )chunkSize {
547510 NSMutableArray *bodies = [NSMutableArray new ];
548511 NSUInteger chunkCount = data.length / chunkSize;
@@ -572,7 +535,7 @@ - (void)recoverPrefetch {
572535- (void )recoverConfirmations {
573536 if (self.confirmations .isEnabled ) {
574537 [self .confirmations recover ];
575- [self .dispatcher sendSyncMethod: [[ RMQConfirmSelect alloc ] initWithOptions: RMQConfirmSelectNoOptions ]];
538+ [self .dispatcher sendSyncMethod: [RMQConfirmSelect new ]];
576539 }
577540}
578541
@@ -592,9 +555,9 @@ - (void)recoverExchangeBindings {
592555
593556- (void )recoverQueuesAndTheirBindings {
594557 for (RMQQueue *queue in self.queues .allValues ) {
595- [self queueDeclare : queue.name
596- options: queue.options
597- arguments: queue.arguments];
558+ [self .dispatcher sendSyncMethod: [[RMQQueueDeclare alloc ] initWithQueue : queue.name
559+ options: queue.options
560+ arguments: queue.arguments] ];
598561 for (NSDictionary *binding in [self .queueBindings[queue.name] copy ]) {
599562 [self queueBind: queue.name exchange: binding[@" exchange" ] routingKey: binding[@" routing-key" ]];
600563 }
@@ -603,11 +566,9 @@ - (void)recoverQueuesAndTheirBindings {
603566
604567- (void )recoverConsumers {
605568 for (RMQConsumer *consumer in self.consumers .allValues ) {
606- [self .dispatcher sendSyncMethod: [[RMQBasicConsume alloc ] initWithReserved1: [[RMQShort alloc ] init: 0 ]
607- queue: [[RMQShortstr alloc ] init: consumer.queueName]
608- consumerTag: [[RMQShortstr alloc ] init: consumer.tag]
609- options: consumer.options
610- arguments: [[RMQTable alloc ] init: @{}]]];
569+ [self .dispatcher sendSyncMethod: [[RMQBasicConsume alloc ] initWithQueue: consumer.queueName
570+ consumerTag: consumer.tag
571+ options: consumer.options]];
611572 }
612573}
613574
0 commit comments