Thymeleaf

Contents

  1. Introduction
    1. Content Organisation
    2. Flow of control
  2. Brief-on-usage
    1. Dependencies
    2. Defining Layout page
    3. Defining content page
    4. Using script in layout-Content page
  3. Resources and references

Contents can be organised on UI as:

  • master-page[layman term] orLayout page[thyme-leaf specific term] which loads other pages on it (header/Footer)
  • Content page

Flow of control

  • Sprinboot(once added with thymeleaf dependecy) looks for src/main/resources/template folder for UI pages
  • the template or the view pages (basically html files in template folder) interact with Controller
  • Use Model to return data to view and in the return statement put the name of view/template to return to.
  • One thing to note about template is that it’s a normal html file but has a extra attribute specific to thyme-leaf to support it’s features. refer below for syntax

Dependencies-

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

<dependency>
    <groupId>nz.net.ultraq.thymeleaf</groupId>
    <artifactId>thymeleaf-layout-dialect</artifactId>
    <version>2.5.1</version>
</dependency>




Defining Layout Page

The layout page is similar to any other HTML page. However, you must add the xmlns:layout attribute to the  html tag.

<html lang="en" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">

Next, you need to specify the part of the layout page where you want the content to appear. This is done using a div tag with the fragment attribute. So anything outside this div tag would remain fixed while the content of the div tag would be changing. The code below shows how you do this.

<div layout:fragment="content">
    <p>Changing contents</p>
</div>

Defining Content Page

Just like in the layout page, you need to add the xmlns:layout attribute. But additionally, you also must add the layout: decorate attribute as well. The layout:decorate attribute would have a value set to the layout page(without the .html extension).  This is shown below:

<html lang="en" 
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorate="_layout">

Here, the layout page is _layout.html placed inside the templates folder.

Having added this HTML markup, you then need to specify the div tag that would wrap the whole content of the page. This is done as shown below:

<div layout:fragment="content">

<!--Content of the page-->

</div>

At this point, anything you want in the content page must be inside this div tag include modals.

4. Using Scripts in Layout-Content Page [Confusing – need to see reference resources]

First, note that scripts defined in the layout page, apply to both the layout and the content page. However, you may want a script that applies only to the layout page. This is achieved using the th:block tag.

For instance, we want a script called account.js to execute only for the content page. Then take the steps below:

In the layout page, add the following block,

<th:block layout:fragment="script"></th:block>

In the content page, add

<th:block layout:fragment="script">
    <script th:src="@{/js/accounts.js}"></script>
</th:block>

In this case, the accounts.js script is placed inside the js folder in the static folder.

Micro-services Interview

Objective is to provide a stricture of content – kind of memory map that induces interaction/promption !

Introduction – micro-services breaks the monolith architect into small services that are more manageable and serves a single business process (e.g Notification or billing or payment), it adds to agility to development process and releases – less dependency o other code that we are not modifying.

As compared to monolith

Micro-services provides agility in development as compared to monolith but does introduces more added steps for communication , but because the microservies advantages weighs more than it’s cons conapred to monolith . so microserces is a preferred way of development

Number of Steps involved in making/implementing the microservies working –

  • Creating the micro-services (for details refer corresponding section)
  • Locating the micro-services (for details refer corresponding section)

MServices Design pattern

Micro-services introduction

Index

  • 12 factor app

12 factor app – it was documented by heroku based on their experiences with developing micro-services , it outlines set of best practises and guidelines while building the micro-services app

1. Codebase:

  • Principle: Maintain one codebase in version control, deploy multiple instances.
  • Implementation in Java:
    • Use Git for version control.
    • Organize code into a single repository.
    • Employ branching strategies for various environments (dev, staging, prod).
  • Why It’s Needed in Microservices:
    • Enables consistency across different environments.
    • Facilitates coordinated development and deployment of microservices.

