Chia sẻ kiến thức IT ứng dụng: AI, Backend, Frontend, Full Stack, DevOps & Cloud, and More.

Showing posts with label Backend. Show all posts
Showing posts with label Backend. Show all posts

Monday, July 26, 2021

Creating a Batch Service

 To start from scratch, move on to Starting with Spring Initializr.

To skip the basics, do the following:

When you finish, you can check your results against the code in gs-batch-processing/complete.

Business Data

Typically, your customer or a business analyst supplies a spreadsheet. For this simple example, you can find some made-up data in src/main/resources/sample-data.csv:

Jill,Doe
Joe,Doe
Justin,Doe
Jane,Doe
John,Doe

This spreadsheet contains a first name and a last name on each row, separated by a comma. This is a fairly common pattern that Spring can handle without customization.

Spring batch introduction

Spring Batch is a lightweight, comprehensive batch framework designed to enable the development of robust batch applications vital for the daily operations of enterprise systems. Spring Batch builds upon the characteristics of the Spring Framework that people have come to expect (productivity, POJO-based development approach, and general ease of use), while making it easy for developers to access and leverage more advance enterprise services when necessary. Spring Batch is not a scheduling framework. There are many good enterprise schedulers (such as Quartz, Tivoli, Control-M, etc.) available in both the commercial and open source spaces. It is intended to work in conjunction with a scheduler, not replace a scheduler. 

Spring Batch is also a minimalistic framework to run batch processing applications. It provides reusable functions that are essential in processing large volumes of records, including logging/tracing, transaction management, job processing statistics, job restart, skip, and resource management. It also provides more advanced technical services and features that will enable extremely high-volume and high-performance batch jobs through optimization and partitioning techniques. Simple as well as complex, high-volume batch jobs can leverage the framework in a highly scalable manner to process significant volumes of information.

Spring Batch provides reusable functions that are essential in processing large volumes of records, including logging/tracing, transaction management, job processing statistics, job restart, skip, and resource management. It also provides more advanced technical services and features that enable extremely high-volume and high performance batch jobs through optimization and partitioning techniques. Spring Batch can be used in both simple use cases (such as reading a file into a database or running a stored procedure) as well as complex, high volume use cases (such as moving high volumes of data between databases, transforming it, and so on). High-volume batch jobs can leverage the framework in a highly scalable manner to process significant volumes of information.

Saturday, July 24, 2021

What is backbase

What are Digital Banking Platforms (DBP)?

A digital banking platform (DBP) enables a bank to begin the transformational process of becoming a truly digital bank that is ecosystem-centric. A DBP also enables banks to achieve business optimization. However, that is not the end state. For banks seeking only business optimization as the goal of their digital banking strategy, a digital banking multichannel solution will meet those needs.

Tuesday, March 2, 2021

Beginning Amazon DynamoDB

What Is Amazon DynamoDB?

Amazon DynamoDB is a fully managed NoSQL database service that provides fast and predictable performance with seamless scalability. 

NoSQL is a term used to describe nonrelational database systems that are highly available, scalable, and optimized for high performance. Instead of the relational model, NoSQL databases (like DynamoDB) use alternate models for data management, such as key-value pairs or document storage. For more information, see http://aws.amazon.com/nosql.

Tuesday, October 27, 2020

MyBatis introduction

 MyBatis is a Java persistence framework that couples objects with stored procedures or SQL statements using an XML descriptor or annotations.

MyBatis is free software that is distributed under the Apache License 2.0.

MyBatis is a fork of iBATIS 3.0 and is maintained by a team that includes the original creators of iBATIS. 

MyBatis is a first class persistence framework with support for custom SQL, stored procedures and advanced mappings. MyBatis eliminates almost all of the JDBC code and manual setting of parameters and retrieval of results. MyBatis can use simple XML or Annotations for configuration and map primitives, Map interfaces and Java POJOs (Plain Old Java Objects) to database records

Sunday, August 9, 2020

Beginning playframework

 What is Play?

Play is a high-productivity Java and Scala web application framework that integrates components and APIs for modern web application development. Play was developed by web developers for web application development.

