Know about Microservice Aggregator Design Pattern.
Know Aggregator Microservice Design Pattern
The Aggregator is something that collects related items or data and displays them (combining and merging of data).
In MSA aggregator is a basic web service that internally invokes various services to get the required information that needs to be aggregated and send back to the requestor.
This pattern helps when you have the requirement of collecting data from various different services and merging the collected information.
Example:
We have two different services namely Student and Address which has their own database, and we need to gather the data from both the service/database.
Which uses a Unique ID as a reference in both databases, thus allowing us to fetch the data from both databases via the web service endpoint and combine or aggregate them with help of the new service Student’s Address which is the aggregator service.
In the next article, we will see in API Gateway design pattern.
In this article, we will see Micro service and Design Patterns.
Micro service and Design Patterns
Micro service aka MSA has become the go-solution for most of the Enterprise to build or migrate the applications. They are known to solve various snags.
In order to build effective Microservice. We need to weld on to the design patterns, which helps us to improve the performance of the application.
Let us see the below topics as part of this article:
Microservices, aka MSA aka microservice architecture, is an style that structures an application as small collection of autonomous services which is surrounded around Business domain or models.
Ethics followed while Designing Microservice Architecture
Independent & Autonomous services
Scalability
Decentralization
Robust Services
Real-Time Load balancing
Availability
Continuous delivery through DevOps integration
Seamless API integration and continuous monitoring
Make WordPress as Android App. Yes, follow the article from top to bottom and do not miss out anything. In the end you will see your website or WordPress blog in Android phone as an application.
You can also publish the app in Google Play Store or any eco-system for Android apps (Such as Amazon app store, Samsung galaxy app store, Honor/Huawei App Gallery and So on).
How to Make WordPress as Android App?
Converting WordPress blog or Website is easy if you have hands-on with Android Studio and Android SDKs.
Yes, you need to know little bit of java coding knowledge and basics of Android application development. Do not worry if you have very little knowledge on these both should also be fine. If you follow this article carefully.
Learn Python in Tamil | பைதான் மொழியைக் கற்றுக்கொள்ளுங்கள் – Python type casting and operators.
Classes & Objects
Python is an object-oriented programming language. Almost everything in Python is an object, with its properties and methods. A Class is like an object constructor, or a “blueprint” for creating objects.
This is kind of Python’s standard initialize method which is invoked during object creation of the class. consider you want to pre-initialize the properties of the class ahead of object creation, then you need to use this method.
class Student:
def __init__(self, sid, name, age):
self.sid = sid
self.name = name
self.age = age
# -------------------------------------------
student1 = Student(100,"Bob", 22)
print(student1.sid)
print(student1.name)
print(student1.age)
In the above class we have “init” method which gets initialized along with the constructor while creating an object and we have self as our first parameter, which is used for identifying the current/own object.
Note: The \__init\__() function is called automatically every time the class is being used to create a new object.
The self Parameter
The self parameter is a reference to the current instance of the class, and is used to access variables that belongs to the class and It doesn’t need to be named like “self”.
We can call it whatever we want, but it should be the first parameter of any function in the class, see below example..
class Student:
def __init__(self, sid, name, age):
self.sid = sid
self.name = name
# -------------------------------------------
student1 = Student(100,"Bob")
del student1.sid
Delete object
class Student:
def __init__(self, sid, name, age):
self.sid = sid
self.name = name
# -------------------------------------------
student1 = Student(100,"Bob")
del student1
Modules
Python Modules
Python modules are .py files that consist of Python code. Any Python file can be referenced as a module.
Some modules are available through the Python Standard Library and are therefore installed with your Python installation.
Others can be installed with Python’s package manager pip.
Additionally, you can create your own Python modules since modules are comprised of Python .py files.
Writing and Importing Modules
Writing Modules
Writing a module is just like writing any other Python file. Modules can contain definitions of functions, classes, and variables that can then be utilized in other Python programs.
From our Python 3 local programming environment or server-based programming environment, let’s start by creating a file hello.py that we’ll later import into another file.
To begin, we’ll create a function that prints Hello, World!:
# math_operations.py (Located under my-own-modules directory)
# Maths Operation
def add(a, b):
print(a + b)
If we run the program on the command line with python math_operations.py nothing will happen since we have not invoked the functions add.
Importing Modules
Let’s create a second file called main_program.py so that we can import the module we just created, and then call the function.
main_program.py
# Import math_operations module - which is nothing but the math_operations.py file
import math_operations
# Call function
math_operation.add(1, 2)
Because we are importing a module, we need to call the function by referencing the module name in DOT " . " notation.
We could instead import the module as from hello import world and call the function directly as world(). You can learn more about this method by reading how to using from … import when importing modules.
Functions
Python Functions
Python functions are written inside .py files which performs the instruction or action written in Python.
each method/function performs set of instruction or operations we wanted to perform. like adding two numbers, checking if the user is admin or not etc.,
Creating Function
In order to create python functions/methods you need to use def key word prefixed. lets see the below example.
# functions.py
# def -> key word tells us this is a method.
# display_app_name(): this is our method name with no parameters, because with in the brackets we have not passes any variable.
def display_app_name():
print("My App Name")
Calling Function
Calling a medhod in Python is easy, just need to use the method name with the brackets. (If method has any parameters, we need to just pass it inside the brackets.)
Learn Python in Tamil | பைதான் மொழியைக் கற்றுக்கொள்ளுங்கள் – Python type casting and operators.
Decision making
Decision making evaluates multiple expressions which produce TRUE or FALSE as an outcome.
Which defines action to take and what statements has to execute when the outcome is TRUE or FALSE otherwise.
Note: Python programming language assumes any non-zero and non-null values as TRUE, and if it is either zero or null, then it is assumed as FALSE value
# if statement
# When you want to check some logical condition and perform actions based on positive result.
x = 8
y = 10
if x > y:
print("X is greater")
print(f"{x}")
print("Program ended")
If-else statement
# if-else statement
# An if statement can be followed by an optional else statement, which executes when the boolean expression is FALSE.
x = 80
y = 10
if x > y:
print("X is greater")
else:
print("Y is greater")
print("Program Ended")
Nested if-else statement
# nested/multiple if-else statement
# When you want to check multiple conditions and perform actions based on the result (TRUE or FALSE).
x = 80
y = 10
z = 90
# Multiple if
if x > y:
print("X is greater")
elif x > z:
print("X is greater")
elif y > z:
print("Y is greater")
else:
print("Z is greater")
# Nested If
if x > y:
if x > z:
print("x is greater")
else:
print("z is greater")
elif y > z:
print("y is greater")
else:
print("z is greater")
print("Program Ended")
Loops
A loop statement allows us to execute a statement or group of statements multiple times.
Along with above loops, we also have the following 3 keywords used during Loops.
Break
Continue
Pass
While loop
# While loop repeatedly executes a target statement as long as a given condition becomes true.
# Example 1 (Simple while loop)
count = 1
while count < 4:
print(count)
count = count + 1
print("Out of while loop")
print("------------------------------")
# Example 2 : Using else Statement with While Loop
count = 0
while count < 4:
print(count)
count = count + 1
else:
print("count is less than 4")
For loop
# For loop
# it has the ability to iterate over the items of any sequence,
# such as a list or a string.
# We can iterate Collection items
# Such as List, Tuple, Set and so on.
# Example 1 : looping list
blog_websites = ["aryanz.co.in", "balamt.in", "wecancode.live"]
for x in blog_websites:
print(x)
# Example 2 : looping string value
name = "John"
for letter in name:
print(letter)
# Example 3: Using else in For loop
for i in range(1,4):
print(i)
else:
print(f"Reached the max range")
Nested loop
# Nested loop
# looping inside another loop is called nested loop
# What is the output of the following code? - Comment your answer here > https://youtu.be/A2qoypUV-ZE
for x in range(1, 5):
for y in range(x-1, x): # 1, 4
print(f"{y}")
print(f"\t")