I want to communicate between a RSocket server (written in java using spring boot rsocket) and a C# client using directly the official rsocket .net library : https://github.com/rsocket/rsocket-net
Unfortunately, the java server has trouble to decode the payload and map it to a java class. Obvisouly it does work with a byte array but how I can map it to an object.
This is the server config (over tcp:7000)
spring:
rsocket:
server:
port: 7000
transport: tcp
my server has basically a controller where I want the data be mapped to a java object (here Person):
@Controller
@Log4j2
public class RSocketController {
@MessageMapping("")
void reqFireAndForget(Person data) {
log.info("Received raf request...");
log.info(data.getName());
}
}
The Person java class is this :
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
@Getter
@Setter
public class Person implements Serializable {
int Id;
String Name;
String Address;
}
The client is basically the official github example using tcp Socket transport to the spring boot rsocket server
class Program
{
static async Task Main(string[] args)
{
var client = new RSocketClient(new SocketTransport("tcp://localhost:7000/"), new RSocketOptions() { InitialRequestSize = 3 });
await client.ConnectAsync();
Console.WriteLine("Requesting Raw Protobuf Stream...");
var persondata = new Person() { Id = 1234, Name = "Someone Person", Address = "123 Any Street" };
var personmetadata = new Person() { Id = 567, Name = "Meta Person", Address = "" };
client.RequestFireAndForget(data: ProtobufNetSerializer.Serialize(persondata), metadata: ProtobufNetSerializer.Serialize(personmetadata));
Console.ReadKey();
}
}
C# Person class is as follow :
[ProtoContract]
class Person
{
[ProtoMember(1)] public int Id { get; set; }
[ProtoMember(2)] public string Name { get; set; }
[ProtoMember(3)] public String Address { get; set; }
public override string ToString() => $"{Id}:{Name} ({Address})";
}
options are :
public static readonly RSocketOptions Default = new RSocketOptions()
{
KeepAlive = TimeSpan.FromMinutes(1),
Lifetime = TimeSpan.FromMinutes(3),
DataMimeType = "application/x-protobuf",
MetadataMimeType = "application/x-protobuf",
};
Maybe it is possible to use a Protobuf encoder with a jackson object mapper or something, I have not found anything related
here is the stack :
2020-09-07 15:54:50.005 DEBUG 31324 --- [ctor-http-nio-4] io.rsocket.FrameLogger : receiving ->
Frame => Stream ID: 1 Type: REQUEST_FNF Flags: 0b100000000 Length: 62
Metadata:
+-------------------------------------------------+
| 0 1 2 3 4 5 6 7 8 9 a b c d e f |
+--------+-------------------------------------------------+----------------+
|00000000| 08 b7 04 12 0b 4d 65 74 61 20 50 65 72 73 6f 6e |.....Meta Person|
|00000010| 1a 00 |.. |
+--------+-------------------------------------------------+----------------+
Data:
+-------------------------------------------------+
| 0 1 2 3 4 5 6 7 8 9 a b c d e f |
+--------+-------------------------------------------------+----------------+
|00000000| 08 d2 09 12 0e 53 6f 6d 65 6f 6e 65 20 50 65 72 |.....Someone Per|
|00000010| 73 6f 6e 1a 0e 31 32 33 20 41 6e 79 20 53 74 72 |son..123 Any Str|
|00000020| 65 65 74 |eet |
+--------+-------------------------------------------------+----------------+
2020-09-07 15:54:50.006 DEBUG 31324 --- [ctor-http-nio-4] o.s.m.h.i.reactive.InvocableHelper : Invoking RSocketController#reqFireAndForget[1 args]
2020-09-07 15:54:50.006 DEBUG 31324 --- [ctor-http-nio-4] o.s.m.h.i.reactive.InvocableHelper : Searching for methods to handle MethodArgumentResolutionException
2020-09-07 15:54:50.008 ERROR 31324 --- [ctor-http-nio-4] o.s.m.h.i.reactive.InvocableHelper : No exception handling method
org.springframework.messaging.handler.invocation.MethodArgumentResolutionException: Could not resolve method parameter at index 0 in void ch.akatech.images.controllers.RSocketController.reqFireAndForget(ch.akatech.images.entities.Person): Cannot decode to [ch.akatech.images.entities.Person]GenericMessage [payload=DefaultDataBuffer (r: 0, w: 35, c: 35), headers={dataBufferFactory=DefaultDataBufferFactory (preferDirect=true), rsocketRequester=org.springframework.messaging.rsocket.DefaultRSocketRequester@3b73055b, lookupDestination=, contentType=application/x-protobuf, rsocketFrameType=REQUEST_FNF}]
at org.springframework.messaging.handler.annotation.reactive.PayloadMethodArgumentResolver.decodeContent(PayloadMethodArgumentResolver.java:261) ~[spring-messaging-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.messaging.handler.annotation.reactive.PayloadMethodArgumentResolver.resolveArgument(PayloadMethodArgumentResolver.java:168) ~[spring-messaging-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.messaging.handler.invocation.reactive.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:120) ~[spring-messaging-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.messaging.handler.invocation.reactive.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:183) ~[spring-messaging-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.messaging.handler.invocation.reactive.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:128) ~[spring-messaging-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.messaging.handler.invocation.reactive.InvocableHelper.handleMessage(InvocableHelper.java:194) ~[spring-messaging-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.messaging.handler.invocation.reactive.AbstractMethodMessageHandler.handleMatch(AbstractMethodMessageHandler.java:458) ~[spring-messaging-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.messaging.handler.annotation.reactive.MessageMappingMessageHandler.handleMatch(MessageMappingMessageHandler.java:330) ~[spring-messaging-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.messaging.handler.annotation.reactive.MessageMappingMessageHandler.handleMatch(MessageMappingMessageHandler.java:83) ~[spring-messaging-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.messaging.handler.invocation.reactive.AbstractMethodMessageHandler.handleMessage(AbstractMethodMessageHandler.java:453) ~[spring-messaging-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.messaging.rsocket.annotation.support.MessagingRSocket.lambda$handle$1(MessagingRSocket.java:151) ~[spring-messaging-5.2.8.RELEASE.jar:5.2.8.RELEASE]
I hope you can help me !
A.B