rsocket java(服务器)/c#(客户端):无法解码为[ch.person]genericmessage

e1xvtsh3  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(205)

我想在rsocket服务器(使用spring boot rsocket用java编写)和直接使用官方rsocket.net库的c#客户机之间进行通信:https://github.com/rsocket/rsocket-net
不幸的是,java服务器很难解码有效负载并将其Map到java类。很明显,它确实适用于字节数组,但如何将其Map到对象。
这是服务器配置(通过tcp:7000)

spring:
  rsocket:
    server:
      port: 7000
      transport: tcp

我的服务器基本上有一个控制器,我希望将数据Map到一个java对象(这里是person):

@Controller
@Log4j2
public class RSocketController {

    @MessageMapping("")
    void reqFireAndForget(Person data) {
        log.info("Received raf request...");
        log.info(data.getName());
    }

}

person java类是这样的:

import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

@Getter
@Setter
public class Person implements Serializable {
    int Id;
    String Name;
    String Address;
}

客户机基本上是使用tcp套接字传输到spring boot rsocket服务器的官方github示例

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#人员等级如下:

[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})";
    }

选项包括:

public static readonly RSocketOptions Default = new RSocketOptions()
        {
            KeepAlive = TimeSpan.FromMinutes(1),
            Lifetime = TimeSpan.FromMinutes(3),
            DataMimeType = "application/x-protobuf",
            MetadataMimeType = "application/x-protobuf",
        };

也许有可能使用protobuf编码器和jackson对象Map器之类的东西,我没有发现任何相关的东西
下面是堆栈:

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]

我希望你能帮助我!
a、 b类

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题