Notes

My latest writings


Thursday, September 28, 2017

Getting started with Spring Boot

What is Spring Boot

Spring Boot is a tool provided by Spring to help you starting a project quickly and easily. This is indeed true, but not the first time.

If you are using Spring Boot for the first time it will take you some time to get all the pieces of the long documentation to really understand how to use it. Spring Boot is simple but I think the documentation doesn’t really show it.

Don’t get confused…

If you want to work with Spring Boot you will inevitably go there http://projects.spring.io/spring-boot. This page is very confusing because you will understand that Spring Boot is a CLI, but also an online tool, and finally the page will suggest you to download a snippet of .xml.

From here you should start be lost and ask yourself questions like, why do I need to download a snippet of code if there is a CLI ? Is this Spring Boot thing a generator or not?

Then, to get more confused they add:
The recommended way to get started using spring-boot in your project is with a dependency management system
Ok, now you are talking about a dependency management system although I just wanted to generate a boilerplate Spring project to start with. This is where you will think that you need to go to the heavy documentation to understand Spring Boot. The good news is that you don’t need to.

So, what is it really?

Spring Boot regroup 2 things.
Spring Boot will help you to:

Generate a project
  • Using the online tool
  • Using the CLI
Run/maintain your project by managing Spring dependencies for you.

Generate a Spring project

Using the online tool Spring Initializer

If you don’t like the command line you can go online to http://start.spring.io and generate your Spring project.

Be careful, by default the tool doesn’t give you much choices, but on the bottom of the page you have a small link to access the full version of the tool.

The tool can take a lot of information as entries like the dependency management system that you want to use (Gradle or Maven), the Java version, or your Spring dependencies. After you have selected your desired options, the tool will send you a .zip file containing your Spring project and that’s it, you are done.

Using the CLI

The Spring Boot CLI provides a command which can generate a Spring project for you, like the Spring Initializr does. But if you prefer to use the CLI, you will have to install it first. It can be installed by several means but the easiest on Mac OS is surely Homebrew.

brew tap pivotal/tap
brew install springboot

Go here if you need instructions to install it on another system.

The command spring init will generate .zip file containing a very basic project structure but it is really helpful and powerful if you add some parameters to the command. Have a look at the documentation here

https://docs.spring.io/spring-boot/docs/current/reference/html/cli-using-the-cli.html#cli-init to get an overview of the possibilities or type spring init — list. If you use all of them you can get something as complete as the online version of the Spring Initializr.

This is an example of the command that you could use:

spring init --build=maven --java-version=1.8 --dependencies=web --packaging=war sample-app.zip

Run/manage your project with Spring Boot

The second use of Spring Boot is to run and maintain the dependencies of your project.

Run your project

To run your project you would need to build it and then run it. But because Spring Boot sets up your project with a Maven plugin, it will do all of that for you.

So, in order to run your project with the help of Maven and Spring Boot, simply run:

mvn spring-boot:run

You should now be able to visit http://localhost:8080 and see the first page of your project.
Don’t be surprised to read the message “Whitelabel Error Page” on the page. It doesn’t mean that your project is not working but instead that your project doesn’t have a page mapped to the url “/”. So all what you need to do here is to create your first controller and start building your web app.

Manage your Spring dependencies

Spring Boot is also very helpful to manage Spring dependencies in a project. Remember that when you generated your project you mentioned Spring dependencies. Those dependencies are indeed spring-boot dependencies which means that Spring Boot will manage them for you.

It will manage for example the versions to be sure that they are compatible but where it shines really is with configuration.

Spring Boot dependencies will allow your Spring project to be automatically configured whenever possible which is quite often actually. That means that your project almost doesn’t require that you manage its configuration yourself. This is a big advantage.

Finally, Spring Boot Actuator aimed at helping you to monitor and manage your application with a set of metrics gathered automatically for you. It adds several endpoints to your application each of them relative to different metrics. Learn more here.

Add other Spring dependencies

You are still able to add Spring dependencies after you generated your project. Go to your software management file and add the sping-boot dependencies that you want. This is an example with Maven.


    org.springframework.boot
    spring-boot-starter-web


    org.springframework.boot
    spring-boot-starter-tomcat
    provided


A word on Gradle and Maven

Although the Maven plugin allows you to build and run your project as a single step, you can still of course use Gradle or Maven to only build your project in order to deploy it.

If you want to use those tool, here is a reminder of how to.

Install Maven:
brew install maven

Build your project with Maven:
mvn clean install

