Skip to content

Setup Payload for RequestChannel #465

Closed

Description

@phoad

According to the protocol (https://github.com/rsocket/rsocket/blob/master/Protocol.md#frame-request-channel), channels have a setup payload that can be used to indicate to the backend which service is requested and therefore which handler should attach to this channel (similar to requestStream).

However, in both the rsocket-cpp implementation, request channel does not allow specifying an initial Payload also in rsocket-java.
https://github.com/rsocket/rsocket-java/blob/1.0.x/rsocket-core/src/main/java/io/rsocket/RSocketClient.java#L214

So we will have an initial payload and not just an inputstream, as almost all real world us cases need an initial payload to do setup, routing, determine the handler, etc.

Activity

  1. self-assigned this
    on Jan 29, 2018
  2. robertroeser commented on Feb 20, 2018

    @robertroeser
    Member

    This isn't necessary. Unless things has changed the payload in the requestChannel method signature was same as the first channel in the stream. This was removed on purpose. RSocket have an operator called SwitchTransform that you can use to switch on the payload for routing. We do this in Proteus in the RequestHandlingRSocket: https://github.com/netifi-proteus/proteus-java/blob/master/core/src/main/java/io/netifi/proteus/rs/RequestHandlingRSocket.java#L100

    The java RSockets are now composable - that wasn't true before when we had a request handler class. Everything in the Java version is an RSocket and we were able to get rid of handler class.

  3. yschimke commented on Feb 20, 2018

    @yschimke
    Member

    My concern here is two teams building two different semantics for the same operations.

    cpp - setup frame, pushed initially on connection, received before any subscription etc.
    java - first frame is the first in the stream.

    They may be mappable to each other, but they are confusingly different models. IMHO.

  4. robertroeser commented on Feb 20, 2018

    @robertroeser
    Member

    The Java requestChannel has always worked the same way. The payload in the method signature was always the first payload in the stream. All we did is remove the 'convenience' field so we don't need a handler, and made RSockets composable. If you are doing something different like the first payload that comes in is not the first payload in the stream then you changed the way the spec works, or interrupted it differently.

  5. robertroeser commented on Feb 20, 2018

    @robertroeser
    Member
  6. lexs commented on Feb 20, 2018

    @lexs
    Contributor

    @robertroeser Which spec are you talking about here? rsocket says this:

    REQUEST_CHANNEL
    ...
    Request Data: identification of the service being requested along with parameters for the request.
    

    This seems pretty clear to me, the data in the REQUEST_CHANNEL is distinct from the channel itself, and should be specified separately, which is what @phoad proposes here.

  7. robertroeser commented on Feb 21, 2018

    @robertroeser
    Member

    @lexs If that's what you see than it's not clear, because Request Data description is the same thing fire/forget, requestChannel, requestStream, and request/Reply

    I literally remember Ben adding that payload there because its hard to pull the first payload out of an observable and then add it back into the stream and process it - thus the payload outside the stream - which is identical to the first payload in the stream. It is not a special setup payload, and if that is the way CPP implements its either wrong or the spec has changed.

  8. lexs commented on Feb 21, 2018

    @lexs
    Contributor

    Are you saying that the payload in the REQUEST_CHANNEL frame is identical to the first PAYLOAD? That's extremely confusing and makes it quite hard to do any routing for different REQUEST_CHANNELs. Also seems exactly opposite of what the spec says (see the above comment).

  9. robertroeser commented on Feb 22, 2018

    @robertroeser
    Member

    @lexs Please look at the frames below included in this post - they all have the same message. There is no 'setup' payload.

    Are you saying that the payload in the REQUEST_CHANNEL frame is identical to the first PAYLOAD?
    No - in the method signature requestChannel(Payload payload, Publisher publisher) the payload there is the same as the first item emitted from publisher. It was done that way so it was easier to route (like you pointed out). We removed this, and wrote SwitchTransform to do this instead.

    We think this is a better API then CPP version / old Java version because the client and server are now symmetric, and everything can implement as RSockets which are composable. You have one abstraction for everything with the same behavior. For instance you can use the
    SpectatorRSocket socket
    https://github.com/rsocket/rsocket-java/blob/1.0.x/rsocket-spectator/src/main/java/io/rsocket/spectator/SpectatorRSocket.java
    on both the client and the server - you don't have to have a special RequestHandler, and another one for the client.

    We did the same thing with DuplexConnection - please take a look at the FragmentationDuplexConnection
    https://github.com/rsocket/rsocket-java/blob/1.0.x/rsocket-core/src/main/java/io/rsocket/fragmentation/FragmentationDuplexConnection.java

    See the fields below all Request Data fields say: identification of the service being requested along with parameters for the request.

    REQUEST_RESPONSE Frame (0x04)
    
    Frame Contents
    
         0                   1                   2                   3
         0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        |                           Stream ID                           |
        +-----------+-+-+-+-------------+-------------------------------+
        |Frame Type |0|M|F|     Flags   |
        +-------------------------------+
                             Metadata & Request Data
    
        Frame Type: (6 bits) 0x04
        Flags: (10 bits)
            (M)etadata: Metadata present
            (F)ollows: More fragments follow this fragment.
        **Request Data: identification of the service being requested along with parameters for the request.**
    
    
    REQUEST_FNF (Fire-n-Forget) Frame (0x05)
    
    Frame Contents
    
         0                   1                   2                   3
         0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        |                           Stream ID                           |
        +-----------+-+-+-+-------------+-------------------------------+
        |Frame Type |0|M|F|    Flags    |
        +-------------------------------+
                              Metadata & Request Data
    
        Frame Type: (6 bits) 0x05
        Flags: (10 bits)
            (M)etadata: Metadata present
            (F)ollows: More fragments follow this fragment.
        **Request Data: identification of the service being requested along with parameters for the request.**
    
    
    REQUEST_STREAM Frame (0x06)
    
    Frame Contents
    
         0                   1                   2                   3
         0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        |                           Stream ID                           |
        +-----------+-+-+-+-------------+-------------------------------+
        |Frame Type |0|M|F|    Flags    |
        +-------------------------------+-------------------------------+
        |0|                    Initial Request N                        |
        +---------------------------------------------------------------+
                              Metadata & Request Data
    
        Frame Type: (6 bits) 0x06
        Flags: (10 bits)
            (M)etadata: Metadata present
            (F)ollows: More fragments follow this fragment.
        Initial Request N: (31 bits = max value 2^31-1 = 2,147,483,647) Unsigned 31-bit integer representing the initial number of items to request. Value MUST be > 0.
        **Request Data: identification of the service being requested along with parameters for the request.**
    
    REQUEST_CHANNEL Frame (0x07)
    
    Frame Contents
    
         0                   1                   2                   3
         0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        |                           Stream ID                           |
        +-----------+-+-+-+-+-----------+-------------------------------+
        |Frame Type |0|M|F|C|  Flags    |
        +-------------------------------+-------------------------------+
        |0|                    Initial Request N                        |
        +---------------------------------------------------------------+
                               Metadata & Request Data
    
        Frame Type: (6 bits) 0x07
        Flags: (10 bits)
            (M)etadata: Metadata present
            (F)ollows: More fragments follow this fragment.
            (C)omplete: bit to indicate stream completion.
                If set, onComplete() or equivalent will be invoked on Subscriber/Observer.
        Initial Request N: (31 bits = max value 2^31-1 = 2,147,483,647) Unsigned 31-bit integer representing the initial request N value for channel. Value MUST be > 0.
        **Request Data: identification of the service being requested along with parameters for the request.**
    
  10. lexs commented on Feb 26, 2018

    @lexs
    Contributor

    In rsocket-cpp the first emitted item was never the same as the request data payload. This is where my confusion stems from.

    I find it fairly confusing that the first item of a channel would have a completely different type than the rest, as the first payload (the request data) is the request params. I much rather keep the old API (and not having the first emitted payload be the payload that is part of the REQUEST_CHANNEL frame.

    I'm not following why this makes it harder to be symmetric, the RSocket class would still exist, the contract is still the same on either side. requestData is the data in the REQUEST_CHANNEL and is not duplicated in any stream.

    public Flux<Payload> requestChannel(Payload requestData, Publisher<Payload> payloads);
  11. rstoyanchev commented on Feb 27, 2018

    @rstoyanchev
    Contributor

    @robertroeser, I'm trying to understand the argument about client and server symmetry. If there was Payload setup argument on requestChannel wouldn't that be used on both sides? The requester for sending the setup, and the responder for processing the setup.

    To achieve this currently, one has to use SwitchTransform on the responder side, and attach metadata to the first item in the requester Flux, which amounts to the same but requires more effort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions