diff options
author | Muxi Yan <mxyan@google.com> | 2018-06-19 12:04:06 -0700 |
---|---|---|
committer | Muxi Yan <mxyan@google.com> | 2018-06-19 12:04:06 -0700 |
commit | b13eda3cb49bcbf5cb8926aef419acc1fffdb98f (patch) | |
tree | e2b5aed8e0eae8550f436983abf1290653a5b6b0 | |
parent | 9e3e64604d9a3bb4bea9202ede844e6f7b592eeb (diff) |
Enable retry
-rw-r--r-- | src/objective-c/GRPCClient/GRPCCall+ChannelArg.h | 5 | ||||
-rw-r--r-- | src/objective-c/GRPCClient/GRPCCall+ChannelArg.m | 5 | ||||
-rw-r--r-- | src/objective-c/GRPCClient/private/GRPCHost.h | 1 | ||||
-rw-r--r-- | src/objective-c/GRPCClient/private/GRPCHost.m | 5 |
4 files changed, 16 insertions, 0 deletions
diff --git a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h index c05ba54c99..0b6855f6a4 100644 --- a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h +++ b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h @@ -55,4 +55,9 @@ typedef NS_ENUM(NSInteger, GRPCCompressAlgorithm) { timeout:(int)timeout forHost:(nonnull NSString *)host; +/** Enable/Disable automatic retry of gRPC calls on the channel. If automatic retry is enabled, the + * retry is controlled by server's service config. If automatic retry is disabled, failed calls are + * immediately returned to the application layer. */ ++ (void)enableRetry:(BOOL)enabled forHost:(nonnull NSString *)host; + @end diff --git a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m index 8f9c1b90ce..78bf3fd79f 100644 --- a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m +++ b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m @@ -64,4 +64,9 @@ hostConfig.keepaliveTimeout = timeout; } ++ (void)enableRetry:(BOOL)enabled forHost:(nonnull NSString *)host { + GRPCHost *hostConfig = [GRPCHost hostWithAddress:host]; + hostConfig.retryEnabled = enabled; +} + @end diff --git a/src/objective-c/GRPCClient/private/GRPCHost.h b/src/objective-c/GRPCClient/private/GRPCHost.h index d9916d9303..9a5293d90b 100644 --- a/src/objective-c/GRPCClient/private/GRPCHost.h +++ b/src/objective-c/GRPCClient/private/GRPCHost.h @@ -38,6 +38,7 @@ struct grpc_channel_credentials; @property(nonatomic) int keepaliveInterval; @property(nonatomic) int keepaliveTimeout; @property(nonatomic) id logContext; +@property(nonatomic) BOOL retryEnabled; /** The following properties should only be modified for testing: */ diff --git a/src/objective-c/GRPCClient/private/GRPCHost.m b/src/objective-c/GRPCClient/private/GRPCHost.m index 348989904a..13c2baada5 100644 --- a/src/objective-c/GRPCClient/private/GRPCHost.m +++ b/src/objective-c/GRPCClient/private/GRPCHost.m @@ -85,6 +85,7 @@ static NSMutableDictionary *kHostCache; _secure = YES; kHostCache[address] = self; _compressAlgorithm = GRPC_COMPRESS_NONE; + _retryEnabled = YES; } #ifndef GRPC_CFSTREAM [GRPCConnectivityMonitor registerObserver:self selector:@selector(connectivityChange:)]; @@ -240,6 +241,10 @@ static NSMutableDictionary *kHostCache; args[@GRPC_ARG_DISABLE_CLIENT_AUTHORITY_FILTER] = [NSNumber numberWithInt:1]; } + if (_retryEnabled == NO) { + args[@GRPC_ARG_ENABLE_RETRIES] = [NSNumber numberWithInt:0]; + } + return args; } |