Once you have built your project you should get either a .jar or .war depending of what you chose when you generated your project. Then, you can run your project with:
java -jar target/sample-app-0.0.1-SNAPSHOT.jar

or (for a .war):
java -jar target/sample-app-0.0.1-SNAPSHOT.war

Finally, if you need to, you can also deploy your resulting .war file to a Tomcat server.



References:
blog.benoitvallon.com.

Friday, July 5, 2024

Building a E-commerce Microservices Architecture with Spring Boot and Spring Cloud


In this article, we will walk through the creation of a scalable microservices architecture for an e-commerce application using Java Spring Boot and Spring Cloud. The architecture includes several services such as Config Server, Eureka Server, API Gateway, Auth Service, Order Service, Inventory Service, and Notification Service with Kafka.

Project Structure

The project is organized into the following structure:
ecommerce-microservices
├── config-server
├── eureka-server
├── api-gateway
├── auth-service
├── order-service
├── inventory-service
├── notification-service
├── docker-compose.yml (optional)
└── README.md
        

Config Server

The Config Server manages external configurations for all microservices.
config-server/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>config-server</artifactId>
    <version>1.0.0</version>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>
        
config-server/src/main/resources/application.yml
server:
  port: 8888

spring:
  cloud:
    config:
      server:
        git:
          uri: https://github.com/your-repo/config-repo
        
config-server/src/main/java/com/example/configserver/ConfigServerApplication.java
package com.example.configserver;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;

@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(ConfigServerApplication.class, args);
    }
}
        

Why Use Config Server?

Config Server provides a centralized place to manage external properties for applications across all environments. It uses a Git repository to store configuration files, making it easy to version and manage configurations.

How to Deploy and Run Config Server

To deploy the Config Server, ensure you have a Git repository with configuration files. Then, run the application using:
mvn spring-boot:run
This will start the Config Server on port 8888.

Eureka Server

The Eureka Server is a service registry for locating services.
eureka-server/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>eureka-server</artifactId>
    <version>1.0.0</version>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>
        
eureka-server/src/main/resources/application.yml
server:
  port: 8761

eureka:
  client:
    register-with-eureka: false
    fetch-registry: false
  instance:
    hostname: localhost
        
eureka-server/src/main/java/com/example/eurekaserver/EurekaServerApplication.java
package com.example.eurekaserver;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(EurekaServerApplication.class, args);
    }
}
        

Why Use Eureka Server?

Eureka Server acts as a discovery server for registering and locating microservices. This helps in load balancing and makes it easier to scale services dynamically.

How to Deploy and Run Eureka Server

To deploy the Eureka Server, run the application using:
mvn spring-boot:run
This will start the Eureka Server on port 8761.

API Gateway

The API Gateway routes requests to appropriate services.
api-gateway/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>api-gateway</artifactId>
    <version>1.0.0</version>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-gateway</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security.oauth.boot</groupId>
            <artifactId>spring-security-oauth2-autoconfigure</artifactId>
            <version>2.2.5.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>
        
api-gateway/src/main/resources/application.yml
server:
  port: 8080

spring:
  application:
    name: api-gateway

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/
  instance:
    prefer-ip-address: true

spring:
  security:
    oauth2:
      resourceserver:
        jwt:
          jwk-set-uri: http://localhost:9000/oauth2/default/.well-known/jwks.json
        
api-gateway/src/main/java/com/example/apigateway/ApiGatewayApplication.java
package com.example.apigateway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;

@SpringBootApplication
@EnableEurekaClient
@EnableResourceServer
public class ApiGatewayApplication {
    public static void main(String[] args) {
        SpringApplication.run(ApiGatewayApplication.class, args);
    }
}
        
api-gateway/src/main/java/com/example/apigateway/config/SecurityConfig.java
package com.example.apigateway.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;

@Configuration
@EnableResourceServer
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
            .antMatchers("/h2-console/**").permitAll()
            .anyRequest().authenticated()
            .and()
            .csrf().disable()
            .headers().frameOptions().disable();
    }
}
        

Why Use API Gateway?

The API Gateway handles requests by routing them to the appropriate microservice. It provides a single entry point for the client and helps in securing and managing requests efficiently.

How to Deploy and Run API Gateway

To deploy the API Gateway, run the application using:
mvn spring-boot:run
This will start the API Gateway on port 8080.

Auth Service

The Auth Service handles authentication and authorization using OAuth2.
auth-service/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>auth-service</artifactId>
    <version>1.0.0</version>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-oauth2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>
        
auth-service/src/main/resources/application.yml
server:
  port: 9000

spring:
  application:
    name: auth-service

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/
  instance:
    prefer-ip-address: true

