Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Getting Started with Microservices

Getting Started with Microservices

Understand:
1. Why Microservice ?
2. What is Microservice ?
3. What do we( Developer,Architect, Business..etc) need ?
4. Technology Comparison
5. Microservice Features
6. Spring Boot Features
7. Microservice Communication
8. Testing

Walking Tree Technologies

November 24, 2016
Tweet

More Decks by Walking Tree Technologies

Other Decks in Technology

Transcript

  1. Agenda • Why Microservice ? • What is Microservice ?

    • What do we( Developer,Architect, Business..etc) need ? • Technology Comparison • Microservice Features • Spring Boot Features • Microservice Communication • Testing • Demo
  2. Problem with Monolithic Architecture ➔ Tightly Coupled ➔ Language dependency

    ➔ Scalability ➔ Root Cause Analysis ➔ Monitoring ➔ Auditing ➔ Performance Management Integration Layer (Business Logic) Catalog Query Parts Pricing & Availabilit y Quotatio n Order Order Track ORM Database Pricing
  3. What ? ➔ Software Architecture Style ➔ Loosely coupled ➔

    Language Agnostic ➔ Highly Scalable Catalog ORM Database
  4. What ? “Microservices is a way of breaking large software

    projects into smaller, independent, and loosely coupled modules. Individual modules are responsible for highly defined and discrete tasks and communicate with other modules through simple, universally accessible APIs.”
  5. Software/Service • Loosely coupled • Rest Support • Transaction Management

    • Log Management • Auditing • Scalable • Secure • Statistics We need..
  6. Technologies.. Comparison Rest Support Embedded Container Statistics Support Log Management

    Transaction Management Security DropWizard ✓ ✓ ✓ ✓ ✕ ✓ Spring Boot ✓ ✓ ✓ ✓ ✓ ✓ Apache Karaf ✓ ✓ ✕ ✕ ✓ ✓ Jersey ✓ ✓ ✓ ✓ ✕ ✓ Apache CXF ✓ ✓ ✓ ✓ ✓ ✓
  7. Coupling Microservices definitions says that “Microservices is a way of

    breaking large software projects into smaller, independent, and loosely coupled modules” So, this issue is straightaway solved. Catalog ORM Database Query Parts ORM Database
  8. Language Independent Each service can be developed using different programming

    language Allows you to take advantage of emerging and latest technologies (framework, programming language , programming practice, etc.). Catalog( Spring Boot ) Spring Data NoSql Query Parts( Apache Karaf ) Hibernate RDBMS
  9. Scalability Since microservices are very small part of the complete

    software ecosystem, It is very easy to scale the same. Unlike, the monolithic web application, where if we have to do a scaling, first we have to setup the environment ( apache, tomcat ) and then deploy the war/ear files in that.
  10. Scalability with monolithic ... Integration Layer (Business Logic) Catalog Query

    Parts Pricing & Availabi lity Quotat ion Order Order Track ORM Database Pricing Integration Layer (Business Logic) Catalog Query Parts Pricing & Availabi lity Quotat ion Order Order Track ORM Database
  11. Root Cause Analysis It is always difficult to find the

    root cause in a Single Large Monolithic system. In microservice, fault isolation would be improved and we can easily identify which service is consuming more memory or cpu and we can scale that service easily and fix the issue ( if any ) later.
  12. Logging Strategy Spring Boot provides us the various way to

    achieve logging ➔ Using Aspect ➔ Using logback ➔ Annotation based logging ( When an exception occurs )
  13. @Before("execution(* com.wtc.samplems.controller.*.*(..))") public void logServicebefore(JoinPoint joinPoint) { logger.debug("Completed: " +

    joinPoint); System.out.println( "Completed: " + joinPoint ); } Annotation ( Handling Exception and log ): @ExceptionHandler(Exception.class) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) public @ResponseBody JSONObject handleException(Exception e, HttpServletRequest request) { JSONObject jSONObject = new JSONObject(); jSONObject.put(ConstantsUtility.STATUS, ConstantsUtility.FAILED); UtilityLogger.error("Request Processing Failed in Navigation Serv "+e.getMessage()); return jSONObject; } AspectJ:
  14. <?xml version="1.0" encoding="UTF-8"?> <configuration> <property scope="context" name="logger.type" value="servicename" /> <!--

    <include resource="org/springframework/boot/logging/logback/base.xml" /> --> <include resource="org/springframework/boot/logging/logback/defaults.xml" /> <jmxConfigurator /> <appender name="navigationservices" class="ch.qos.logback.core.rolling.RollingFileAppender"> <Encoding>UTF-8</Encoding> <File>./logs/servive.log</File> <encoder> <pattern>%d ${logger.type} %p %m%n</pattern> </encoder> <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> <maxIndex>10</maxIndex> <FileNamePattern>./logs/navigationservices.log.%i</FileNamePattern> </rollingPolicy> <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> <MaxFileSize>1MB</MaxFileSize> </triggeringPolicy> </appender> <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%d ${logger.type} %p %m%n</pattern> <charset>utf8</charset> </encoder> </appender> <root level="info"> <appender-ref ref="navigationservices" /> </root> </configuration> Logback:
  15. Monitoring Spring boot comes with it’s own monitoring tool called

    “Spring Admin Console” We can monitor various aspects like: ➔ Application health ➔ Memory ➔ JVM ➔ Garbage Collection ➔ Metrics etc.. We can also changelog level without restarting of the application. This would help us in debugging any prod issue Sample UI : https://github.com/codecentric/spring-boot-admin
  16. Auditing Auditing would be achieved using AspectJ We can have

    the information like ➔ Who accessed the URL and from where ➔ How many requests have been successfully served to whom and how many got failed ➔ Which services - How many times - By Whom
  17. Performance Management Until now, We are using several tools to

    perform this task • Jconsole • JvisualVM • Java Mission Control ( Comes with Java 8 ) • Logicmonitor (Paid)
  18. Performance Management Every time a new developer/user comes to the

    environment, we have to educate them to understand each of the tool. Spring Boot gives us a single tool ( Spring Admin Console) to do the performance management as well
  19. Transaction Management Spring gives us various ways to manage the

    transactions, In which two of them are very popular : ➔ Using Aspects ➔ Annotation Based
  20. <!-- the transactional advice (what 'happens'; see the <aop:advisor/> bean

    below) --> <tx:advice id="txAdvice" transaction-manager="txManager"> <!-- the transactional semantics... --> <tx:attributes> <!-- all methods starting with 'get' are read-only --> <tx:method name="get*" read-only="true"/> <!-- other methods use the default transaction settings (see below) --> <tx:method name="*"/> </tx:attributes> </tx:advice> <!-- ensure that the above transactional advice runs for any execution of an operation defined by the FooService interface --> <aop:config> <aop:pointcut id="fooServiceOperation" expression="execution(* x.y.service.FooService.*(..))"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="fooServiceOperation"/> </aop:config> Using Aspect
  21. @Transactional public class DefaultFooService implements FooService { Foo getFoo(String fooName);

    Foo getFoo(String fooName, String barName); . . } <tx:annotation-driven transaction-manager="txManager"/> <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <!-- (this dependency is defined somewhere else) --> <property name="dataSource" ref="dataSource"/> </bean> Annotation
  22. ?