Tuesday, August 27, 2019

Automate: Create Remote Desktop connection

How to connect to remote machine automatically running a bat file in Windows.
This will ease your life.

below is the sample line

cmdkey /generic:"IP Address" /user:"UserName" /pass:"Password"
mstsc /v:"IP Address"
eg:

cmdkey /generic:111.111.111.111 /user:Domain\user.name /pass:password
mstsc /v:111.111.111.111

Wednesday, August 21, 2019

Microservice - Create Eureka Server

In micro service architecture, Discovery server is a key component.
As we don't have to build everything from the scratch, we have Eureka server which can use very easily with very much less code.

1. Create java project

Create the project using starter io , https://start.spring.io/
Make sure you do this as a habit, Do not create project manually with creating pom file etc. That was old fashion and get use to use the available resources.

Here you can give

  1. Project type -  Maven , Gradle 
  2. Language =Java, Groovy, Kotlin
  3. Spring Boot version = 2.2. M5 , 2.17 etc
  4. Project meta data  = which used give in creating pom file
    1. group  - com.test.micro
    2. artifact  - eurekaServer
    3. Description - Demo project for Eureka Server
    4. package name - com.test.micro.eurekaServer
    5. packaging - Jar | War
    6. java version - 12, 11, 8
  5. dependencies = Eureka server , Actuator, devtools

2. download the project and open with eclipse and run

This will give some errors
It will try to behave as a Eureka Client
use "@EnableEurekaServer" to make this a Eureka server

package com.saap.micro.eurekaServer;

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

@EnableEurekaServer
@SpringBootApplication
public class EurekaServerApplication {

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

}


As we have not given any properties to configure, This will start with default configs

taking port 8080 as default port
you can acess the eureka server via below url

http://localhost:8080/

As we have no any running clients, we will have an empty dashboard.







Now let's add an yml file and configure the Discovery server as we want.

Create "application.yml" file inside "resources"  folder  (  eurekaServer\src\main\resources)



eureka:
  instance:
    hostname: localhost
  client:  # Not a client, don't register with yourself
    registerWithEureka: false
    fetchRegistry: false

server:
  port: 1111   # HTTP (Tomcat) port



you will get the console out as below - see 1111 newly created port





you can see the port in the console out put also

================================================================

INFO 18152 --- [      Thread-16] e.s.EurekaServerInitializerConfiguration : Started Eureka Server
INFO 18152 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 1111 (http) with context path ''
INFO 18152 --- [  restartedMain] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 1111
INFO 18152 --- [  restartedMain] c.s.m.e.EurekaServerApplication          : Started EurekaServerApplication in 11.818 seconds (JVM running for 12.9)
INFO 18152 --- [io-1111-exec-10] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
INFO 18152 --- [io-1111-exec-10] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
INFO 18152 --- [io-1111-exec-10] o.s.web.servlet.DispatcherServlet        : Completed initialization in 17 ms


package com.saap.micro.eurekaServer;

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

@EnableEurekaServer
@SpringBootApplication
public class EurekaServerApplication {

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

}