spring:
  datasource:
    url: jdbc:h2:mem:testdb
    driverClassName: org.h2.Driver
    username: sa
    password: password

spring:
  h2:
    console:
      enabled: true

spring:
  jpa:
    hibernate:
      ddl-auto: update
    database-platform: org.hibernate.dialect.H2Dialect
        
auth-service/src/main/java/com/example/authservice/AuthServiceApplication.java
package com.example.authservice;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;

@SpringBootApplication
@EnableEurekaClient
@EnableAuthorizationServer
public class AuthServiceApplication {
    public static void main(String[] args) {
        SpringApplication.run(AuthServiceApplication.class, args);
    }
}
        
auth-service/src/main/java/com/example/authservice/config/AuthorizationServerConfig.java
package com.example.authservice.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;

@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {

    @Autowired
    private AuthenticationManager authenticationManager;

    @Override
    public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
        security.tokenKeyAccess("permitAll()")
                .checkTokenAccess("isAuthenticated()");
    }

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients.inMemory()
                .withClient("client-id")
                .secret("{noop}client-secret")
                .authorizedGrantTypes("password", "authorization_code", "refresh_token")
                .scopes("read", "write")
                .accessTokenValiditySeconds(3600)
                .refreshTokenValiditySeconds(36000);
    }

    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
        endpoints.authenticationManager(authenticationManager);
    }
}
        
auth-service/src/main/java/com/example/authservice/config/WebSecurityConfig.java
package com.example.authservice.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Bean
    @Override
    protected AuthenticationManager authenticationManager() throws Exception {
        return super.authenticationManager();
    }

    @Bean
    @Override
    protected UserDetailsService userDetailsService() {
        InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
        manager.createUser(User.withDefaultPasswordEncoder()
                .username("user")
                .password("password")
                .roles("USER")
                .build());
        return manager;
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
            .anyRequest()
            .authenticated()
            .and()
            .formLogin()
            .permitAll();
    }
}
        

Why Use Auth Service?

The Auth Service handles user authentication and authorization using OAuth2. It provides secure access to resources by issuing JWT tokens.

How to Deploy and Run Auth Service

To deploy the Auth Service, run the application using:
mvn spring-boot:run
This will start the Auth Service on port 9000.

Order Service

The Order Service manages orders within the e-commerce application.
order-service/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>order-service</artifactId>
    <version>1.0.0</version>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.kafka</groupId>
            <artifactId>spring-kafka</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>
        
order-service/src/main/resources/application.yml
server:
  port: 9001

spring:
  application:
    name: order-service

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/
  instance:
    prefer-ip-address: true

spring:
  datasource:
    url: jdbc:h2:mem:testdb
    driverClassName: org.h2.Driver
    username: sa
    password: password

spring:
  h2:
    console:
      enabled: true

spring:
  jpa:
    hibernate:
      ddl-auto: update
    database-platform: org.hibernate.dialect.H2Dialect

spring:
  kafka:
    bootstrap-servers: localhost:9092
    consumer:
      group-id: order-group
        
order-service/src/main/java/com/example/orderservice/OrderServiceApplication.java
package com.example.orderservice;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

@SpringBootApplication
@EnableEurekaClient
public class OrderServiceApplication {
    public static void main(String[] args) {
        SpringApplication.run(OrderServiceApplication.class, args);
    }
}
        
order-service/src/main/java/com/example/orderservice/model/Order.java
package com.example.orderservice.model;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class Order {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String product;
    private int quantity;
    private double price;

    // Getters and setters
}
        
order-service/src/main/java/com/example/orderservice/repository/OrderRepository.java
package com.example.orderservice.repository;

import com.example.orderservice.model.Order;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface OrderRepository extends JpaRepository<Order, Long> {
}
        
order-service/src/main/java/com/example/orderservice/controller/OrderController.java
package com.example.orderservice.controller;

import com.example.orderservice.model.Order;
import com.example.orderservice.repository.OrderRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/orders")
public class OrderController {

    @Autowired
    private OrderRepository orderRepository;

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;

    private static final String TOPIC = "order-topic";

    @PostMapping
    public Order createOrder(@RequestBody Order order) {
        Order savedOrder = orderRepository.save(order);
        kafkaTemplate.send(TOPIC, "Order created: " + savedOrder.getId());
        return savedOrder;
    }

    @GetMapping("/{id}")
    public Order getOrder(@PathVariable Long id) {
        return orderRepository.findById(id).orElse(null);
    }
}
        

Why Use Order Service?