2. Dependencies:

  • Principle: Explicitly declare and isolate dependencies.
  • Implementation in Java:
    • Use Maven or Gradle for dependency management.
    • Declare dependencies in project configuration.
    • Isolate dependencies to prevent conflicts.
  • Why It’s Needed in Microservices:
    • Ensures consistent dependencies across microservices.
    • Facilitates modular and independent development.

3. Config:

  • Principle: Store configuration in the environment.
  • Implementation in Java:
    • Utilize environment variables or configuration files.
    • Leverage Spring Boot configuration options.
    • Externalize sensitive configuration.
  • Why It’s Needed in Microservices:
    • Allows dynamic configuration changes without code modification.
    • Enhances portability across various deployment environments.

4. Backing Services:

  • Principle: Treat backing services as attached resources.
  • Implementation in Java:
    • Use connection pools and externalize configurations.
    • Employ abstractions provided by frameworks (e.g., Spring Data).
    • Avoid hardcoding credentials.
  • Why It’s Needed in Microservices:
    • Promotes independence of microservices from underlying infrastructure.
    • Simplifies integration with different backing services.

5. Build, Release, Run:

  • Principle: Separate build, release, and run processes.
  • Implementation in Java:
    • Use build tools for artifact creation.
    • Adopt continuous integration and deployment practices.
    • Separate build and deployment scripts.
  • Why It’s Needed in Microservices:
    • Enables efficient and controlled release processes.
    • Facilitates automation of deployment pipelines.

6. Processes:

  • Principle: Execute the app as stateless processes.
  • Implementation in Java:
    • Design stateless applications, especially in microservices.
    • Use frameworks like Spring Boot for stateless architectures.
  • Why It’s Needed in Microservices:
    • Enhances scalability and fault tolerance.
    • Allows for easy replication and distribution of microservices.

7. Port Binding:

  • Principle: Export services via port binding.
  • Implementation in Java:
    • Expose services through well-defined ports.
    • Use frameworks like Spring Boot for simplified port binding.
  • Why It’s Needed in Microservices:
    • Enables clear communication channels between microservices.
    • Enhances consistency and predictability in service access.

8. Concurrency:

  • Principle: Scale-out via the process model.
  • Implementation in Java:
    • Design applications for horizontal scalability.
    • Leverage Java’s concurrency utilities.
    • Use technologies like Kubernetes for orchestration.
  • Why It’s Needed in Microservices:
    • Facilitates handling increased loads by adding more instances.
    • Allows dynamic scaling based on demand.

9. Disposability:

  • Principle: Maximize robustness with fast startup and graceful shutdown.
  • Implementation in Java:
    • Optimize application startup time.
    • Use frameworks that support graceful shutdown.
    • Implement exception handling for robustness.
  • Why It’s Needed in Microservices:
    • Enables rapid deployment and updates.
    • Enhances the ability to recover from failures gracefully.

10. Dev/Prod Parity:

  • Principle: Keep development, staging, and production environments as similar as possible.
  • Implementation in Java:
    • Use containerization for environment consistency.
    • Apply infrastructure as code practices.
    • Utilize configuration management tools.
  • Why It’s Needed in Microservices:
    • Reduces the likelihood of bugs due to environment differences.
    • Facilitates smoother transitions between development and production.

11. Logs:

  • Principle: Treat logs as event streams.
  • Implementation in Java:
    • Use logging frameworks like SLF4J.
    • Send logs to centralized log management systems.
    • Structure logs for analysis.
  • Why It’s Needed in Microservices:
    • Aids in monitoring and debugging in a distributed environment.
    • Centralized logs provide a comprehensive view of the system.

12. Admin Processes:

  • Principle: Run admin/management tasks as one-off processes.
  • Implementation in Java:
    • Develop separate scripts or utilities for admin tasks.
    • Use frameworks like Spring Batch for batch processing.
  • Why It’s Needed in Microservices:
    • Allows for efficient and isolated execution of administrative tasks.
    • Prevents interference with regular application processes.

