The RSocketConnector is used to establish an RSocket connection. It requires a ConnectorConfig object which defines the transport, setup parameters, and optional features like resumption, leasing, and fragmentation.
Configuration Options
setup
Configures the initial RSocket SETUP frame:
payload: An optional Payload containing data and metadata.dataMimeType: MIME type for data (defaults to application/octet-stream).metadataMimeType: MIME type for metadata (defaults to application/octet-stream).keepAlive: Keep-alive interval in milliseconds (defaults to 60000).lifetime: Connection lifetime in milliseconds (defaults to 300000).
transport (Required)
An instance of ClientTransport used to establish the underlying connection.
lease
Enables RSocket Lease functionality:
maxPendingRequests: The maximum number of requests allowed before waiting for a lease (defaults to 256).
resume
Enables RSocket Resumption to recover from connection loss:
cacheSize: Size of the frame cache.tokenGenerator: A function that returns a Buffer to be used as the resumption token.reconnectFunction: An async function (attempt: number) => Promise<void> used to handle reconnection logic.
fragmentation
maxOutboundFragmentSize: Maximum size for outbound fragments (defaults to 0).
const config: ConnectorConfig = {
transport: myTransport,
setup: {
dataMimeType: 'application/json',
keepAlive: 30000
},
lease: {
maxPendingRequests: 100
},
resume: {
tokenGenerator: () => Buffer.from('my-token'),
reconnectFunction: async (attempt) => {
// logic to wait or retry
}
}
};