Posts

Showing posts from September, 2017

java jdbc - how to connect to oracle using service name instead of sid

Thin-style Service Name Syntax Thin-style service names are supported only by the JDBC Thin driver. The syntax is: @//host_name:port_number/service_name For example: jdbc:oracle:thin:scott/tiger@//myhost:1521/myservicename

multiple jdbc instance

@Configuration public class DatabaseConfig {     @Bean(name = "dsSlave")     @ConfigurationProperties(prefix="spring.mysql_slave")     public DataSource slaveDataSource() {         return DataSourceBuilder.create().build();     }     @Bean(name = "dsMaster")     @Primary     @ConfigurationProperties(prefix="spring.mysql_master")     public DataSource masterDataSource() {         return DataSourceBuilder.create().build();     }    @Bean(name = "jdbcSlave") @Autowired public JdbcTemplate slaveJdbcTemplate(@Qualifier("dsSlave") DataSource dsSlave) {     return new JdbcTemplate(dsSlave); }     @Bean(name = "jdbcMaster")     @Autowired     public JdbcTemplate masterJdbcTemplate(@Qualifier("dsMaster")DataSource dsMaster) {         return new JdbcTemplate(dsMaster);     } } @Component pu...

Zuul Filter

Image
PRE: Filters execute before routing to the origin. For example: request authentication, logging debug info ROUTING: Filters handle routing the request to an origin. POST: Filters execute after the request has been routed to the origin. ERROR: Filters execute when an error occurs during one of the other phases. package org.springframework.cloud.samplezuulfilters; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.zuul.EnableZuulProxy; import org.springframework.context.annotation.Bean; @EnableZuulProxy @SpringBootApplication public class ZuulGatewayApplication { @Bean public AddResponseHeaderFilter addResponseHeaderFilter() { return new AddResponseHeaderFilter(); } @Bean public ModifyResponseBodyFilter modifyResponseHeaderFilter() { return new ModifyResponseBodyFilter(); } @Bean public ModifyResponseDataStreamFilter modifyResponseDataStreamFilter() { return new Mod...

Study about zuul netflix

Image
Zuul is a JVM based router and server side load balancer by Netflix. It provides a single entry to our system, which allows a browser, mobile app, or other user interface to consume services from multiple hosts without managing cross-origin resource sharing (CORS) and authentication for each one. We can integrate Zuul with other Netflix projects like Hystrix for fault tolerance and Eureka for service discovery, or use it to manage routing rules, filters, and load balancing across your system. Zuul is a JVM based router and server side load balancer by Netflix. Zuul is the front door for all requests from devices and web sites to the backend of the Netflix streaming application. As an edge service application, Zuul is built to enable dynamic routing, monitoring, resiliency and security. Routing in an integral part of a microservice architecture. For example, may be mapped to your web application, /api/users is mapped to the user service and /api/shop is mapped to the shop service. Zuul ...

Spring Cloud- REST call using Netflix Feign Client

Image
Feign is a java to http client binder inspired by Retrofit, JAXRS-2.0, and WebSocket. Feign's first goal was reducing the complexity of binding Denominator uniformly to http apis regardless of restfulness. Previous examples in the employee-consumer we consumed the REST services exposed by the employee-producer using REST Template But we had to write a lot of code to perform following- For Load balancing using Ribbon. Getting the Service instance and then the Base URL. Make use of the REST Template for consuming service. @Controller public class ConsumerControllerClient { @Autowired private LoadBalancerClient loadBalancer; public void getEmployee() throws RestClientException, IOException { ServiceInstance serviceInstance=loadBalancer.choose("employee-producer"); System.out.println(serviceInstance.getUri()); String baseUrl=serviceInstance.getUri().toString(); baseUrl=baseUrl+"/employee"; RestTemplate restTemplate = new RestTemplate(); Re...

FeignClient - Load Balancer with Eureka

Image
feign-eureka-hello-server ========================= HelloServerApplication.java =========================== package demo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /**  * @author Spencer Gibb  */ @SpringBootApplication @EnableDiscoveryClient @RestController public class HelloServerApplication { @Autowired DiscoveryClient client; @RequestMapping("/") public String hello() { ServiceInstance localInstance = client.getLocalServiceInstance(); return "Hello World: "+ localInstance.getServiceId()+":"...

Ribbon - Load Balancer without Eureka

Ribbon is a client side load balancer, which gives you a lot of control over the behavior of HTTP and TCP clients. Ribbon's Client component offers a good set of configuration options such as connection timeouts, retries, retry algorithm (exponential, bounded back off) etc. Ribbon comes built in with a pluggable and customizable Load Balancing component. Some of the load balancing strategies offered are listed below: Simple Round Robin LB Weighted Response Time LB Zone Aware Round Robin LB Random LB Using Ribbon - Code: @SpringBootApplication @RestController @RibbonClient(name = "hello-service", configuration = HelloServiceConfiguration.class) public class UserApplication {     @LoadBalanced     @Bean     RestTemplate restTemplate() {         return new RestTemplate();     }     @Autowired     RestTemplate restTemplate;     @RequestMapping("/hi")     public String hi(@RequestParam(value =...

Load Balancing

Image
 Load Balancing automatically distributes incoming application traffic between two or more computers.  It enables you to achieve fault tolerance in your applications, seamlessly providing the required amount of load balancing capacity needed to route application traffic.  Load balancing aims to optimize resource use, maximize throughput, minimize response time, and avoid overload of any single resource. Using multiple components with load balancing instead of a single component may increase reliability and availability through redundancy.

Eureka Properties

Image
eureka.environment The environment name in which this Eureka cluster is running (dev, staging, prod). eureka.datacenter The datacenter in which this instance is running. eureka.enableSelfPreservation Specifies if this instance should enter Self Preservation Mode in case it cannot contact Eureka servers to refresh its local registry. If set to false, the registry would expire and attempts to locate other services will fail. eureka.client.registerWithEureka Specifies if this instance should register its metadata with Eureka servers to be discovered by other clients. eureka.client.fetchRegistry Specifies if this instance should request the Eureka registry from a Eureka server. eureka.client.serviceUrl.defaultZone Specifies a single or comma-separated URL of alternative Eureka server locations. eureka.instance.hostname The hostname where this instance is running or found out via the OS. eureka.instance.statusPageUrlPath Specifies the relative status page URL for this instance. eure...

how to kill a service binded in particular port

Image
Step 1 Run command-line as an Administrator. Then run the below mention command. type your port number in yourPortNumber netstat -ano | findstr :yourPortNumber Red coloured circled area shows the PID (process identifier) Step 2 Then you execute this command after identify the PID. taskkill /PID typeyourPIDhere /F ---------------------------------------------- Click the Start menu Click Run or in the search bar type services.msc Press Enter Look for the service and check the Properties and identify its service name Once found, open a command prompt. Type sc queryex [servicename]. Press Enter Identify the PID In the same command prompt type taskkill /pid [pid number] /f Press Enter

NetFlix Spring Boot ZUUL Example

tp-eureka-service ================== EurekaServiceApplication.java ============================= package com.techprimers.cloud; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; @EnableEurekaServer @SpringBootApplication public class EurekaServiceApplication { public static void main(String[] args) { SpringApplication.run(EurekaServiceApplication.class, args); } } application.properties ====================== spring.application.name=eureka-service server.port=8070 application.yml =============== eureka:   client:     registerWithEureka: false     fetchRegistry: false   server:       waitTimeInMsWhenSyncEmpty: 0   instance:     hostname: localhost   pom.xml ======= (?xml version="1.0" encoding="UTF-8"?) (project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w...