EDAS- "sexy" micro-analysis service

background

For micro-services middleware has been EDAS Ali cloud application development, deployment, which has a unique sexy, and not a lot of support while longing. In the existing micro-services industry development in full swing, the development of simple, efficient deployment, mature EDAS product support and other advantages, let's start with the code today, so that "sexy" tentacle can touch;

EDAS support the development mode

  • dubbo, translated to the native Dubbo EDAS, by way pandoraboot hsf compatible for conversion Dubbo Dubbo development;
  • Spring cloud, native mode to access via EDAS;
  • hsf, natural support, developed by pandora container ways;

Typical RPC

All demo today to explain the classical through RPC calls, registration services, discovery, access and other dimensions is described, and will be combined with limiting degradation functional demo together;

image.png

PROVIDER

RPC role as a core, business-critical deployments code, foreign service interface exposed by way of registration, will be registered with the service EDAS Service Center;

itemcenter-fire

package com.alibaba.edas.carshop.itemcenter;

/**
 * Alibaba Group EDAS. http://www.aliyun.com/product/edas
 */
public interface ItemService {

    public Item getItemById( long id );
    
    public Item getItemByName( String name );
    
}
  • Exposed service interface provides two main ways, getItemById get goods ID, getItemByName acquired trade names

itemcenter

package com.alibaba.edas.carshop.itemcenter;


/**
 * Alibaba Group EDAS. http://www.aliyun.com/product/edas
 */
public class ItemServiceImpl implements ItemService {

    @Override
    public Item getItemById( long id ) {
        Item car = new Item();
        car.setItemId( 1l );
        car.setItemName( "Mercedes Benz" );
        return car;
    }
    @Override
    public Item getItemByName( String name ) {
        Item car = new Item();
        car.setItemId( 1l );
        car.setItemName( "Mercedes Benz" );
        return car;
    }
}
  • itemservice getItemById getItemByName mainly used to implement the interface of these two methods;
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:hsf="http://www.taobao.com/hsf"
       xmlns="http://www.springframework.org/schema/beans"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.taobao.com/hsf
       http://www.taobao.com/hsf/hsf.xsd" default-autowire="byName">
    <bean id="itemService" class="com.alibaba.edas.carshop.itemcenter.ItemServiceImpl" />
    <!-- 提供一个服务示例 -->
    <hsf:provider id="itemServiceProvider" interface="com.alibaba.edas.carshop.itemcenter.ItemService"
        ref="itemService" version="1.0.0">
    </hsf:provider>
</beans>
  • It is injected through spring grammar itemservice method, to expose the service; group assignment If a group is not in hsf way, the default service registration is hsf, older versions do not support the concept of multi-tenant so hsf syntax must be added to group =
package com.alibaba.edas.carshop.itemcenter;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Alibaba Group EDAS. http://www.aliyun.com/product/edas
 */
public class IndexServlet extends HttpServlet {

    private static final long serialVersionUID = -112210702214857712L;

    @Override
    public void doGet( HttpServletRequest req, HttpServletResponse resp ) throws ServletException, IOException {
        PrintWriter writer = resp.getWriter();
        writer.write("OK");
        return;
    }
    
    @Override
    protected void doPost( HttpServletRequest req, HttpServletResponse resp ) throws ServletException, IOException {
        return;
    }

}
  • In the present example made by a simple test demo servlet manner, the provider after successful deployment can be directly tested;

CONSUMER

Consumers began to call to itemservice detail subscription service; also the specific method by spring injection, consistent syntax and bean file PROVIDER of bean file;

    @Override
    public void contextInitialized( ServletContextEvent sce ) {
        ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext( sce.getServletContext() );
        final ItemService itemService = ( ItemService ) ctx.getBean( "item" );
        Thread thread = new Thread( new Runnable() {
            @Override
            public void run() {
                while ( true ) {
                    try {
                        Thread.sleep( 500l );
                        System.out.println( itemService.getItemById( 1111 ) );
                        System.out.println( itemService.getItemByName( "myname is le" ) );
                    } catch ( Throwable e ) {
                        e.printStackTrace();
                    }
                }
            }
        } );
        thread.start();
    }
    public class IndexServlet extends HttpServlet {

    private static final long serialVersionUID = -112210702214857712L;

    @Override
    public void doGet( HttpServletRequest req, HttpServletResponse resp ) throws ServletException, IOException {
        final ItemService itemService = ( ItemService ) StartListener.CONTEXT.getBean("item");
        Item item = itemService.getItemByName(req.getParameter("name"));
        
        PrintWriter write = resp.getWriter();
        write.write(String.format("item id: %s, item name: %s", item.getItemId(),item.getItemName()    ));
    }
    
    @Override
    protected void doPost( HttpServletRequest req, HttpServletResponse resp ) throws ServletException, IOException {
    }

}
  • Subscription service named item ID
  • Consumers demo started in a container by pandoraboot way; once every 500ms Print
  • indexservlet likewise provides a test class

Begin deployment

All the deployment process is completed by configclient on the client ECU, without the use of any relevant script; let's start practice operations;

image.png

Screenshot decomposition according to each of the major functions of meaning:

1) namespace isolation logic resources management, space applications in the barrier can not call each other names;

2) Cluster type: swarm cluster, cluster ECS, container services k8s cluster, the cluster is a unified management of the ECS machine;

3) Application of deployment: jar, war, image deployment;
ready to deploy 3.1) jar ordinary java application directly packaged into JAR;
3.2) WAR, type of Web applications;
3.3) deployed by the docker mirror mode application;

Special environments, sc native applications, and Spring cloud pandora is not the same, the need to deploy a common standard java environment, which requires the deployment edas-container vessel.

image.png

4) Create a deployment environment;

image.png

image.png

Once deployed, the application menu on the left is the dimension of the formation of support functions, all operating buttons on the upper right corner of the application;

image.png

You can see the application for all operations in the "change record", the abnormality can be released by a single investigation and analysis of all published applications appear;

5) to deploy applications

image.png

image.png

After the deployment is complete, the application of state "operating normally" agent has been successfully deployed properly explain, let's start testing.
CONSUMER PROVIDER deploy any test can be used indexservlet type of test we've written;

6) final test

Herein only deploys an application provider, it can be tested directly on the ECU and to be an http request by way of a curl pattern;

image.png

To be continued ......

Guess you like

Origin yq.aliyun.com/articles/706422