Giter Club home page Giter Club logo

web-route-spring-boot-starter's Introduction

web-route-spring-boot-starter

Web Route Spring Book Edition

δΈ­ζ–‡

Support Function:

  • WebRoute

WebRoute:

Make Web Clustering More Selective
If You Use The spring-boot-starter-web Framework, You Need To Replace The Container With Jetty Or Undertow
The Project Uses HttpHeader For Routing

Quick Start

<!--Adding dependencies to pom. XML-->
        <dependency>
            <artifactId>web-route-spring-boot-starter</artifactId>
            <groupId>com.github.thierrysquirrel</groupId>
            <version>1.0.0.0-RELEASE</version>
        </dependency>

configuration file

## application.properties
web.route.url=127.0.0.1:9090
web.route.relays[0].header-route-value=userRoute
web.route.relays[0].relay-bean-name=userRoute

Start WebRoute

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

Getting Started WebRoute

@Component
public class UserRoute implements WebRelayTemplate {
	private static final List<String> WEB_SERVER_URL = new ArrayList<>();

	static {
		/**
		 * You Can Use The RPC Tool To Obtain The Cluster URL Address Periodically
		 * For Example, Use HTTP To Request URL Storage Server (HttpServer+Redis)
		 */
		WEB_SERVER_URL.add("127.0.0.1:8080");
		WEB_SERVER_URL.add("127.0.0.1:8081");
		WEB_SERVER_URL.add("127.0.0.1:8082");
	}

	public static String getLocalUrl(int offset) {
		return WEB_SERVER_URL.get(offset);
	}

	@Override
	public WebRelayMessage relay(HttpRequestMessage httpRequestMessage) {
		HttpHeaders headers = httpRequestMessage.getHeaders();
		int offset = Integer.getInteger(headers.get("offset"));
		String url = getLocalUrl(offset);
		headers.add("Hello", "World");

		String uri = httpRequestMessage.getUri();
		var path = "";
		var relayErrorMessage = "relayError";
		try {
			Map<String, String> uriParam = UriUtils.uriConvertMap(uri);
			uriParam.put("hello", "world");
			path = UriUtils.mapConvertUri(uri, uriParam);

		} catch (UnsupportedEncodingException e) {
			log.error("relayError", e);
		}
		return WebRelayMessageBuilder.builderWebRelayMessage(url, path, headers, relayErrorMessage);
	}
}

web-route-spring-boot-starter's People

Contributors

thierrysquirrel avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.