Using HttpRpcClient in polling requests

In the Corda 5 Developer Preview, you can use the native HTTP-RPC client , HttpRpcClient, in your Java/Kotlin code.

HttpRpcClient simplifies Java/Kotlin calls to the HTTP-RPC service.

Here is an RPCOps interface definition for a simple durable stream operation:

@CordaSerializable
enum class NumberTypeEnum {
    EVEN, ODD
}

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

You can write the same definition using HttpRpcClient as if normal interface methods (such as poll) are invoked:

        val client = HttpRpcClient(
                baseAddress = "http://localhost:$port/api/v1/",
                NumberSequencesRPCOps::class.java,
                HttpRpcClientConfig()
                        .username(userAlice.username)
                        .password(requireNotNull(userAlice.password))
        )

        client.use {
            val connection = client.start()
            with(connection.proxy) {
                val cursor = this.retrieve(NumberTypeEnum.EVEN).build()
                with(cursor.poll(100, 100.seconds)) {
                    assertEquals(100, values.size)
                    assert(values.first() == "Two")
                    assert(values.last() == "Two hundreds")
                    assertFalse(this.isLastResult)
                    cursor.commit(this)
                }

                with(cursor.poll(200, 100.seconds)) {
                    assertEquals(200, values.size)
                    assert(values.first() == "Two hundreds and two")
                    assert(values.last() == "Six hundreds")
                    assertFalse(this.isLastResult)
                    // Committed not the last
                    cursor.commit(positionedValues[2].position) // 206
                }
            }
        }

HttpRpcClient uses dynamic proxies to translate interface calls into remote calls to the HTTP-RPC server side.

PositionManager

The HTTP-RPC client is responsible for tracking positions/sequence .

If you’re using Java, you can track positions using the interface PositionManager:

interface PositionManager : Supplier<Long>, Consumer<Long>

PositionManager can get and set position value as a Long value.

You can have a custom implementation of the PositionManager interface. DurableCursorBuilder can use this custom implementation which you can assign to a build before the first durable query is made using the poll method. After the poll method has been called, changes can’t be made to the PositionManager.

By default PositionManager is initialized with InMemoryPositionManager which retains position value inside AtomicLong.

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.