Skip to content

Commit

Permalink
Breaking change: send/receive data, not strings.
Browse files Browse the repository at this point in the history
Issue #46

[#124585511]
  • Loading branch information
camelpunch committed Jul 5, 2016
1 parent 4319b93 commit 296126d
Show file tree
Hide file tree
Showing 20 changed files with 144 additions and 131 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Test-driven from Swift and implemented in Objective-C, to avoid burdening Object
- [x] PKCS12 client certificates using the [TLS auth mechanism plugin](https://github.com/rabbitmq/rabbitmq-auth-mechanism-ssl)
- [ ] [PKCS12 client certificates using chained CAs](https://github.com/rabbitmq/rabbitmq-objc-client/issues/74)
- [ ] [Publisher confirmations](https://github.com/rabbitmq/rabbitmq-objc-client/issues/68)
- [ ] [Publish and consume messages as data](https://github.com/rabbitmq/rabbitmq-objc-client/issues/46)
- [x] [Publish and consume messages as data](https://github.com/rabbitmq/rabbitmq-objc-client/issues/46)
- [ ] [Connection closure when broker doesn't send heartbeats fast enough](https://github.com/rabbitmq/rabbitmq-objc-client/issues/41)
- [ ] [Customisable consumer hooks](https://github.com/rabbitmq/rabbitmq-objc-client/issues/71)
- [ ] [basic.return support](https://github.com/rabbitmq/rabbitmq-objc-client/issues/72)
Expand Down Expand Up @@ -90,9 +90,9 @@ this list.
```swift
let q = ch.queue("myqueue")
q.subscribe { m in
print("Received: \(m.content)")
print("Received: \(m.body)")
}
q.publish("foo")
q.publish("foo".dataUsingEncoding(NSUTF8StringEncoding)!)
```

1. Close the connection when done:
Expand Down
36 changes: 16 additions & 20 deletions RMQClient/RMQAllocatedChannel.m
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ - (void)basicCancel:(NSString *)consumerTag {
options:RMQBasicCancelNoOptions]];
}

- (void)basicPublish:(NSString *)message
- (void)basicPublish:(NSData *)body
routingKey:(NSString *)routingKey
exchange:(NSString *)exchange
properties:(NSArray<RMQValue *> *)properties
Expand All @@ -251,8 +251,7 @@ - (void)basicPublish:(NSString *)message
exchange:[[RMQShortstr alloc] init:exchange]
routingKey:[[RMQShortstr alloc] init:routingKey]
options:options];
NSData *contentBodyData = [message dataUsingEncoding:NSUTF8StringEncoding];
RMQContentBody *contentBody = [[RMQContentBody alloc] initWithData:contentBodyData];
RMQContentBody *contentBody = [[RMQContentBody alloc] initWithData:body];

NSData *bodyData = contentBody.amqEncoded;

Expand Down Expand Up @@ -282,15 +281,13 @@ - (void)basicGet:(NSString *)queue
options:options]
completionHandler:^(RMQFrameset *frameset) {
RMQBasicGetOk *getOk = (RMQBasicGetOk *)frameset.method;
NSString *messageContent = [[NSString alloc] initWithData:frameset.contentData
encoding:NSUTF8StringEncoding];
RMQMessage *message = [[RMQMessage alloc] initWithContent:messageContent
consumerTag:@""
deliveryTag:@(getOk.deliveryTag.integerValue)
redelivered:getOk.options & RMQBasicGetOkRedelivered
exchangeName:getOk.exchange.stringValue
routingKey:getOk.routingKey.stringValue
properties:frameset.contentHeader.properties];
RMQMessage *message = [[RMQMessage alloc] initWithBody:frameset.contentData
consumerTag:@""
deliveryTag:@(getOk.deliveryTag.integerValue)
redelivered:getOk.options & RMQBasicGetOkRedelivered
exchangeName:getOk.exchange.stringValue
routingKey:getOk.routingKey.stringValue
properties:frameset.contentHeader.properties];
userCompletionHandler(message);
}];
}
Expand Down Expand Up @@ -439,16 +436,15 @@ - (void)handleConfirmation:(RMQFrameset *)frameset {

- (void)handleBasicDeliver:(RMQFrameset *)frameset {
RMQBasicDeliver *deliver = (RMQBasicDeliver *)frameset.method;
NSString *content = [[NSString alloc] initWithData:frameset.contentData encoding:NSUTF8StringEncoding];
RMQConsumer *consumer = self.consumers[deliver.consumerTag.stringValue];
if (consumer) {
RMQMessage *message = [[RMQMessage alloc] initWithContent:content
consumerTag:deliver.consumerTag.stringValue
deliveryTag:@(deliver.deliveryTag.integerValue)
redelivered:deliver.options & RMQBasicDeliverRedelivered
exchangeName:deliver.exchange.stringValue
routingKey:deliver.routingKey.stringValue
properties:frameset.contentHeader.properties];
RMQMessage *message = [[RMQMessage alloc] initWithBody:frameset.contentData
consumerTag:deliver.consumerTag.stringValue
deliveryTag:@(deliver.deliveryTag.integerValue)
redelivered:deliver.options & RMQBasicDeliverRedelivered
exchangeName:deliver.exchange.stringValue
routingKey:deliver.routingKey.stringValue
properties:frameset.contentHeader.properties];
consumer.handler(message);
}
}
Expand Down
2 changes: 1 addition & 1 deletion RMQClient/RMQChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@

- (void)basicCancel:(nonnull NSString *)consumerTag;

- (void)basicPublish:(nonnull NSString *)message
- (void)basicPublish:(nonnull NSData *)body
routingKey:(nonnull NSString *)routingKey
exchange:(nonnull NSString *)exchange
properties:(nonnull NSArray<RMQValue *> *)properties
Expand Down
10 changes: 5 additions & 5 deletions RMQClient/RMQExchange.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,19 @@
- (void)unbind:(RMQExchange *)source;
- (void)delete:(RMQExchangeDeleteOptions)options;
- (void)delete;
- (void)publish:(NSString *)message
- (void)publish:(NSData *)body
routingKey:(NSString *)routingKey
properties:(NSArray <RMQValue<RMQBasicValue> *> *)properties
options:(RMQBasicPublishOptions)options;
- (void)publish:(NSString *)message
- (void)publish:(NSData *)body
routingKey:(NSString *)key
persistent:(BOOL)isPersistent
options:(RMQBasicPublishOptions)options;
- (void)publish:(NSString *)message
- (void)publish:(NSData *)body
routingKey:(NSString *)key
persistent:(BOOL)isPersistent;
- (void)publish:(NSString *)message
- (void)publish:(NSData *)body
routingKey:(NSString *)key;
- (void)publish:(NSString *)message;
- (void)publish:(NSData *)body;

@end
20 changes: 10 additions & 10 deletions RMQClient/RMQExchange.m
Original file line number Diff line number Diff line change
Expand Up @@ -106,50 +106,50 @@ - (void)delete {
[self delete:RMQExchangeDeleteNoOptions];
}

- (void)publish:(NSString *)message
- (void)publish:(NSData *)body
routingKey:(NSString *)routingKey
properties:(NSArray<RMQValue<RMQBasicValue> *> *)properties
options:(RMQBasicPublishOptions)options {
[self.channel basicPublish:message
[self.channel basicPublish:body
routingKey:routingKey
exchange:self.name
properties:properties
options:options];
}

- (void)publish:(NSString *)message
- (void)publish:(NSData *)body
routingKey:(NSString *)key
persistent:(BOOL)isPersistent
options:(RMQBasicPublishOptions)options {
NSMutableArray *properties = [NSMutableArray new];
if (isPersistent) {
[properties addObject:[[RMQBasicDeliveryMode alloc] init:2]];
}
[self.channel basicPublish:message
[self.channel basicPublish:body
routingKey:key
exchange:self.name
properties:properties
options:options];
}

- (void)publish:(NSString *)message
- (void)publish:(NSData *)body
routingKey:(NSString *)key
persistent:(BOOL)isPersistent {
[self publish:message
[self publish:body
routingKey:key
persistent:isPersistent
options:RMQBasicPublishNoOptions];
}

- (void)publish:(NSString *)message
- (void)publish:(NSData *)body
routingKey:(NSString *)key {
[self publish:message
[self publish:body
routingKey:key
persistent:NO];
}

- (void)publish:(NSString *)message {
[self publish:message
- (void)publish:(NSData *)body {
[self publish:body
routingKey:@""];
}

Expand Down
16 changes: 8 additions & 8 deletions RMQClient/RMQMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,21 @@
#import "RMQBasicProperties.h"

@interface RMQMessage : RMQValue
@property (nonatomic, readonly) NSString *content;
@property (nonatomic, readonly) NSData *body;
@property (nonatomic, readonly) NSString *consumerTag;
@property (nonatomic, readonly) NSNumber *deliveryTag;
@property (nonatomic, readonly) BOOL isRedelivered;
@property (nonatomic, readonly) NSString *exchangeName;
@property (nonatomic, readonly) NSString *routingKey;
@property (nonatomic, readonly) NSArray *properties;

- (instancetype)initWithContent:(NSString *)content
consumerTag:(NSString *)consumerTag
deliveryTag:(NSNumber *)deliveryTag
redelivered:(BOOL)isRedelivered
exchangeName:(NSString *)exchangeName
routingKey:(NSString *)routingKey
properties:(NSArray<RMQValue<RMQBasicValue> *> *)properties;
- (instancetype)initWithBody:(NSData *)body
consumerTag:(NSString *)consumerTag
deliveryTag:(NSNumber *)deliveryTag
redelivered:(BOOL)isRedelivered
exchangeName:(NSString *)exchangeName
routingKey:(NSString *)routingKey
properties:(NSArray<RMQValue<RMQBasicValue> *> *)properties;

- (NSString *)appID;
- (NSString *)contentType;
Expand Down
18 changes: 9 additions & 9 deletions RMQClient/RMQMessage.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
#import "RMQMessage.h"

@interface RMQMessage ()
@property (nonatomic, readwrite) NSString *content;
@property (nonatomic, readwrite) NSData *body;
@property (nonatomic, readwrite) NSString *consumerTag;
@property (nonatomic, readwrite) NSNumber *deliveryTag;
@property (nonatomic, readwrite) BOOL isRedelivered;
Expand All @@ -63,16 +63,16 @@ @interface RMQMessage ()

@implementation RMQMessage

- (instancetype)initWithContent:(NSString *)content
consumerTag:(NSString *)consumerTag
deliveryTag:(NSNumber *)deliveryTag
redelivered:(BOOL)isRedelivered
exchangeName:(NSString *)exchangeName
routingKey:(NSString *)routingKey
properties:(NSArray<RMQValue<RMQBasicValue> *> *)properties {
- (instancetype)initWithBody:(NSData *)body
consumerTag:(NSString *)consumerTag
deliveryTag:(NSNumber *)deliveryTag
redelivered:(BOOL)isRedelivered
exchangeName:(NSString *)exchangeName
routingKey:(NSString *)routingKey
properties:(NSArray<RMQValue<RMQBasicValue> *> *)properties {
self = [super init];
if (self) {
self.content = content;
self.body = body;
self.consumerTag = consumerTag;
self.deliveryTag = deliveryTag;
self.isRedelivered = isRedelivered;
Expand Down
8 changes: 4 additions & 4 deletions RMQClient/RMQQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@
- (void)unbind:(RMQExchange *)exchange;
- (void)delete:(RMQQueueDeleteOptions)options;
- (void)delete;
- (void)publish:(NSString *)message
- (void)publish:(NSData *)body
properties:(NSArray <RMQValue<RMQBasicValue> *> *)properties
options:(RMQBasicPublishOptions)options;
- (void)publish:(NSString *)message
- (void)publish:(NSData *)body
persistent:(BOOL)isPersistent
options:(RMQBasicPublishOptions)options;
- (void)publish:(NSString *)message
- (void)publish:(NSData *)body
persistent:(BOOL)isPersistent;
- (void)publish:(NSString *)message;
- (void)publish:(NSData *)body;
- (void)pop:(RMQConsumerDeliveryHandler)handler;
- (RMQConsumer *)subscribe:(RMQConsumerDeliveryHandler)handler;
- (RMQConsumer *)subscribe:(RMQBasicConsumeOptions)options
Expand Down
16 changes: 8 additions & 8 deletions RMQClient/RMQQueue.m
Original file line number Diff line number Diff line change
Expand Up @@ -104,37 +104,37 @@ - (void)delete {
[self delete:RMQQueueDeleteNoOptions];
}

- (void)publish:(NSString *)message
- (void)publish:(NSData *)data
properties:(NSArray<RMQValue<RMQBasicValue> *> *)properties
options:(RMQBasicPublishOptions)options {
[self.channel basicPublish:message
[self.channel basicPublish:data
routingKey:self.name
exchange:@""
properties:properties
options:options];
}

- (void)publish:(NSString *)message
- (void)publish:(NSData *)body
persistent:(BOOL)isPersistent
options:(RMQBasicPublishOptions)options {
NSMutableArray *properties = [NSMutableArray new];
if (isPersistent) {
[properties addObject:[[RMQBasicDeliveryMode alloc] init:2]];
}
[self.channel basicPublish:message
[self.channel basicPublish:body
routingKey:self.name
exchange:@""
properties:properties
options:options];
}

- (void)publish:(NSString *)message
- (void)publish:(NSData *)body
persistent:(BOOL)isPersistent {
[self publish:message persistent:isPersistent options:RMQBasicPublishNoOptions];
[self publish:body persistent:isPersistent options:RMQBasicPublishNoOptions];
}

- (void)publish:(NSString *)message {
[self publish:message persistent:NO];
- (void)publish:(NSData *)body {
[self publish:body persistent:NO];
}

- (void)pop:(RMQConsumerDeliveryHandler)handler {
Expand Down
Loading

0 comments on commit 296126d

Please sign in to comment.