This is part 5 of Developing Instagram Clone series, other parts are linked below
Post service is a straight forward service, it provides a CRUD operations for user posts.
It uses MongoDB as a data store and Apache Kafka as a messaging system.
Looking into PostApi controller, you’ll find the following endpoints are exposed.
POST "/posts" //creates new post
DELETE "/posts/{id}" //deletes post by id
GET "/posts/me" // finds current user posts
GET "/posts/{username}" // find user posts
POST "/posts/in" // find posts by ids
It is using Spring data MongoDB, all you have to do to provide an interface and the operations (following spring data conventions) and spring will provide the implementations for you.
Nothing fancy here, I think method names are descriptive.
Also, post service is self descriptive, it provides CURD operations for Post object (create, update, delete, … etc). You’ll find it uses PostEventSender to send Kafka messages which I will discuss in the next section.
It is uses Spring cloud stream, for more info about it, refer to Auth Service.
As you can see, it publishes an event to momentsPostChanged to topic whenever a new post is created, updated or deleted.
We will need to listen to these events to update users’ feed, which we will discuss later in the Feed service.
For kafka configurations, also refer to Auth Service.
#microservices #mongodb #cloud #developer