AtRpc class
A simple rpc request-response abstraction which uses atProtocol notifications under the hood.
- 'requests' are sent as notifications with a 'key' like: request.<requestId>.domainNameSpace.rpcsNameSpace.baseNameSpace
- 'responses' are sent as notifications with a 'key' like: <ack|nack|success|error>.<requestId>.domainNameSpace.rpcsNameSpace.baseNameSpace
Sample usage:
- Requester:
- Responder:
Constructors
-
AtRpc({required AtClient atClient, required String baseNameSpace, String rpcsNameSpace = '__rpcs', required String domainNameSpace, required AtRpcCallbacks callbacks, required Set<
String> allowList, bool allowAll = false, bool isClient = true, bool isServer = true, bool enableRequestMutex = false}) -
AtRpc.server({required AtClient atClient, required String baseNameSpace, String rpcsNameSpace = '__rpcs', required String domainNameSpace, required RpcRequestHandler requestHandler, Set<
Atsign> ? allowList, required bool allowAll, required bool enableRequestMutex}) -
factory
Properties
- allowAll → bool
-
Allow requests which are not on the allow list.
NOTE: It is the application's request handling code's
responsibility to handle this appropriately, for example by checking
the
fromAtSignagainst theallowListand acting accordingly.final -
allowList
→ Set<
String> -
The list of atSigns you wish to be able to send requests to you. Any
requests received from any atSign not in this list will be discarded
and not delivered to the AtRpcCallbacks.handleRequest callback
final
- atClient → AtClient
-
The AtClient used by this AtRpc
final
- baseNameSpace → String
-
Base namespace, typically the namespace used by the using application.
For example an app called 'Buzz' could have a namespace like
'buzz'or'buzz_app'final - callbacks → AtRpcCallbacks
-
The callback functions which will be called when requests or responses
are received
final
- domainNameSpace → String
-
A namespace within the rpcsNameSpace, allowing logical separation of
different types of RPCs. Apps can then create multiple AtRpc objects,
each of which is sending and / or listening to a subset of the RPCs.
final
- enableRequestMutex → bool
-
Enables the mutex in handleRequestNotification to ensure redundancy
handling across all services that use AtRpc.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- isClient → bool
-
final
- isServer → bool
-
final
- listenerReadyTimeout ↔ Duration
-
How long ready waits for the notification listener before giving up.
getter/setter pair
- maxSendAttempts ↔ int
-
When sending requests and responses, sometimes network is down,
the socket connection is broken, or so on, and a retry is required.
sendRequest and sendResponse will try to send the notification up to
maxSendAttempts times before giving up, pausing for 200
milliseconds before its first retry, 1 second before its second retry
and 5 seconds before its third (and every subsequent) retry. The
default value of 4 means a total maximum of 4 attempts - i.e. a first
attempt and 3 retries
getter/setter pair
-
requestStream
→ Stream<
AtNotification> ? -
The stream of request notifications
no setter
-
responsesEnded
→ Future<
void> -
Completes when the response listener start subscribed has ended, which
is what the client stopping does to it.
no setter
-
responseStream
→ Stream<
AtNotification> ? -
The stream of response notifications
no setter
- rpcsNameSpace → String
-
A namespace within the baseNameSpace which should be used just for RPCs.
Defaults to
'__rpcs'final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
handleRequestNotification(
AtNotification notification) → Future< void> - Not part of API, but visibleForTesting. Receives 'request' notifications, and
-
handleResponseNotification(
AtNotification notification) → Future< void> - Not part of API, but visibleForTesting. Receives 'response' notifications, and
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
ready(
{Duration? timeout}) → Future< void> - Completes once this atSign's notification listener is up.
-
sendRequest(
{required String toAtSign, required AtRpcReq request, String? cryptoProviderId}) → Future< void> -
Sends a request by sending a notification with 'key' of
request.${request.reqId}.$domainNameSpace.$rpcsNameSpace.$baseNameSpacewith payload ofjsonEncode([request].toJson())totoAtSign -
sendResponse(
AtNotification notification, AtRpcReq request, AtRpcResp response) → Future< void> -
Not part of API, but visibleForTesting.
Sends a response. Note that this is marked as
@visibleForTestingas it is only called by handleRequestNotification and is not intended to be used directly by AtRpc users. -
start(
) → void -
Starts listening for notifications of the requests and responses
in the
$domainNameSpace.$rpcsNameSpace.$baseNameSpacenamespace -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- defaultNotificationExpiry ↔ Duration
-
getter/setter pair
- logger → AtSignLogger
-
final