Play uses Model-View-Controller (MVC) architecture so that It is familiar and easy to learn. Play is a full-stack framework so that Play includes all the components you need to build Web Applications and REST services, such as an integrated HTTP server, form handling, Cross-Site Request Forgery (CSRF) protection, a powerful routing mechanism, I18n support, and more.

Play’s lightweight, stateless, web-friendly architecture uses Akka and Akka Streams under the covers to provide predictable and minimal resource consumption (CPU, memory, threads).

Play is non-opinionated about database access, and integrates with many object relational mapping (ORM) layers. It supports Anorm, Slick, and JPA out of the box, but many customers use NoSQL or other ORMs.

Play Requirements

A Play application only needs to include the Play JAR files to run properly. These JAR files are published to the Maven Repository, therefore you can use any Java or Scala build tool to build a Play project. However, Play provides an enhanced development experience (support for routes, templates compilation and auto-reloading) when using the sbt.

Play requires:

  1. Java SE 1.8 or higher
  2. sbt - we recommend the latest version

To check that you have Java SE 1.8 or higher, enter the following in a terminal:

java -version

You should see something like:

openjdk version "1.8.0_222"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_222-b10)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.222-b10, mixed mode)

You can obtain Java SE from Oracle’s JDK Site. 

If you want to use sbt to create a new project, you need to install the sbt launcher on your system. With sbt installed, you can use our giter8 template for Java or Scala to create your own project with a single command, using sbt new. Find the links on the sbt download page to install the sbt launcher on your system and refer to the sbt documentation for details about how to set it up.

After install sbt launcher, we can use sbt command to create Play Java  using sbt new command, for example:

sbt new playframework/play-java-seed.g8

After the template creates the project:

  1. Change into the top level project directory.
  2. Enter sbt run to download dependencies and start the system.
  3. In a browser, enter http://localhost:9000 to view the welcome page.
If I run on Hello World example from https://github.com/playframework/play-samples url, the result will be


The Play application layout

The layout of a Play application is standardized to keep things as simple as possible. After the first successful compilation, the project structure looks like this:

















The app/ directory

The app directory contains all executable artifacts: Java and Scala source code, templates and compiled assets’ sources.

There are three packages in the app directory, one for each component of the MVC architectural pattern:

  • app/controllers
  • app/models
  • app/views

You can add your own packages, for example, an app/services package.

More information is available on https://www.playframework.com/documentation/2.8.x/Anatomy url.

Using the sbt console

You can run single sbt commands directly. For example, to build and run Play, change to the directory of your project and run:

$ sbt run

To launch sbt in the interactive mode, change into the top-level of your project and enter sbt with no arguments:

$ cd my-first-app
my-first-app $  sbt

Tip: you can also launch some commands before getting into sbt shell by running shell at the end of task list. For example:

$ sbt clean compile shell

With sbt in the interactive mode, run the current application in development mode, use the run command:

[my-first-app] $ run

You can also compile your application without running the HTTP server. The compile command displays any application errors in the command window. For example, in the interactive mode, enter:

[my-first-app] $ compile

You can run tests without running the server. For example, in interactive mode, use the test command:

[my-first-app] $ test

Type console to enter the Scala console, which allows you to test your code interactively:

[my-first-app] $ console

Debug: You can ask Play to start a JPDA debug port when starting the console. You can then connect using Java debugger. Use the sbt -jvm-debug <port> command to do that:

$ sbt -jvm-debug 9999

When a JPDA port is available, the JVM will log this line during boot:

Listening for transport dt_socket at address: 9999

You can use sbt features such as triggered execution.

For example, using ~ compile:

[my-first-app] $ ~ compile

The compilation will be triggered each time you change a source file.

If you are using ~ run:

[my-first-app] $ ~ run

The triggered compilation will be enabled while a development server is running.

You can also do the same for ~ test, to continuously test your project each time you modify a source file:

[my-first-app] $ ~ test

You can also run commands directly without entering the Play console. 

For example, enter sbt run:

Use the help command to get basic help about the available commands. You can also use this with a specific command to get information about that command:

[my-first-app] $ help run

