Spring WebFlux With Protobuf

Spring WebFlux With Protobuf:

By default Spring Web/WebFlux modules use JSON for exchanging messages & the corresponding message converter. Spring also offers ProtobufHttpMessageConverter for us to use Protobuf if required.

Sample Application:

We would create a simple Spring application is for managing persons with following dependencies.

Person Proto:

I define the Person proto as shown here.

syntax = "proto3";option java_multiple_files = true;
option java_package = "com.vinsguru.models";
message Person {
string name = 1;
int32 age = 2;

Person Repository:

I use a Map as a database in this example and I create a PersonRepository as shown here.

Person Controller:

Lets expose REST APIs for the Person type created using Protobuf.


We were able successfully demonstrate Spring WebFlux with Protobuf. I am able to GET Person object and POST a protobuf Person object successfully. Spring also allows to have both JSON and Protobuf messages in a same application which is interesting!



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vinoth Selvaraj

Vinoth Selvaraj

Principal Software Engineer — passionate about software architectural design, microservices.