The Order Service manages all operations related to orders. It uses Kafka to send notifications whenever an order is created.

How to Deploy and Run Order Service

To deploy the Order Service, run the application using:
mvn spring-boot:run
This will start the Order Service on port 9001.

Inventory Service

The Inventory Service manages product inventory within the e-commerce application.
inventory-service/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>inventory-service</artifactId>
    <version>1.0.0</version>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.kafka</groupId>
            <artifactId>spring-kafka</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>
        
inventory-service/src/main/resources/application.yml
server:
  port: 9002

spring:
  application:
    name: inventory-service

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/
  instance:
    prefer-ip-address: true

spring:
  datasource:
    url: jdbc:h2:mem:testdb
    driverClassName: org.h2.Driver
    username: sa
    password: password

spring:
  h2:
    console:
      enabled: true

spring:
  jpa:
    hibernate:
      ddl-auto: update
    database-platform: org.hibernate.dialect.H2Dialect

spring:
  kafka:
    bootstrap-servers: localhost:9092
    consumer:
      group-id: inventory-group
        
inventory-service/src/main/java/com/example/inventoryservice/InventoryServiceApplication.java
package com.example.inventoryservice;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

@SpringBootApplication
@EnableEurekaClient
public class InventoryServiceApplication {
    public static void main(String[] args) {
        SpringApplication.run(InventoryServiceApplication.class, args);
    }
}
        
inventory-service/src/main/java/com/example/inventoryservice/model/Inventory.java
package com.example.inventoryservice.model;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class Inventory {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String product;
    private int quantity;

    // Getters and setters
}
        
inventory-service/src/main/java/com/example/inventoryservice/repository/InventoryRepository.java
package com.example.inventoryservice.repository;

import com.example.inventoryservice.model.Inventory;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface InventoryRepository extends JpaRepository<Inventory, Long> {
}
        
inventory-service/src/main/java/com/example/inventoryservice/controller/InventoryController.java
package com.example.inventoryservice.controller;

import com.example.inventoryservice.model.Inventory;
import com.example.inventoryservice.repository.InventoryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/inventory")
public class InventoryController {

    @Autowired
    private InventoryRepository inventoryRepository;

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;

    private static final String TOPIC = "inventory-topic";

    @PostMapping
    public Inventory addInventory(@RequestBody Inventory inventory) {
        Inventory savedInventory = inventoryRepository.save(inventory);
        kafkaTemplate.send(TOPIC, "Inventory added: " + savedInventory.getId());
        return savedInventory;
    }

    @GetMapping("/{id}")
    public Inventory getInventory(@PathVariable Long id) {
        return inventoryRepository.findById(id).orElse(null);
    }
}
        

Why Use Inventory Service?

The Inventory Service manages all operations related to inventory. It uses Kafka to send notifications whenever inventory is updated.

How to Deploy and Run Inventory Service

To deploy the Inventory Service, run the application using:
mvn spring-boot:run
This will start the Inventory Service on port 9002.

Communication Between Services

Microservices communicate using REST APIs and Apache Kafka for asynchronous messaging. Services are registered with Eureka and communicate via Eureka Server.

Testing

Unit and integration tests are implemented using Spring Boot Test.
Example test class:
order-service/src/test/java/com/example/orderservice/OrderServiceApplicationTests.java
package com.example.orderservice;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class OrderServiceApplicationTests {

    @Test
    void contextLoads() {
    }

}
        

Directory Structure

Here's the complete directory structure for the project:
ecommerce-microservices/
├── api-gateway/
│   ├── src/main/java/com/example/apigateway/ApiGatewayApplication.java
│   ├── src/main/resources/application.yml
│   └── pom.xml
├── auth-service/
│   ├── src/main/java/com/example/authservice/AuthController.java
│   ├── src/main/java/com/example/authservice/AuthServiceApplication.java
│   ├── src/main/java/com/example/authservice/SecurityConfig.java
│   ├── src/main/java/com/example/authservice/User.java
│   ├── src/main/java/com/example/authservice/UserRepository.java
│   ├── src/main/resources/application.yml
│   └── pom.xml
├── config-server/
│   ├── src/main/java/com/example/configserver/ConfigServerApplication.java
│   ├── src/main/resources/application.yml
│   └── pom.xml
├── eureka-server/
│   ├── src/main/java/com/example/eurekaserver/EurekaServerApplication.java
│   ├── src/main/resources/application.yml
│   └── pom.xml
├── inventory-service/
│   ├── src/main/java/com/example/inventoryservice/InventoryController.java
│   ├── src/main/java/com/example/inventoryservice/Inventory.java
│   ├── src/main/java/com/example/inventoryservice/InventoryRepository.java
│   ├── src/main/java/com/example/inventoryservice/InventoryServiceApplication.java
│   ├── src/main/resources/application.yml
│   └── pom.xml
├── notification-service/
│   ├── src/main/java/com/example/notificationservice/KafkaConsumerConfig.java
│   ├── src/main/java/com/example/notificationservice/KafkaListenerService.java
│   ├── src/main/java/com/example/notificationservice/NotificationServiceApplication.java
│   ├── src/main/resources/application.yml
│   └── pom.xml
├── order-service/
│   ├── src/main/java/com/example/orderservice/OrderController.java
│   ├── src/main/java/com/example/orderservice/Order.java
│   ├── src/main/java/com/example/orderservice/OrderRepository.java
│   ├── src/main/java/com/example/orderservice/OrderServiceApplication.java
│   ├── src/main/resources/application.yml
│   └── pom.xml
├── docker-compose.yml (optional)
└── README.md