Embracing the 12 Factor App principles in Java-based microservices promotes consistency, scalability, and maintainability. It addresses challenges specific to distributed systems and ensures that microservices are developed and deployed in a cloud-native manner.

AWS Cloud Developer Associate Certification

Index

  1. IAM, VPC & AWS Free Tier Account
  2. EC2
    1. Intro
    2. Pricing Model
    3. AMI
    4. EC2 IP Adress
    5. Monitoring
    6. NAT Instance and NAT Gateway
  3. ELB and ASG
  4. VPC
  5. Route53
  6. S3 and cloudfront
  7. IaaC- Cloud formation
  8. EBT- Bean Stack
  9. Lambda
    1. Introduction
    2. Lambda Pricing
    3. Lambda Event source mapping
    4. Lambda event notification
    5. Lambda handler
    6. Lambda synchronous and async
    7. Lambda version
    8. Lambda concurrency
  10. Container -ECS, Fargate, ECR
  11. Developer Tools -CI/CD
    1. Code commit
    2. Code pipeline
    3. Code Build
      • alternatives to Code Build
    4. Code Deploy
      • alternatives to Code Build from aws
  12. RDS and Elastic Cache
    1. Database types – Relational VS non relational
    2. Database types – Operational vs Analytical
    3. Databases Architectures
    4. amazon RDS
    5. Elastic cache
      1. Caching strategies – Lazy load,Write through,TTL
      2. elastic Cache Engines
        1. Memcached
        2. Redis(cluster disabled)
        3. Redis(cluster enabled)
  13. DynamoDB (Stephen)
    1. Introduction
    2. Primary Keys
      1. Partition(Hash)
      2. Partition+Range
    3. WCU
    4. RCU
    5. Eventual and strong consistency
    6. DynamoDB -Reading Data
      1. DynamoDB -Reading Data (Query)
      2. DynamoDB -Reading Data (Scan)
    7. DynamoDB -Writing Data
    8. DynamoDB as Session state Cache
    9. Dynamo dB Transactions
    10. Dynamo dB WritesTypes
  14. API Gateway(Stephen)
    1. Integration with other services
    2. API Gateway- endpoints Types
    3. Deployment stages
    4. API Gateway Integration Types
    5. Caching API Responses
    6. API Gateway- Usage plans and API Keys
    7. API Gateway throlleling
    8. API Gateway – errors
    9. API Gateway – CORS
    10. API Gateway – SECURITY
    11. API Gateway – HTTP API vs Rest API
    12. API Gateway – web Socket
    13. connecting Api
    14. API Gateway Architecture
  15. SAM (Server-less Application Model)(Stephen)
    1. Introduction
    2. SAM-Recipe
    3. CLI Debugging
    4. Policy template
    5. SAM and Code deploy
    6. Exam Summary
    7. SAR(Server-less Application Repository)
  16. Application Integration (SQS, SNS & Kinesis – Stephen above dynamo)
    1. Introduction
    2. Amazon SQS
      1. Standard Queue
      2. Producing Messages
      3. Consuming Messages
      4. Multiple EC2 Instances Consumers
      5. Amazon SQS – Security
      6. SQS – Message Visibility Timeout
      7. Amazon SQS – Dead Letter Queue
      8. Amazon SQS – Delay Queue
      9. Amazon SQS – Long Polling
      10. SQS Extended Client
      11. SQS – Must know API
    3. Amazon SQS – FIFO Queue
      1. SQS FIFO – Deduplication
      2. SQS FIFO – Message Grouping
    4. Amazon SNS
      1. Amazon SNS – How to publish
      2. Amazon SNS – Security
    5. SNS + SQS: Fan Out
    6. Amazon SNS – FIFO Topic
    7. SNS FIFO + SQS FIFO: Fan Out
    8. SNS – Message Filtering
    9. Kinesis
      1. Overview
      2. Kinesis Data Streams
      3. Kinesis Data Streams Security
      4. Kinesis Producers
      5. Kinesis – ProvisionedThroughputExceeded
      6. Kinesis Data Streams Consumers
      7. Kinesis Consumers Types
      8. Kinesis Client Library (KCL)
      9. Kinesis Operation – Shard Splitting
      10. Kinesis Operation – Merging Shards
      11. Kinesis Data Firehose
      12. Kinesis Data Streams vs Firehose
      13. Kinesis Data Analytics (SQL application)
      14. Ordering data into Kinesis
    10. Ordering data into SQS
    11. Kinesis vs SQS ordering
    12. SQS vs SNS vs Kinesis
  17. Monitoring,Logging, Auditing (CloudWatch, X-Ray and CloudTrail)
    1. AWS Monitoring – Section Introduction
    2. Monitoring Overview in AWS
    3. CloudWatch
      1. CloudWatch Metrics
      2. CloudWatch Custom Metrics
      3. CloudWatch Logs
      4. CloudWatch Logs Hands On
      5. CloudWatch Agent & CloudWatch Logs Agent
      6. CloudWatch Logs Metric Filters
      7. CloudWatch Alarms
      8. CloudWatch Alarms Hands On
      9. CloudWatch Events
    4. EventBridge Overview
      1. EventBridge Hands On
    5. X-Ray Overview
      1. X-Ray Hands On
      2. X-Ray: Instrumentation and Concepts
      3. X-Ray: Sampling Rules
      4. X-Ray APIs
      5. X-Ray with Beanstalk
      6. X-Ray & ECS
    6. CloudTrail
      1. CloudTrail Hands On
    7. CloudTrail vs CloudWatch vs X-Ray
    8. AWS Quick Clean-up
  18. Advanced IAM (Stephen + Neel)
    1. STS Overview
    2. IAM best practices
    3. Advanced IAM
    4. IAM Policies & S3 Bucket Policies
    5. Granting a User Permissions to Pass a Role to an AWS Service
    6. Directory Services – Overview
  19. Security Services (Stephen –2nd last + Neel) – KMS, Encryption SDK, SSM Parameter Store
    1. AWS Security – Section Introduction
    2. Encryption 101
    3. KMS
      • KMS Overview
      • KMS Hands On w/ CLI
      • KMS Encryption Patterns and Envelope Encryption
      • Encryption SDK CLI Hands On
      • KMS Limits
      • KMS and AWS Lambda Practice
    4. S3
      1. S3 Security Advanced
      2. S3 Bucket Key
    5. SSM
      • SSM Parameter Store Overview
      • SSM Parameter Store Hands On (CLI)
      • SSM Parameter Store Hands On (AWS Lambda)
    6. Secrets Manager –
      • Secrets Manager Overview
      • Secrets Manager – Hands On
    7. SSM Parameter Store vs Secrets Manager
    8. CloudWatch Logs Encryption
    9. CodeBuild Security
  20. Other server-less- step-function and AppSync
    1. Step Functions Overview
      1. Step Functions – Hands On
      2. Step Functions – Error Handling
      3. Step Functions – Error Handling Hands On
      4. Step Functions – Standard vs Express
    2. AppSync Overview
      1. AppSync Hands On
  21. Cognito:Cognito User pools ,Cognito Identity pools ,Cognito Sync
    1. Cognito Overview
      1. Cognito User Pools(-DB OF USERS CAN provide federated udentity )
      2. Cognito User Pools Hands On
      3. Cognito User Pools – Others
    2. Cognito Identity Pools(id for user ,user can be guest)
      1. Cognito Identity Pools Hands On
    3. Cognito User Pools vs Cognito Identity Pools
    4. Cognito Sync
  22. Exam Tips
    1. Test-1
    2. Test-2
    3. Test-3
    4. Test-4
  23. Quick Notes – as per findings from tests
    1. EC2
      1. Instances-type and billing
    2. Lambda
      1. Versioning
    3. Scaling policy
    4. S3 Bucket
      1. Security
    5. Deployment solution
      1. immutable
      2. blue-green
      3. rolling
      4. rolling-batch
    6. IAM policies
      1. Identity Based
      2. Resource based
      3. Policy types
    7. Security
      1. Security-Group
      2. NACL
      3. Introduction,Defence order, occurrence
    8. ALB
    9. DynamoDB
      1. Read-consistency
  24. FAQs
    1. Lambda