Hello World example

Assume that we use of sbt or gradlew commands from a terminal, but you can also integrate Play projects with your favorite IDE.

Code of Hello World app is at https://github.com/playframework/play-samples/tree/2.8.x/play-java-hello-world-tutorial

When you enter http://localhost:9000/ in your browser:

  1. The browser requests the root / URI from the HTTP server using the GET method.
  2. The Play internal HTTP Server receives the request.
  3. Play resolves the request using the routes file, which maps URIs to controller action methods.
  4. The action method renders the index page, using Twirl templates.
  5. The HTTP server returns the response as an HTML page.

At a high level, the flow looks something like this:


 Let’s look at the tutorial project to locate the implementation for:

  1. The routes file that maps the request to the controller method.
  2. The controller action method that defines how to handle a request to the root URI.
  3. The Twirl template that the action method calls to render the HTML markup.


index.scala.html Twirl template file.

public Result index() {
       return ok(views.html.index.render("Your new application is
  return ok(javaguide.hello.html.index.render("Your new application is ready.", assetsFinder));
}

To view the route that maps the browser request to the controller method, open the conf/routes file. A route consists of an HTTP method, a path, and an action. This control over the URL schema makes it easy to design clean, human-readable, bookmarkable URLs. The following line maps a GET request for the root URL / to the index action in HomeController:

GET     /           controllers.HomeController.index

Open app/views/index.scala.html with your text editor. The main directive in this file calls the main template main.scala.html with the string Welcome to generate the page. You can open app/views/main.scala.html to see how a String parameter sets the page title.

conf/routes file:

# Routes

# This file defines all application routes (Higher priority routes first)

# An example controller showing a sample home page

GET     /                           controllers.HomeController.index

GET    /explore                     controllers.HomeController.explore

GET    /tutorial                    controllers.HomeController.tutorial


# Map static resources from the /public folder to the /assets URL path

GET     /assets/*file               controllers.Assets.versioned(path="/public", file: Asset)

So the main steps to create Hello World application include:
  1. Create the Hello World page
  2. Add an action method
  3. Define a route
  4. Customize the greeting

1. Create the Hello World page

Follow the instructions below to add a new Hello World page to this project.

With any text editor, create a file named hello.scala.html and save it in the app/views directory of this project. Add the following contents to the file:

@()(implicit assetsFinder: AssetsFinder)

@main("Hello") {
    <section id="top">
        <div class="wrapper">
            <h1>Hello World</h1>
        </div>
    </section>
}

This Twirl and HTML markup accomplishes the following:

  1. The @ sign tells the template engine to interpret what follows.
  2. In this case, @main("Hello", assetsFinder) calls the main template, main.scala.html and passes it the page title of "Hello" (you can ignore the assetsFinder argument for the time being).
  3. The content section contains the Hello World greeting. The main template will insert this into the body of the page.

Now we are ready to add an action method that will render the new page.

2. Add an action method

To add an action method for the new page:

Open the app/controllers/HomeController.java (or .scala) file. Under the tutorial method and before the closing brace, add the following method:

Java
public Result hello() {
    return ok(views.html.hello.render(assetsFinder));
}
Scala
def hello = Action {
  Ok(views.html.hello())
}

Note that, in HomeController.java, it needs to add following code pieces:

import views.html.*;
import javax.inject.Inject;
..
private final AssetsFinder assetsFinder;

    @Inject
    public HomeController(AssetsFinder assetsFinder) {
        this.assetsFinder = assetsFinder;
    }

3. Define a route

To define a route for the new Hello page That maps the page to the method.:

Open the conf/routes file and add the following line:

GET     /hello      controllers.HomeController.hello

When you add a route to the routes file, Play’s routes compiler will automatically generate a router class that calls that action using an instance of your controller. For more information see the routing documentation. By default, the controller instances are created using dependency injection (see docs for Java and Scala).

You are now ready to test the new page. If you stopped the application for some reason, restart it with the sbt run command.

Enter the URL http://localhost:9000/hello to view the results of your work. The browser should respond with something like the following:

4. Customize the greeting

As the final part of this tutorial, we’ll modify the hello page to accept an HTTP request parameter. The steps include a deliberate mistake to demonstrate how Play provides useful feedback.

To customize the Hello World greeting, follow the instructions below.

In the app/controllers/HomeController.java (or .scala) file, add the helloName action method to accept a name parameter using the following code:

Java
public Result helloName(String name) {
    return ok(views.html.hello.render(name, assetsFinder));
}

In the conf/routes file, add a (name: String) parameter at the end of the hello:

GET  /helloName        controllers.HomeController.helloName(name: String)

In Twirl templates, all variables and their types must be declared. In the app/views/helloName.scala.html file:

  1. Insert a new line at the top of the file.
  2. On that line, add an @ directive that declares the name parameter and its type: @(name: String)
  3. To use the variable on the page, change the text in the <h2> heading from Hello World! to <h2>Hello @name!</h2>.

The end result will be:

@(name: String)(implicit assetsFinder: AssetsFinder)
@main("Hello") {
    <section id="top">
        <div class="wrapper">
            <h2>Hello, @name</h2>
        </div>
    </section>
}

In the browser, enter the following URL and pass in any name as a query parameter to the helloName method: http://localhost:9000/helloName?name=MyName, as the result It shows the following screen


Congrat! Our HelloWorld implementation by using Play framework is done. The first step to finding out Play framework has been completed.

From https://www.playframework.com/documentation/2.8.x/Home

Monday, July 6, 2020

Doing microservices with JHipster

Today many companies are developing applications using Microservices, and Microservices with spring boot is chosen by many big companies in Vietnam.
In JHipster framework, Microservices is also supported. JHipster is a free and open-source application generator used to quickly develop modern web applications and Microservices using Angular or React (JavaScript library) and the Spring Framework.

Some technologies and tools are:

  • Yeoman, a front-end scaffolding tool
  • Spring Boot
  • Angular 8, ReactJS: frontend Javascript frameworks.
  • Swagger, for API documentation
  • Maven, Npm, Yarn, Gulp and Bower are dependency managers and build tools
  • Jasmine, Protractor, Cucumber and Gatling are test frameworks
  • Liquibase is for database versioning

We need to  install Java 8, Git (version control system), NodeJS, Yeoman, Yarn and may be Gulp and Bower also on the computer.

Microservices vs Monolithic architecture

The first question JHipster will ask you is the kind of application you want to generate. You have the choice between two architecture styles:
  • A “monolithic” architecture uses a single, one-size-fits-all application, which contains both the front-end code, and the back-end Spring Boot code.
  • A “microservices” architecture splits the front-end and the back-end, so that it’s easier for your application to scale and survive infrastructure issues.
A “monolithic” application is much easier to work on, so if you don’t have any specific requirements, this is the option we recommend, and our default option.
However, A “monolithic” application is still an Spring Boot application with Microservices support.

Microservices architecture overview

The JHipster microservices architecture works in the following way:
  • A gateway is a JHipster-generated application (using application type microservice gateway when you generate it) that handles Web traffic, and serves an Angular/React application. There can be several different gateways, if you want to follow the Backends for Frontends pattern, but that’s not mandatory.
  • Traefik is a modern HTTP reverse proxy and load balancer that can work with a gateway.
  • The JHipster Registry is a runtime application on which all applications registers and get their configuration from. It also provides runtime monitoring dashboards.
  • Consul is a service discovery service, as well as a key/value store. It can be used as an alternative to the JHipster Registry.
  • JHipster UAA is a JHipster-based User Authentication and Authorization system, which uses the OAuth2 protocol.
  • Microservices are JHipster-generated applications (using application type microservice application when you generate them), that handle REST requests. They are stateless, and several instances of them can be launched in parallel to handle heavy loads.
  • The JHipster Console is a monitoring & alerting console, based on the ELK stack.

In the diagram below, the green components are specific to your application and the blue components provide its underlying infrastructure.

From above picture, we can see that Eureka Server has been wrapped into Jhipster Registry, because the standard architecture of Eureka Server is something like following:

Docker installation

Guide to install docker on windows: https://docs.docker.com/toolbox/toolbox_install_windows/, https://github.com/docker/toolbox/releases
After installation, click on shortcut on desktop of computer to start docker

Then the terminal will appear with messages

Type the docker run hello-world command and press RETURN.

In the first times, It will show errors and then download hello-world example. If you run that command in the second times, It will show above messages. That means the installation of docker is okay.

Install Compose on Windows desktop systems
Docker Desktop for Windows and Docker Toolbox already include Compose along with other Docker apps, so most Windows users do not need to install Compose separately. Docker install instructions for these are here:


Links:
https://www.jhipster.tech/microservices-architecture/
https://spring.io/blog/2015/07/14/microservices-with-spring

Sunday, July 5, 2020

SSO java-servlet-application-with-keycloak

There are some concepts relating to SSO - single sign on in software applications.

What is OpenID?

OpenID allows you to use an existing account to sign in to multiple websites, without needing to create new passwords.
You may choose to associate information with your OpenID that can be shared with the websites you visit, such as a name or email address. With OpenID, you control how much of that information is shared with the websites you visit.
With OpenID, your password is only given to your identity provider, and that provider then confirms your identity to the websites you visit.  Other than your provider, no website ever sees your password, so you don’t need to worry about an unscrupulous or insecure website compromising your identity.
So when talking about OpenID it means we are talking about authentication topics.

Saturday, July 4, 2020

Spring Security Overview

Spring Security is a powerful and highly customizable authentication and access-control framework. It is the de-facto standard for securing Spring-based applications.
Spring Security is a framework that focuses on providing both authentication and authorization to Java applications. Like all Spring projects, the real power of Spring Security is found in how easily it can be extended to meet custom requirements

Saturday, May 9, 2020

Angular 2 with ZK

With the emerging of reactjs and angular2, zk and other old ui java frameworks are standing before of going to history library but now angular2 has been integrated into zk and make it having more custom chosen for users so that zk framework is still used for maintainance and new java projects.

Angular 2 is integrated in zk by using  client command binding to communicate with a Java ViewModel at the server-side.

Wednesday, June 26, 2019

Jakarta EE and JSF 2.x

Jakarta EE

In September 2017, Oracle announced its intention to transition Java EE to the Eclipse Foundation. Java EE has since been rebranded to Jakarta EE, and JSF 2.3 (Eclipse Mojarra) has been adopted for continuation. The next major release of the JSF specification will be Eclipse Mojarra 3.0. (source from JavaWorld).

Sunday, May 26, 2019

Oracle SQL căn bản P2


1> Execute a function that is defined in a package

Question: How can I execute a function that is defined in a package using Oracle/PLSQL?
Answer: To execute a function that is defined in a package, you'll have to prefix the function name with the package name.
package_name.function_name (parameter1, parameter2, ... parameter_n)
You can execute a function a few different ways.

Saturday, March 30, 2019

Create a backend for frontend application architecture

A Backend for Frontend (BFF) architecture can be used to create backends for client-facing mobile or web apps. BFF’s can help support an application with multiple clients while at the same time moving the system into a less-coupled state than a monolith system. This code pattern helps teams iterate features faster and have control over the backends for mobile apps without affecting the experience for a corresponding mobile or web app.

Sunday, September 9, 2018

Beginning elasticsearch

1.Elasticsearch concepts

wikipedia talks about elasticsearch:
Elasticsearch is a search engine based on Lucene. It provides a distributed, multitenant-capable full-text searchengine with an HTTP web interface and schema-free JSON documents. Elasticsearch is developed in Java and is released as open source under the terms of the Apache License. Official clients are available in Java, .NET(C#), PHP, Python, Apache Groovy, Ruby and many other languages.[1] According to the DB-Engines ranking, Elasticsearch is the most popular enterprise search engine followed by Apache Solr, also based on Lucene.[2]

elasticsearch definition from elastic site:
Elasticsearch is a real-time distributed search and analytics engine. It allows you to explore your data at a speed and at a scale never before possible. It is used for full-text search, structured search, analytics, and all three in combination:
  • Wikipedia uses Elasticsearch to provide full-text search with highlighted search snippets, and search-as-you-type and did-you-mean suggestions.
  • The Guardian uses Elasticsearch to combine visitor logs with social -network data to provide real-time feedback to its editors about the public’s response to new articles.
  • Stack Overflow combines full-text search with geolocation queries and uses more-like-this to find related questions and answers.
  • GitHub uses Elasticsearch to query 130 billion lines of code.

Saturday, September 8, 2018

Monday, September 3, 2018

Java Concurrency

1. Java Concurrency from docs.oracle.com
Computer users take it for granted that their systems can do more than one thing at a time. They assume that they can continue to work in a word processor, while other applications download files, manage the print queue, and stream audio. Even a single application is often expected to do more than one thing at a time. For example, that streaming audio application must simultaneously read the digital audio off the network, decompress it, manage playback, and update its display. Even the word processor should always be ready to respond to keyboard and mouse events, no matter how busy it is reformatting text or updating the display. Software that can do such things is known as concurrent software.
The Java platform is designed from the ground up to support concurrent programming, with basic concurrency support in the Java programming language and the Java class libraries. Since version 5.0, the Java platform has also included high-level concurrency APIs. This lesson introduces the platform's basic concurrency support and summarizes some of the high-level APIs in the java.util.concurrent packages.

Database normalization Introduction

Database normalization is the process of restructuring a relational database in accordance with a series of so-called normal forms in order to reduce data redundancyand improve data integrity. It was first proposed by Edgar F. Codd as an integral part of his relational model.
Normalization entails organizing the columns (attributes) and tables (relations) of a database to ensure that their dependencies are properly enforced by database integrity constraints. It is accomplished by applying some formal rules either by a process of synthesis (creating a new database design) or decomposition (improving an existing database design).
=> quá trình chuẩn hóa DB sẽ áp dụng 1 số luật (các dạng chuẩn) để thiết kế các bảng cơ sở dữ liệu sao cho có thể giảm thiếu tối đa dư thừa dữ liệu, sự chính xác của truy vấn dữ liệu, tăng performance truy xuất DB,..

Java EE 7: Building Web Applications with WebSocket, JavaScript and HTML5

Purpose

how to create an application that uses the WebSocket API for real-time communication between a client and a server:
  • Create a Java Platform, Enterprise Edition 7 (Java EE 7) application that uses the WebSocket API
  • Use the OnOpen and OnMessage WebSocket lifecycle events to perform different actions on the Java EE 7 application.
  • Define a client-side WebSocket endpoint by using JavaScript
  • Operate on Plain Old Java Objects (POJOs), in real-time, with actions invoked from a web browser client

Friday, August 31, 2018

ZK - Difference Between @load,@save,@bind

Can someone please explain me the difference between @load,@save,@bind with an example, i have read about them but i got more confused about the basic difference between them. they all look and work in somewhat same manner.
what does it mean when i write something like below
<textbox value="@load(vm.address.streatName)"/>
<datebox value="@save(vm.trip.leaveDate)"/>
<label value="@bind(vm.name)"/>
thanks in advance

Saturday, April 28, 2018

ZK reference

ZK is a component-based UI framework that enables you to build Rich Internet Application (RIA) and mobile applications without having to learn JavaScript or AJAX. You can build highly-interactive and responsive AJAX web applications in pure Java. ZK provides hundreds of components[1] which are designed for various purposes, some for displaying large amount of data and some for user input. We can easily create components in an XML-formatted language, ZUL.
All user actions on a page such as clicking and typing can be easily handled in a Controller. You can manipulate components to respond to users action in a Controller and the changes you made will reflect to browsers automatically. You don't need to care about communication details between browsers and servers, ZK will handle it for you. In addition to manipulating components directly i.e. MVC (Model-View-Controller) pattern [2], ZK also supports another design pattern, MVVM (Model-View-ViewModel) [3] which gives the Controller and View more separation. These two approaches are mutually interchangeable, and you can choose one of them upon your architectural consideration.

Architecture of ZK




Simple Architecture

PHỔ BIẾN

TỔNG LƯỢT XEM