Sunday, July 7, 2024

Twelve-Factor App methodology applying the Developing a Microservice with Spring Boot


12-Factor App Methodology

The 12-Factor App methodology is a set of best practices for building modern web-based applications. It provides guidelines for creating scalable, maintainable, and portable applications that can be deployed across various environments. Here are the twelve factors with examples:

1. Codebase

One codebase tracked in revision control, many deploys. Example: A single Git repository for your e-commerce application that includes all code for various environments (development, staging, production). Branches can be used for feature development and bug fixes.
git clone https://github.com/username/ecommerce-app.git

2. Dependencies

Explicitly declare and isolate dependencies. Example: Using pom.xml in a Maven-based Java project to declare dependencies.
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>2.5.4</version>
</dependency>

3. Config

Store config in the environment. Example: Using environment variables to manage configuration.
# application.properties
spring.datasource.url=${DATABASE_URL}
spring.datasource.username=${DATABASE_USERNAME}
spring.datasource.password=${DATABASE_PASSWORD}
Setting environment variables:
export DATABASE_URL=jdbc:mysql://localhost:3306/mydb
export DATABASE_USERNAME=root
export DATABASE_PASSWORD=secret

4. Backing Services

Treat backing services as attached resources. Example: Configuring a database connection in Spring Boot.
spring.datasource.url=${DATABASE_URL}
This allows you to switch databases easily without changing the code.

5. Build, Release, Run

Strictly separate build and run stages. Example: Using Jenkins to manage build and release pipelines. Build stage: Compile the code, run tests, and package the application.
mvn clean package
Release stage: Combine the build with environment-specific configuration.
java -jar target/myapp.jar --spring.config.location=/path/to/config/
Run stage: Execute the application.
java -jar target/myapp.jar

6. Processes

Execute the app as one or more stateless processes. Example: Running a Spring Boot application as a stateless process.
java -jar target/myapp.jar
State (like session data) is stored in external services like Redis.

7. Port Binding

Export services via port binding. Example: Configuring a Spring Boot application to run on a specific port.
server.port=8080
Accessing the application:
curl http://localhost:8080

8. Concurrency

Scale out via the process model. Example: Running multiple instances of a Spring Boot application using Docker.
docker run -d -p 8080:8080 myapp:latest
docker run -d -p 8081:8080 myapp:latest
Load balancing these instances using Nginx or another load balancer.

9. Disposability

Maximize robustness with fast startup and graceful shutdown. Example: Implementing graceful shutdown in Spring Boot.
@Bean
public ServletWebServerFactory servletContainer() {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
    tomcat.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> {
        connector.setProperty("server.shutdown.graceful", "true");
    });
    return tomcat;
}

10. Dev/Prod Parity

Keep development, staging, and production as similar as possible. Example: Using Docker to ensure the same environment in all stages.
docker build -t myapp:latest .
docker run -e DATABASE_URL=jdbc:mysql://localhost:3306/mydb myapp:latest

11. Logs

Treat logs as event streams. Example: Using a logging framework like Logback to write logs to stdout.
<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss} - %msg%n</pattern>
        </encoder>
    </appender>
    <root level="info">
        <appender-ref ref="STDOUT" />
    </root>
</configuration>

12. Admin Processes

Run admin/management tasks as one-off processes. Example: Running a database migration using Flyway in a Spring Boot application.
java -cp myapp.jar org.flywaydb.core.Flyway migrate


Developing a Microservice with Spring Boot: Applying the Twelve-Factor Methodology

