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
)
}