Executor Service

FAQs

Q-What do you understand by Executor Framework in Java

Executor Framework in java has been introduced in JDK 5. Executor Framework handles creation of thread, creating the thread pool and checking health while running and also terminates if needed.

2: What is the role of ExecutorService in Java?

ExecutorService provides different methods to start and terminate thread. There are two methods execute() and submit() in ExecutorService. Execute() method is used for threads which is Runnable and submit() method is used for Callable threads.

3: What is Executors in java Executor Framework?

Ans: Executors is a factory that provides the methods to return ExecutorService, ScheduledExecutorService, ThreadFactory. Find some method details.

newFixedThreadPool(): It returns the pool with fixed number of size. We need to pass the number of threads to this method. If concurrently task are submitted more than the pool size, then rest of task need to wait in queue. It returns ExecutorService.
newScheduledThreadPool: This also creates a fixed size pool but it can schedule the thread to run after some defined delay. It is useful to schedule the task. It returns ScheduledExecutorService.
newCachedThreadPool(): There is no fixed size of this pool. Thread will be created at run time and if there is no task it will alive for 60 second and then die. For short lived threads this pool works good. It returns ExecutorService.

4: What is the role of FutureTask and Future in java?

Ans: FutureTask is a cancellable asynchronous computation in java. It can cancel the task which is running. Once the FutureTask will be cancelled, it cannot be restarted. Future is result of asynchronous computation. Future checks if task is complete and if completed it gets the output.