Developing a microservice using Spring Boot involves several steps, from setting up your development environment to implementing features and ensuring the application adheres to best practices, including the twelve-factor methodology. Here's a step-by-step guide:

Step 1: Set Up Your Development Environment

  1. Install JDK: Ensure you have Java Development Kit (JDK) installed. Spring Boot typically requires JDK 8 or later.
  2. Install an IDE: Use an Integrated Development Environment (IDE) like IntelliJ IDEA, Eclipse, or Visual Studio Code.
  3. Install Maven/Gradle: These build tools help manage project dependencies and build lifecycle. Maven is commonly used with Spring Boot.

Step 2: Create a Spring Boot Application

  1. Initialize the Project:
    • Use Spring Initializr (https://start.spring.io/) to generate a basic Spring Boot project. Select dependencies such as Spring Web, Spring Data JPA, and any database connector (e.g., H2, MySQL).
    • Download the generated project and import it into your IDE.
  2. Structure Your Project: A typical Spring Boot project follows the Maven structure:
    ├── src
    │   ├── main
    │   │   ├── java
    │   │   │   └── com
    │   │   │       └── example
    │   │   │           └── mymicroservice
    │   │   │               ├── MyMicroserviceApplication.java
    │   │   │               ├── controller
    │   │   │               ├── service
    │   │   │               └── repository
    │   │   ├── resources
    │   │       └── application.properties
    │   └── test

Step 3: Develop Your Microservice

  1. Define Models: Create Java classes representing your data model.
    package com.example.mymicroservice.model;
    
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    
    @Entity
    public class Product {
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        private Long id;
        private String name;
        private Double price;
    
        // getters and setters
    }
  2. Create Repositories: Use Spring Data JPA to handle database interactions.
    package com.example.mymicroservice.repository;
    
    import com.example.mymicroservice.model.Product;
    import org.springframework.data.jpa.repository.JpaRepository;
    
    public interface ProductRepository extends JpaRepository<Product, Long> {
    }
  3. Implement Services: Write business logic in service classes.
    package com.example.mymicroservice.service;
    
    import com.example.mymicroservice.model.Product;
    import com.example.mymicroservice.repository.ProductRepository;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    
    import java.util.List;
    
    @Service
    public class ProductService {
    
        @Autowired
        private ProductRepository productRepository;
    
        public List getAllProducts() {
            return productRepository.findAll();
        }
    
        public Product getProductById(Long id) {
            return productRepository.findById(id).orElse(null);
        }
    
        public Product saveProduct(Product product) {
            return productRepository.save(product);
        }
    
        public void deleteProduct(Long id) {
            productRepository.deleteById(id);
        }
    }
  4. Create Controllers: Define REST endpoints to handle HTTP requests.
    package com.example.mymicroservice.controller;
    
    import com.example.mymicroservice.model.Product;
    import com.example.mymicroservice.service.ProductService;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.*;
    
    import java.util.List;
    
    @RestController
    @RequestMapping("/products")
    public class ProductController {
    
        @Autowired
        private ProductService productService;
    
        @GetMapping
        public List getAllProducts() {
            return productService.getAllProducts();
        }
    
        @GetMapping("/{id}")
        public Product getProductById(@PathVariable Long id) {
            return productService.getProductById(id);
        }
    
        @PostMapping
        public Product createProduct(@RequestBody Product product) {
            return productService.saveProduct(product);
        }
    
        @DeleteMapping("/{id}")
        public void deleteProduct(@PathVariable Long id) {
            productService.deleteProduct(id);
        }
    }

Step 4: Apply the Twelve-Factor Methodology

  1. Codebase: One codebase tracked in version control, many deploys. Use a version control system like Git.
  2. Dependencies: Explicitly declare and isolate dependencies. Manage dependencies using Maven or Gradle.
  3. Config: Store config in the environment.
    server.port=8080
    spring.datasource.url=jdbc:mysql://localhost:3306/mydb
    spring.datasource.username=root
    spring.datasource.password=secret
  4. Backing Services: Treat backing services as attached resources. Configure external resources (e.g., databases, message brokers) using environment variables.
  5. Build, Release, Run: Strictly separate build and run stages. Use CI/CD pipelines to automate the build and deployment process.
  6. Processes: Execute the app as one or more stateless processes. Ensure the application is stateless, storing any needed state in a database or external service.
  7. Port Binding: Export services via port binding. Spring Boot applications bind to a port and serve requests.
  8. Concurrency: Scale out via the process model. Scale the application horizontally by running multiple instances.
  9. Disposability: Maximize robustness with fast startup and graceful shutdown. Implement graceful shutdown and ensure the application can handle interruptions.
  10. Dev/Prod Parity: Keep development, staging, and production as similar as possible. Use Docker or similar technologies to ensure consistency across environments.
  11. Logs: Treat logs as event streams. Use a logging framework like Logback and externalize logs to a centralized logging system.
  12. Admin Processes: Run admin/management tasks as one-off processes. Use tools like Spring Boot Actuator for management and monitoring.

Step 5: Testing and Deployment

  1. Write Tests: Implement unit tests, integration tests, and end-to-end tests.
    package com.example.mymicroservice;
    
    import com.example.mymicroservice.model.Product;
    import com.example.mymicroservice.service.ProductService;
    import org.junit.jupiter.api.Test;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.boot.test.context.SpringBootTest;
    
    import static org.junit.jupiter.api.Assertions.assertNotNull;
    
    @SpringBootTest
    class MyMicroserviceApplicationTests {
    
        @Autowired
        private ProductService productService;
    
        @Test
        void testGetAllProducts() {
            assertNotNull(productService.getAllProducts());
        }
    }
  2. Package and Deploy: Package the application as a JAR or WAR file and deploy it to your server or cloud platform.
    mvn clean package

Step 6: Monitoring and Maintenance

  1. Monitoring: Use tools like Prometheus and Grafana for monitoring application performance.
  2. Logging: Implement centralized logging using tools like ELK Stack (Elasticsearch, Logstash, Kibana).
  3. Security: Regularly update dependencies and use security practices like OAuth2 for authentication and authorization.
By following these steps and adhering to the twelve-factor methodology, you can develop a robust, scalable, and maintainable microservice using Spring Boot.

Monday, December 3, 2018

Best tips to be a Better Java Developer


If you are a Java developer in early phases of your career, here are some concepts you should read about and learn to be an outstanding Java developer.

All books have been written about these concepts. We will just summarise them here and encourage you to find and read more about them.

1. Thread Safety
All web-applications are multi-threaded applications. If you didn’t know, read about how application containers e.g. Tomcat start a new thread or pick one from a thread pool, to render a new web request. Thread safety is about ensuring access to shared resources is serializable. The most common thread safety mistake? Declaring a private field on a singleton class in your application which is changed by multiple threads.

2. Functional Programming
This came late to Java, specifically in version 1.8. But you should learn and use Streams & Lambda functions in your programs. They make for readable, elegant & concise code, often with improved performance.

3. Thread Local variables
Thread safety was about accessing shared variables safely. Thread local allows you to do just that. Think of them as a HashMap of variables by thread id. However, handle their initialization and clean up with care, especially when using thread pools or you can get into thread safety issues and memory leaks.

4. Mapped Diagnostic Contexts in Logging
Underlying, this works as a thread local variable. But you don’t have to worry about it because most logging frameworks will support it out of the box. The idea is to start and end contexts when logging messages. For instance, at the entry of a request, you can log the API URL and user id, so the logs inside would always carry that context.

5. Understand Classpath
It seems easy. But can cause problems or be the reason for some weird effects such as – Why does this work on my local but not on production? It may be because of class-path ordering wherein a production application container loaders an older jar from a shared class-path.

6. Class-path & Class Loaders
Class loaders work as a hierarchy. Learn about class-loaders that come with running an application in tomcat. Find if the same class can be loaded twice in memory and how.

7. Hot Loading
Did you know JVM supports hot reloading of Java classes? You change the code and then don’t have to re-compile everything and restart the application. Just the class changed is recompiled and its in-memory byte-code is updated. Find which cases this can happen and configure it in your development environment if you haven’t already.

8. Dependency Injection
You don’t call me. I call you. That’s inversion of control and the principle behind dependency injection, popularised by Spring Framework. You already knew it, but do you know the alternative to dependency injection? Learn and understand why dependency injection is better and leads to more extensible and testable code.

9. Properties
You know about properties files. But what are the principles to decide if something should be a system property, an environment variable or a command line argument? The hint is in runtime i.e. when does the property become available and is provided. Nevertheless, you should know how to accept and use each and override when needed e.g. in a test environment.

10. Fat Jar Deployment
Most application frameworks, spring boot comes to mind, have an embedded container deployment mode. That is a DevOps friendly way to deploy on the cloud, instead of tweaking application container settings. Even if there is an operations team managing deployment for you, learn it as its the way forward.

11. ORM & Persistence
ORM (JPA & Hibernate) give you convenience and power. And often people shoot themselves in their leg with it. Learn to use them responsibly and without performance impact. Transaction boundaries, Lazy vs Eager fetching, different types of caching and how to debug performance. But most importantly, when not to use an ORM and just write a SQL query. Hint – when the amount of data is large or is distributed in too many tables.

12. Fault Tolerance and Isolation
Let’s say one of your application API calls another rest API. If the other rest API becomes slow, will your application go down? It will. Because of the slow API, all threads will be consumed and your application will become unresponsive. So design it to be fault tolerant with proper timeouts. You can make it more robust by using Resilience4j that allows setting up retry & fallback, circuit breakers, rate limiters and more.

13. Deployment and run-time environment
Do you know how your application works in production? Whether its a Paas like Heroku or Iaas like AWS, you should know the memory available, available CPUs, disk latency, network latency within different components to design a performant application.

14. Monitoring
Will you know if some API in your application is slow? What are the key performance indicators you should monitor? You can use an APM provider like New Relic, or build your own health checks and metrics using spring boot actuator.

15. Build Lifecycle and Dependency Management
Can you configure a new java project by hand using Maven or Gradle? Setup development and production environment configuration, create build lifecycles tasks to run checkstyle or find bugs, create build commands to run test-cases and generate coverage and so on.

16. Debugging Setup
Many developers do not know how to set this up.  This is a must when running test-cases, but JVM also allows remote debugging by opening up a port your IDE can connect to. Learn how to set it up and you will be finding bugs 10 times faster than your teammates who don’t have it set up.

17. Know your IDE
Whether its Eclipse or IntelliJ, shame on you if you can’t set up a new or existing project in your IDE. The ideas IDE setup will have static code analyser, run and debug test environment, can connect to debug a running JVM with has libraries source code also downloaded. A good workman knows their tools.

18. Learn to Refactor SensiblyMost code is not perfect. Learn to improve some of it as you go, but not all of it in one go. Unlike the others, this one will take time and experience to master. 
Start today.

©hashedin.com

Friday, November 2, 2018

Spring RESTful Web service to generate downloadable Excel as response using JExcel API and Apache POI

JExcelApi is a Java library that is dedicated for reading, writing and modifying Excel spreadsheets. It supports Excel 2003 file format and older versions. You can download JExcelApi from the following link:

To work with JExcelApi, you need to add its only jar file: jxl.jar - to your project’s classpath. Download JExcel

Here we are going to create spring API to download Excel file as response using JExcel Api.



Now call the service as :
http://localhost:8080/demo/excelOutputService/download
This will download the Excel file to download folder or show download popup window.


Create Excel using Apache POI

POI-XSSF - Java API To Access Microsoft Excel Format Files
Apache POI is a popular API that allows programmers to create, modify, and display MS Office files using Java programs.
XSSF is the POI Project's pure Java implementation of the Excel 2007 OOXML (.xlsx) file format.

Prerequisites
· DK1.5 or later versions
· Apache POlibrary (http://poi.apache.org/download.html )

Add following library to classpath:
“C:\poi-3.9\poi-3.9-20121203.jar;”
“C:\poi-3.9\poi-ooxml-3.9-20121203.jar;”
“C:\poi-3.9\poi-ooxml-schemas-3.9-20121203.jar;”
“C:\poi-3.9\ooxml-lib\dom4j-1.6.1.jar;”
“C:\poi-3.9\ooxml-lib\xmlbeans-2.3.0.jar;.;”



Read / Write Excel file (.xls or .xlsx) using Apache POI : Full Example

References:
https://aboullaite.me/spring-boot-excel-csv-and-pdf-view-example/
http://simplejava2.blogspot.com/

Works

What can I do


Branding

Social media Branding is far and away the best technique a company has to boost engagement with its customer base. Even a minimum of involvement, such as making one post a day.

Web Design

Web design is the process of creating websites. It encompasses several different aspects, including webpage layout, content production, and graphic design.

Development

Web Development refers to building, creating, and an maintaining websites. It includes aspects such as web design, web publishing, web programming and database management.

Graphic Design

Graphic design is the process of visual communication and problem-solving through the use of typography, photography, and illustration. The field is considered a subset of visual communication and communication design.

Photography

Photography is the art, application and practice of creating durable images by recording light or other electromagnetic radiation, either electronically by means of an image sensor, or chemically by means of a light-sensitive material such as photographic film.

User Experience

User experience (UX) design is the process design teams use to create products that provide meaningful and relevant experiences to users. This involves the design of the entire process of acquiring and integrating the product, including aspects of branding, design.

Contact

Get in touch with me


Adress/Street

Bangalore, India