O'Reilly logo

Microservice Patterns and Best Practices by Vinicius Feitosa Pacheco

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating the service

Previously, the file where the communication layer of our News microservices was located was called views.py. However, the HTTP communication layer does not exist in our application and, consequently, the views.py file doesn't either. Instead, we have a new file called services.py, which is responsible for establishing communication with the message broker. The service.py file is exactly where we will declare the CommandStack and QueryStack.

As always, we will first declare our dependencies. In this part of the following piece of code, we will declare our models and everything necessary for the use of Nameko:

import mongoengine from models import ( CommandNewsModel, Base, QueryNewsModel, ) from sqlalchemy import Sequence ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required