Commit a19ef644 by huangfusuper

Netty客户端测试用例

parent 52b5f3fe
package com.byit.task.annotations;
import com.byit.rpc.remoting.invoker.route.LoadBalance;
import java.lang.annotation.*;
/**
* 任务的客户端 标识在属性层 表示为他是能够调用服务的一个属性 又系统进行自动注入
* @author huangfu
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface TaskClient {
/**
* 负载均衡策略
* @return
*/
LoadBalance loadBalance() default LoadBalance.ROUND;
/**
* htpp方式的回调通知地址
* @return
*/
String callbackUrl() default "";
/**
* 超时时间
* @return
*/
long timeout() default 1000;
}
package com.byit.call;
import com.byit.packet.request.PluginRpcRequestPacket;
import com.byit.packet.response.PluginRpcResponsePacket;
/**
* 远程调用task服务类
* @author huangfu
*/
public interface TaskServer {
/**
* 插件通讯接口
* @param rpcRequestPacket 数据
* @return 结果集
*/
PluginRpcResponsePacket call(PluginRpcRequestPacket rpcRequestPacket);
}
<?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>demo-client</artifactId>
<groupId>myth-job</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>byit-plugin-client</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>myth-job</groupId>
<artifactId>myth-plugin-rpc-client</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.byit.controller;
import com.alibaba.fastjson.JSON;
import com.byit.packet.request.PluginRpcRequestPacket;
import com.byit.packet.response.PluginRpcResponsePacket;
import com.byit.param.defaultparam.DefaultResultCallback;
import com.byit.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
@Autowired
private TestService testService;
@RequestMapping("test")
public PluginRpcResponsePacket test(){
PluginRpcRequestPacket pluginRpcRequestPacket = new PluginRpcRequestPacket();
pluginRpcRequestPacket.setJobName("01Test");
pluginRpcRequestPacket.setParam("123");
pluginRpcRequestPacket.setExtension("13213213");
pluginRpcRequestPacket.setResultCallback(new DefaultResultCallback());
return testService.test(pluginRpcRequestPacket);
}
public static void main(String[] args) {
PluginRpcRequestPacket pluginRpcRequestPacket = new PluginRpcRequestPacket();
pluginRpcRequestPacket.setJobName("01Test");
pluginRpcRequestPacket.setParam("123");
pluginRpcRequestPacket.setExtension("13213213");
pluginRpcRequestPacket.setResultCallback(new DefaultResultCallback());
String x = JSON.toJSONString(pluginRpcRequestPacket);
System.out.println(x);
PluginRpcRequestPacket pluginRpcRequestPacket1 = JSON.parseObject(x, PluginRpcRequestPacket.class);
PluginRpcResponsePacket pluginRpcResponsePacket = new PluginRpcResponsePacket();
pluginRpcResponsePacket.setCode("0000000");
pluginRpcRequestPacket.getResultCallback().resultCallback(null, pluginRpcResponsePacket);
}
}
package com.byit.service;
import com.byit.packet.request.PluginRpcRequestPacket;
import com.byit.packet.response.PluginRpcResponsePacket;
/**
* @author Administrator
*/
public interface TestService {
PluginRpcResponsePacket test(PluginRpcRequestPacket pluginRpcRequestPacket);
}
package com.byit.service;
import com.byit.call.TaskServer;
import com.byit.packet.request.PluginRpcRequestPacket;
import com.byit.packet.response.PluginRpcResponsePacket;
import com.byit.task.annotations.TaskClient;
import org.springframework.stereotype.Service;
@Service
public class TestServiceImpl implements TestService {
@TaskClient
TaskServer taskServer;
@Override
public PluginRpcResponsePacket test(PluginRpcRequestPacket pluginRpcRequestPacket) {
return taskServer.call(pluginRpcRequestPacket);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment