Skip to content

Commit

Permalink
Merge pull request #156 from rabbitmq/rabbitmq-objc-client-155
Browse files Browse the repository at this point in the history
 Make it possible for apps to provide a custom connection name
  • Loading branch information
michaelklishin authored Mar 12, 2019
2 parents 38904c0 + 1a8ad99 commit 8c0d383
Show file tree
Hide file tree
Showing 8 changed files with 308 additions and 19 deletions.
40 changes: 38 additions & 2 deletions RMQClient/RMQConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@
waiterFactory:(nonnull id<RMQWaiterFactory>)waiterFactory
heartbeatSender:(nonnull id<RMQHeartbeatSender>)heartbeatSender;

/// @brief Connection tuning, customisable TLS, all recovery options.
/// @brief Connection tuning, customisable config, all recovery options.
- (nonnull instancetype)initWithUri:(nonnull NSString *)uri
tlsOptions:(nonnull RMQTLSOptions *)tlsOptions
userProvidedConnectionName:(nonnull NSString *)connectionName
channelMax:(nonnull NSNumber *)channelMax
frameMax:(nonnull NSNumber *)frameMax
heartbeat:(nonnull NSNumber *)heartbeat
Expand All @@ -96,6 +96,42 @@
recoveryAttempts:(nonnull NSNumber *)recoveryAttempts
recoverFromConnectionClose:(BOOL)shouldRecoverFromConnectionClose;

/// @brief Connection tuning, customisable TLS, key recovery options.
- (nonnull instancetype)initWithUri:(nonnull NSString *)uri
tlsOptions:(nonnull RMQTLSOptions *)tlsOptions
delegate:(nullable id<RMQConnectionDelegate>)delegate
recoverAfter:(nonnull NSNumber *)recoveryInterval
recoveryAttempts:(nonnull NSNumber *)recoveryAttempts
recoverFromConnectionClose:(BOOL)shouldRecoverFromConnectionClose;

/// @brief Connection tuning, customisable TLS and connection name, key recovery options.
- (nonnull instancetype)initWithUri:(nonnull NSString *)uri
tlsOptions:(nonnull RMQTLSOptions *)tlsOptions
userProvidedConnectionName:(nullable NSString *)connectionName
delegate:(nullable id<RMQConnectionDelegate>)delegate
recoverAfter:(nonnull NSNumber *)recoveryInterval
recoveryAttempts:(nonnull NSNumber *)recoveryAttempts
recoverFromConnectionClose:(BOOL)shouldRecoverFromConnectionClose;

/// @brief Connection tuning, customisable TLS, all recovery options.
- (nonnull instancetype)initWithUri:(nonnull NSString *)uri
userProvidedConnectionName:(nullable NSString *)connectionName
delegate:(nullable id<RMQConnectionDelegate>)delegate
recoverAfter:(nonnull NSNumber *)recoveryInterval
recoveryAttempts:(nonnull NSNumber *)recoveryAttempts
recoverFromConnectionClose:(BOOL)shouldRecoverFromConnectionClose;

/// @brief Connection configuration.
- (nonnull instancetype)initWithUri:(nonnull NSString *)uri
userProvidedConnectionName:(nonnull NSString *)connectionName
delegate:(nullable id<RMQConnectionDelegate>)delegate;

/// @brief TLS, connection configuration and delegate.
- (nonnull instancetype)initWithUri:(nonnull NSString *)uri
tlsOptions:(nonnull RMQTLSOptions *)tlsOptions
userProvidedConnectionName:(nonnull NSString *)connectionName
delegate:(nullable id<RMQConnectionDelegate>)delegate;

/// @brief Allows setting of timeouts
- (nonnull instancetype)initWithUri:(nonnull NSString *)uri
connectTimeout:(nonnull NSNumber*)connectTimeout
Expand Down
188 changes: 186 additions & 2 deletions RMQClient/RMQConnection.m

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions RMQClient/RMQConnectionConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ extern NSInteger const RMQChannelMaxDefault;
@property (nonnull, nonatomic, readonly) NSString *vhost;
@property (nonnull, nonatomic, readonly) RMQCredentials *credentials;
@property (nonnull, nonatomic, readonly) NSString *authMechanism;
@property (nonatomic, readonly) NSString *userProvidedConnectionName;
@property (nonnull, nonatomic, readonly) id<RMQConnectionRecovery> recovery;

- (nonnull instancetype)initWithCredentials:(nonnull RMQCredentials *)credentials
Expand All @@ -78,4 +79,20 @@ extern NSInteger const RMQChannelMaxDefault;
vhost:(nonnull NSString *)vhost
authMechanism:(nonnull NSString *)authMechanism
recovery:(nonnull id<RMQConnectionRecovery>)recovery;

- (nonnull instancetype)initWithCredentials:(nonnull RMQCredentials *)credentials
channelMax:(nonnull NSNumber *)channelMax
frameMax:(nonnull NSNumber *)frameMax
heartbeat:(nonnull NSNumber *)heartbeat
vhost:(nonnull NSString *)vhost
authMechanism:(nonnull NSString *)authMechanism
userProvidedConnectionName:(nonnull NSString *)userProvidedConnectionName
recovery:(nonnull id<RMQConnectionRecovery>)recovery;

- (nonnull instancetype)initWithCredentials:(nonnull RMQCredentials *)credentials
heartbeat:(nonnull NSNumber *)heartbeat
vhost:(nonnull NSString *)vhost
authMechanism:(nonnull NSString *)authMechanism
userProvidedConnectionName:(nonnull NSString *)userProvidedConnectionName
recovery:(nonnull id<RMQConnectionRecovery>)recovery;
@end
39 changes: 39 additions & 0 deletions RMQClient/RMQConnectionConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ @interface RMQConnectionConfig ()
@property (nonnull, nonatomic, readwrite) NSString *vhost;
@property (nonnull, nonatomic, readwrite) RMQCredentials *credentials;
@property (nonnull, nonatomic, readwrite) NSString *authMechanism;
@property (nonatomic, readwrite) NSString *userProvidedConnectionName;
@property (nonnull, nonatomic, readwrite) id<RMQConnectionRecovery> recovery;
@end

Expand Down Expand Up @@ -103,4 +104,42 @@ - (instancetype)initWithCredentials:(RMQCredentials *)credentials
authMechanism:authMechanism
recovery:recovery];
}

- (instancetype)initWithCredentials:(RMQCredentials *)credentials
channelMax:(NSNumber *)channelMax
frameMax:(NSNumber *)frameMax
heartbeat:(NSNumber *)heartbeat
vhost:(nonnull NSString *)vhost
authMechanism:(nonnull NSString *)authMechanism
userProvidedConnectionName:(nonnull NSString *)userProvidedConnectionName
recovery:(nonnull id<RMQConnectionRecovery>)recovery {
self = [super init];
if (self) {
self.credentials = credentials;
self.channelMax = channelMax;
self.frameMax = frameMax;
self.heartbeat = heartbeat;
self.vhost = vhost;
self.authMechanism = authMechanism;
self.userProvidedConnectionName = userProvidedConnectionName;
self.recovery = recovery;
}
return self;
}

- (instancetype)initWithCredentials:(RMQCredentials *)credentials
heartbeat:(NSNumber *)heartbeat
vhost:(nonnull NSString *)vhost
authMechanism:(nonnull NSString *)authMechanism
userProvidedConnectionName:(nonnull NSString *)userProvidedConnectionName
recovery:(nonnull id<RMQConnectionRecovery>)recovery {
return [self initWithCredentials:credentials
channelMax:[NSNumber numberWithInteger:RMQChannelMaxDefault]
frameMax:[NSNumber numberWithInteger:RMQFrameMax]
heartbeat:heartbeat
vhost:vhost
authMechanism:authMechanism
userProvidedConnectionName:userProvidedConnectionName
recovery:recovery];
}
@end
19 changes: 13 additions & 6 deletions RMQClient/RMQHandshaker.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,19 @@ - (RMQConnectionStartOk *)startOk {
NSBundle *bundle = [NSBundle bundleWithIdentifier:@"io.pivotal.RMQClient"];
NSString *version = bundle.infoDictionary[@"CFBundleShortVersionString"];

RMQTable *clientProperties = [[RMQTable alloc] init:
@{@"capabilities" : capabilities,
@"product" : [[RMQLongstr alloc] init:@"RMQClient"],
@"platform" : [[RMQLongstr alloc] init:@"iOS"],
@"version" : [[RMQLongstr alloc] init:version],
@"information" : [[RMQLongstr alloc] init:@"https://github.com/rabbitmq/rabbitmq-objc-client"]}];
NSDictionary *libraryProperties = @{@"capabilities" : capabilities,
@"product" : [[RMQLongstr alloc] init:@"RMQClient"],
@"platform" : [[RMQLongstr alloc] init:@"iOS"],
@"version" : [[RMQLongstr alloc] init:version],
@"information" : [[RMQLongstr alloc] init:@"https://github.com/rabbitmq/rabbitmq-objc-client"]};
NSMutableDictionary *combinedProperties = [[NSMutableDictionary alloc] initWithDictionary:libraryProperties];

NSString *userProvidedConnectionName = [self.config userProvidedConnectionName];
if (userProvidedConnectionName != nil) {
[combinedProperties setObject:[[RMQLongstr alloc] init:userProvidedConnectionName]
forKey:@"connection_name"];
}
RMQTable *clientProperties = [[RMQTable alloc] init:combinedProperties];

return [[RMQConnectionStartOk alloc] initWithClientProperties:clientProperties
mechanism:[[RMQShortstr alloc] init:self.config.authMechanism]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class ChannelLifecycleIntegrationTest: XCTestCase {
let ch2 = conn.createChannel()

let qName = "objc.tests.\(Int.random(in: 200...1000))"
ch1.queue(qName, options: [.exclusive])
ch1.queue(qName, options: [.autoDelete])

// uses a different set of properties from
// the original declaration
Expand Down
13 changes: 13 additions & 0 deletions RMQClientIntegrationTests/ConnectionLifecycleIntegrationTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,18 @@ class ConnectionLifecycleIntegrationTest: XCTestCase {
XCTAssertNotNil(props["product"] ?? nil)
XCTAssertNotNil(props["version"] ?? nil)
XCTAssertNotNil(props["capabilities"] ?? nil)

conn.blockingClose()
}

func testUserProvidedConnectionName() {
let conn = RMQConnection(uri: IntegrationHelper.defaultEndpoint,
userProvidedConnectionName: "testUserProvidedConnectionName.1",
delegate: RMQConnectionDelegateLogger())
conn.start()
XCTAssertTrue(IntegrationHelper.pollUntilConnected(conn))

XCTAssert(conn.isOpen())
conn.blockingClose()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,8 @@ class ConnectionRecoveryIntegrationTest: XCTestCase {

let conn = RMQConnection(uri: plainEndpoint,
tlsOptions: RMQTLSOptions.fromURI(plainEndpoint),
channelMax: RMQChannelMaxDefault as NSNumber,
frameMax: RMQFrameMax as NSNumber,
heartbeat: 10,
connectTimeout: 15,
readTimeout: 30,
writeTimeout: 30,
syncTimeout: 10,
userProvidedConnectionName: nil,
delegate: delegate,
delegateQueue: DispatchQueue.main,
recoverAfter: recoveryInterval as NSNumber,
recoveryAttempts: 5,
recoverFromConnectionClose: true)
Expand Down

0 comments on commit 8c0d383

Please sign in to comment.