init
This commit is contained in:
20
sentinel/sentinel-demo/sentinel-demo-command-handler/pom.xml
Normal file
20
sentinel/sentinel-demo/sentinel-demo-command-handler/pom.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
<parent>
|
||||
<artifactId>sentinel-demo</artifactId>
|
||||
<groupId>com.alibaba.csp</groupId>
|
||||
<version>1.8.3</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>sentinel-demo-command-handler</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.csp</groupId>
|
||||
<artifactId>sentinel-transport-simple-http</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.csp.sentinel.demo.commandhandler;
|
||||
|
||||
import com.alibaba.csp.sentinel.init.InitExecutor;
|
||||
|
||||
/**
|
||||
* <p>To run this demo, we need to add the {@code sentinel-transport-simple-http} dependency.</p>
|
||||
* <p>
|
||||
* As soon as the CommandCenter has been initialized, we can visit {@code http://ip:commandPort/api}
|
||||
* to see all available command APIs (by default the port is 8719).
|
||||
* We can also visit our customized {@code /echo} command.
|
||||
* </p>
|
||||
*
|
||||
* @author Eric Zhao
|
||||
*/
|
||||
public class CommandDemo {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Only for demo. You don't have to do this in your application.
|
||||
InitExecutor.doInit();
|
||||
|
||||
System.out.println("Sentinel CommandCenter has been initialized");
|
||||
}
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.csp.sentinel.demo.commandhandler;
|
||||
|
||||
import com.alibaba.csp.sentinel.command.CommandHandler;
|
||||
import com.alibaba.csp.sentinel.command.CommandRequest;
|
||||
import com.alibaba.csp.sentinel.command.CommandResponse;
|
||||
import com.alibaba.csp.sentinel.command.annotation.CommandMapping;
|
||||
|
||||
/**
|
||||
* This class is a demo shows how to create and register a customized CommandHandler.
|
||||
*
|
||||
* <ul>
|
||||
* <li>1. Create a class which implements the {@link CommandHandler} SPI interface</li>
|
||||
* <li>2. Use a {@link CommandMapping} to specify the url and desc of your CommandHandler</li>
|
||||
* <li>3. Implement your own {@code handle} method </li>
|
||||
* <li>4. Add your CommandHandler in {@code com.alibaba.csp.sentinel.command.CommandHandler} file which is stored in
|
||||
* {@code resources/META-INF/services/} directory </li>
|
||||
* </ul>
|
||||
*
|
||||
* @author houyi
|
||||
*/
|
||||
@CommandMapping(name = "echo", desc = "echo command for demo")
|
||||
public class EchoCommandHandler implements CommandHandler<String> {
|
||||
|
||||
@Override
|
||||
public CommandResponse<String> handle(CommandRequest request) {
|
||||
String name = request.getParam("name");
|
||||
if (name == null || name.trim().length() == 0) {
|
||||
return CommandResponse.ofSuccess("Tell us what's your name by submit a name parameter");
|
||||
}
|
||||
return CommandResponse.ofSuccess("Hello: " + name);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1 @@
|
||||
com.alibaba.csp.sentinel.demo.commandhandler.EchoCommandHandler
|
Reference in New Issue
Block a user