2

I'm currently working on implementing a gRPC nodejs client that should communicate with a java/kotlin gRPC server to test out the cross language codegen.

However when I try to make a call from my nodejs code I get a serialization failure and I have no idea why this is happening.

I've added as much as I can share, if you need any other code snippets, just ask.

I don't use any proto-loader, but rather have a buf-build setup that generates the code in typescript and Java.

The exact error being displayed is:

 Error: 13 INTERNAL: Request message serialization failure: Expected argument of type com.example.resources.chat.v1.GetActiveChatSessionsRequest

If anyone could point me into the right direction or can help me out, would be greatly appreciated

Proto definition

syntax = "proto3";

package com.example.resources.chat.v1;
option java_package = "com.example.resources.chat.v1";

import "google/protobuf/timestamp.proto";

message ChatRoomOverviewItem {
    string support_ticket_id = 1;
    string chat_room_id = 2;
    int32 number_of_unread_messages = 3;
    google.protobuf.Timestamp last_message_received = 4;
    repeated string participants = 5;
}

message GetActiveChatSessionsRequest {
    string participant_id = 1;
    int32 page = 2;
    int32 limit = 3;
}

message GetActiveChatSessionsResponse {
    bool last = 1;
    int32 total_elements = 2;
    int32 total_pages = 3;
    int32 number_of_elements = 4;
    bool first = 5;
    int32 number = 6;
    bool empty = 7;
    repeated ChatRoomOverviewItem content = 8;
}

gRPC definition

syntax = "proto3";

package com.example.resources.chat.v1;
option java_package = "com.example.resources.chat.v1";

import "com/example/resources/chat/v1/chat.proto";

service ChatApiService {
    rpc GetActiveChatSessions (GetActiveChatSessionsRequest) returns (GetActiveChatSessionsResponse);
}

NodeJS - Client


export const chatService = new ChatApiServiceClient(
    process.env.CHAT_GRPC_URI || 'http://localhost:6565', ChannelCredentials.createInsecure())

---

chatApiService.getActiveChatSessions(new GetActiveChatSessionsRequest()
                .setParticipantId(userId)
                .setPage(req.params.page ? parseInt(req.params.page) : 0)
                .setLimit(req.params.limit ? parseInt(req.params.init) : 25),
            async (error, response) => {
                if (error) throw error
                else {
                    /* handle logic */
                }
            })

Kotlin - Server

@GRpcService
class ChatApiService(
    private val streamObserverHandler: GrpcStreamObserverHandler,
    private val chatRoomService: ChatRoomService,
    private val chatMessageService: ChatMessageService
) : ChatApiServiceImplBase() {

    override fun getActiveChatSessions(
        request: Chat.GetActiveChatSessionsRequest,
        responseObserver: StreamObserver<Chat.GetActiveChatSessionsResponse>
    ) {
        streamObserverHandler.accept(
            chatRoomService.getActiveChatRoomsForUser(
                UUID.fromString(request.participantId),
                PageRequest.of(request.page, request.limit)
            ),
            responseObserver
        )
    }
J.Pip
  • 4,523
  • 7
  • 31
  • 49
  • What is the exact text of the error you are getting? – murgatroid99 Jan 27 '23 at 17:42
  • 1
    @murgatroid99... wow I must've been banging my head against the wall for a couple of hours if I forgot the error. I've updated the question with the error in it, thx for pointing it out – J.Pip Jan 29 '23 at 16:47
  • So did you contact the server with other clients and confirm that the server itself is fine? – Mostafa Fakhraei Jan 31 '23 at 08:55
  • Could you share you JS/TS code for class/function `GetActiveChatSessionsRequest` ? – boehm_s Jan 31 '23 at 09:54
  • @MostafaFakhraei yes, using bloomRPC I’m able to contact the server, afaik the serialization failure happens at the client side, which is where I’m stuck – J.Pip Feb 01 '23 at 00:34
  • By the way, I think there is a typo in your code, which might be causing the error. Can you confirm that `parseInt(req.params.init)` has the value? Because the condition is based on `req.params.limit`. – Mostafa Fakhraei Feb 01 '23 at 06:30
  • Try it with hardcoded values instead of the logic to generate the parameters for the`GetActiveChatSessionsRequest`. Debugging is about reducing complexity to get the smallest minimal reproducer that causes the error. – Josh Wulf Feb 01 '23 at 19:28
  • @JoshWulf that was one of the first things I did XD... still haven't figured out what causes this, I'm currently reworking the app to see where it breaks – J.Pip Feb 02 '23 at 10:27
  • @J.Pip Have you checked the above comment about the typo condition? – Mostafa Fakhraei Feb 02 '23 at 10:29

0 Answers0