Skip to content

Commit c7c004b

Browse files
committed
Some convenience inits for AMQ methods
Bugs are hiding in the mess of the channel. Let's tidy up and make it easier to instantiate methods. [#119713047]
1 parent fe2d4da commit c7c004b

File tree

6 files changed

+295
-95
lines changed

6 files changed

+295
-95
lines changed

RMQClient.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@
153153
AECA103A1D1A9E6000ED9EA2 /* ConnectionHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = AECA10381D1A9E2C00ED9EA2 /* ConnectionHelper.swift */; };
154154
AECDEC9F1CBC0E3600EA6E93 /* RMQConnectionDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = AECDEC9E1CBC0E3600EA6E93 /* RMQConnectionDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
155155
AECDECA11CBC4A4F00EA6E93 /* ConnectionDelegateSpy.swift in Sources */ = {isa = PBXBuildFile; fileRef = AECDECA01CBC4A4F00EA6E93 /* ConnectionDelegateSpy.swift */; };
156+
AED74B4C1D22AF2400EE9550 /* RMQMethods+Convenience.h in Headers */ = {isa = PBXBuildFile; fileRef = AED74B4B1D22AF2400EE9550 /* RMQMethods+Convenience.h */; settings = {ATTRIBUTES = (Public, ); }; };
157+
AED74B4E1D22AF5F00EE9550 /* RMQMethods+Convenience.m in Sources */ = {isa = PBXBuildFile; fileRef = AED74B4D1D22AF5F00EE9550 /* RMQMethods+Convenience.m */; };
156158
AEDBFF231CD8E2E20004DB67 /* RMQPKCS12CertificateConverter.h in Headers */ = {isa = PBXBuildFile; fileRef = AEDBFF211CD8E2E20004DB67 /* RMQPKCS12CertificateConverter.h */; settings = {ATTRIBUTES = (Public, ); }; };
157159
AEDBFF241CD8E2E20004DB67 /* RMQPKCS12CertificateConverter.m in Sources */ = {isa = PBXBuildFile; fileRef = AEDBFF221CD8E2E20004DB67 /* RMQPKCS12CertificateConverter.m */; };
158160
AEDBFF2A1CD8E3AD0004DB67 /* RMQPKCS12CertificateConverterTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEDBFF291CD8E3AD0004DB67 /* RMQPKCS12CertificateConverterTest.swift */; };
@@ -389,6 +391,8 @@
389391
AECA10381D1A9E2C00ED9EA2 /* ConnectionHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConnectionHelper.swift; sourceTree = "<group>"; };
390392
AECDEC9E1CBC0E3600EA6E93 /* RMQConnectionDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RMQConnectionDelegate.h; sourceTree = "<group>"; };
391393
AECDECA01CBC4A4F00EA6E93 /* ConnectionDelegateSpy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConnectionDelegateSpy.swift; sourceTree = "<group>"; };
394+
AED74B4B1D22AF2400EE9550 /* RMQMethods+Convenience.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RMQMethods+Convenience.h"; sourceTree = "<group>"; };
395+
AED74B4D1D22AF5F00EE9550 /* RMQMethods+Convenience.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RMQMethods+Convenience.m"; sourceTree = "<group>"; };
392396
AEDBFF211CD8E2E20004DB67 /* RMQPKCS12CertificateConverter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RMQPKCS12CertificateConverter.h; sourceTree = "<group>"; };
393397
AEDBFF221CD8E2E20004DB67 /* RMQPKCS12CertificateConverter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RMQPKCS12CertificateConverter.m; sourceTree = "<group>"; };
394398
AEDBFF291CD8E3AD0004DB67 /* RMQPKCS12CertificateConverterTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RMQPKCS12CertificateConverterTest.swift; sourceTree = "<group>"; };
@@ -550,6 +554,8 @@
550554
AE338D7D1CF5F0CF005D8D6C /* RMQTable.m */,
551555
AE4E7F491C6A293D00A441EC /* RMQMethods.h */,
552556
AEA45EC41C43C20F00FE1F62 /* RMQMethods.m */,
557+
AED74B4B1D22AF2400EE9550 /* RMQMethods+Convenience.h */,
558+
AED74B4D1D22AF5F00EE9550 /* RMQMethods+Convenience.m */,
553559
AEADA37F1C71F59A00012D61 /* RMQMethodMap.h */,
554560
AEADA3801C71F59A00012D61 /* RMQMethodMap.m */,
555561
AEE445E91C7373BF0082132C /* RMQBasicProperties.h */,
@@ -937,6 +943,7 @@
937943
AE9DB00B1D12A4C40005F44B /* RMQConfirmations.h in Headers */,
938944
AE9DB0101D12C5C30005F44B /* RMQConfirmationTransaction.h in Headers */,
939945
AE4B72FB1D17F9E000907667 /* RMQBasicProperties+MergeDefaults.h in Headers */,
946+
AED74B4C1D22AF2400EE9550 /* RMQMethods+Convenience.h in Headers */,
940947
AE338D7E1CF5F0CF005D8D6C /* RMQTable.h in Headers */,
941948
AEE7FE951C3BCA6000DF8C4F /* RMQClient.h in Headers */,
942949
);
@@ -1164,6 +1171,7 @@
11641171
AEB5F1601CDA73D6001C82FF /* RMQErrors.m in Sources */,
11651172
AEA8A76E1CCA0F8300371E38 /* RMQSemaphoreWaiterFactory.m in Sources */,
11661173
AEE7FEB61C3BD16200DF8C4F /* RMQQueue.m in Sources */,
1174+
AED74B4E1D22AF5F00EE9550 /* RMQMethods+Convenience.m in Sources */,
11671175
AE744E341C85A1B000A4C2FA /* RMQFrame.m in Sources */,
11681176
AE9DB0071D11F0820005F44B /* RMQTransactionalConfirmations.m in Sources */,
11691177
AE8AD2631CC53AEB00229444 /* RMQFramesetValidator.m in Sources */,

RMQClient/RMQAllocatedChannel.m

Lines changed: 40 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
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

RMQClient/RMQClient.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#import <RMQClient/RMQHeartbeat.h>
5959
#import <RMQClient/RMQMethodDecoder.h>
6060
#import <RMQClient/RMQMethodMap.h>
61+
#import <RMQClient/RMQMethods+Convenience.h>
6162
#import <RMQClient/RMQProtocolHeader.h>
6263
#import <RMQClient/RMQURI.h>
6364
#import <RMQClient/RMQAllocatedChannel.h>

0 commit comments

Comments
 (0)