5: What is difference between shutdownNow() and shutdown() in Executor Framework in java?

shutdown() and shutdownNow() methods belongs to ExecutorService. shutdown() method tries to stop the threads and do not accept new task to execute but it completes the execution which has been submitted. shutdownNow() methods also tries to stop the running threads and will not execute any task which has been submitted but not started.

6: How to terminate a thread in Executor Framework in java?

ExecutorService provides a method awaitTermination(long timeout, TimeUnit unit) that takes time and unit of time as an arguments. After that time thread pool is terminated. Suppose we need to terminate a task just now, then we can do as

ExecutorService.awaitTermination(0, TimeUnit.SECONDS)

How to get return value of a callable thread in java Executor Framework?

Ans: Using Future, we can get the return value of callable thread.

ExecutorService exService = Executors.newCachedThreadPool();
Future<Integer> future=exService.submit(new CallableThread());
int val=future.get();

AWS Cloud Practitioner Certification

Index-Topics to be covered as Questions

  1. Introduction – What is Cloud ? Infrastructure,Shared Responsibility Model
  2. IAM
  3. EC2 -Elastic Compute Cloud
  4. EC2 Instance Storage
  5. ELB & ASG – Elastic Load Balancing & Auto-scaling group
  6. S3
  7. Database & Analytics
  8. Other Compute services – ECS, Lambda,batch, lightsail
  9. Deployments
  10. Global Infrastructure
  11. Cloud Integration
  12. Cloud Monitoring
  13. VPC networking
  14. Security Compliance
  15. Machine Learning
  16. Account management and Billing support
  17. Advance Identity
  18. Other services
  19. AWS Architecting and Ecosystem
  20. Media Services Summary
  21. Exam Tips

Objective

What is it ? and costing cons and pros

Quarkus

What is Quarkus? –

It’s a container first (Kubernetes) application. Quarkus tailors your application for GraalVM and HotSpot. Amazingly fast boot time, incredibly low RSS memory (not just heap size!) offering near instant scale up and high density memory utilization in container orchestration platforms like Kubernetes. We use a technique we call compile time boot

Features

  1. It enables reactive
    1. What is reactive and how it enables?