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:
- Annotations
-
- @experimental
Constructors
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
fromAtSign
against theallowList
and 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
- hashCode → int
-
The hash code for this object.
no setterinherited
- 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
-
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
-
sendRequest(
{required String toAtSign, required AtRpcReq request}) → Future< void> -
Sends a request by sending a notification with 'key' of
request.${request.reqId}.$domainNameSpace.$rpcsNameSpace.$baseNameSpace
with 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
@visibleForTesting
as 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.$baseNameSpace
namespace -
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