Implementing durable streams on the server

HTTP-RPC is a secure HTTP API for you RPC interfaces which allows requests and responses to pass between an HTTP client and HTTP server.

When defining durable stream methods , you must include the special construct DurableStreamContext.

DurableStreamContext captures technical (non-business logic) parameters for HTTP-RPC calls, such as:

  • From which position elements should be served.
  • How many elements the client should receive.
  • How long the call may wait (block) on the server side for elements to become available.

You must use these parameters when creating the HTTP-RPC server side implementation.

For this client side interface:

@CordaSerializable
enum class NumberTypeEnum {
    EVEN, ODD
}

@HttpRpcResource("...")
interface NumberSequencesRPCOps : RPCOps {
    @HttpRpcPOST
    fun retrieve(type: NumberTypeEnum): DurableCursorBuilder<String>
}

The server side implementation would be:

class NumberSequencesRPCOpsImpl : NumberSequencesRPCOps {

    override fun retrieve(type: NumberTypeEnum): DurableCursorBuilder<String> {
        return DurableStreamHelper.withDurableStreamContext {
            val pad = when (type) {
                NumberTypeEnum.EVEN -> 2
                NumberTypeEnum.ODD -> 1
            }

            val longRange: LongRange = (currentPosition + 1)..(currentPosition + maxCount)
            val positionedValues = longRange.map { pos -> pos to (pad + pos * 2).toHumanReadableNumber() }
            DurableStreamHelper.outcome(Long.MAX_VALUE, false, positionedValues)
        }
    }
}

In the server side implementation:

  • DurableStreamHelper implements a special DSL syntax to take care of DurableStreamContext, such that server side logic can be implemented assuming that DurableStreamContext is just available.
  • DurableStreamHelper.outcome() returns a correctly typed streaming result from a list of pair values.

To learn more, refer to DurableStreamContext and DurableStreamHelper in the KDocs .

Was this page helpful?

Thanks for your feedback!

Chat with us

Chat with us on our #docs channel on slack. You can also join a lot of other slack channels there and have access to 1-on-1 communication with members of the R3 team and the online community.

Propose documentation improvements directly

Help us to improve the docs by contributing directly. It's simple - just fork this repository and raise a PR of your own - R3's Technical Writers will review it and apply the relevant suggestions.

We're sorry this page wasn't helpful. Let us know how we can make it better!

Chat with us

Chat with us on our #docs channel on slack. You can also join a lot of other slack channels there and have access to 1-on-1 communication with members of the R3 team and the online community.

Create an issue

Create a new GitHub issue in this repository - submit technical feedback, draw attention to a potential documentation bug, or share ideas for improvement and general feedback.

Propose documentation improvements directly

Help us to improve the docs by contributing directly. It's simple - just fork this repository and raise a PR of your own - R3's Technical Writers will review it and apply the relevant suggestions.