Commit 810c9bde by liyuan

添加代码

parent 5e13875d
package com.byit.demo.client.api;
import com.byit.demo.client.api.dto.UserDTO;
/**
* @author liyuan
* create date on 2019-11-14 14:49
* description:
* <p></p>
* modified By
**/
public interface DemoService {
UserDTO hello(String name);
}
package com.byit.demo.client.api.dto;
import lombok.Data;
import java.io.Serializable;
/**
* @author liyuan
* create date on 2019-11-14 14:52
* description:
* <p></p>
* modified By
**/
@Data
public class UserDTO implements Serializable {
private String name;
private String word;
}
package com.byit.demo.client;
import com.byit.rpc.remoting.provider.annotation.RpcService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @author liyuan
* create date on 2019-11-14 15:07
* description:
* <p></p>
* modified By
**/
@SpringBootApplication
@RpcService(http_type = true)
@Slf4j
public class DemoClientApplication {
public static void main(String[] args) {
SpringApplication.run(DemoClientApplication.class, args);
log.info("demo-client启动成功……");
}
}
package com.byit.demo.client.config;
import com.byit.rpc.registry.impl.RegistryServiceRegistry;
import com.byit.rpc.remoting.invoker.impl.RpcSpringInvokerFactory;
import com.byit.rpc.remoting.provider.impl.RpcSpringProviderFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
/**
* @author liyuan
* create date on 2019-11-14 15:09
* description:
* <p></p>
* modified By
**/
@Configuration
@Slf4j
public class DemoRegisterConfig {
@Value("${myth-rpc.registry.address}")
private String address;
@Value("${myth-rpc.registry.biz}")
private String biz;
@Value("${myth-rpc.registry.env}")
private String env;
@Value("${myth-rpc.registry.port}")
private int port;
@Bean
public RpcSpringInvokerFactory invokerFactory(){
RpcSpringInvokerFactory invokerFactory = new RpcSpringInvokerFactory();
invokerFactory.setServiceRegistryClass(RegistryServiceRegistry.class);
invokerFactory.setServiceRegistryParam(new HashMap<String,String>(){{
put(RegistryServiceRegistry.REGISTRY_ADDRESS,address);
put(RegistryServiceRegistry.BIZ, biz);
put(RegistryServiceRegistry.ENV,env);
}});
log.info(">>>>>>>>>> 例子项目 invoker config 初始化成功");
return invokerFactory;
}
@Bean
public RpcSpringProviderFactory rpcSpringProviderFactory() {
RpcSpringProviderFactory providerFactory = new RpcSpringProviderFactory();
providerFactory.setPort(port);
providerFactory.setServiceRegistryClass(RegistryServiceRegistry.class);
providerFactory.setServiceRegistryParam(new HashMap<String, String>() {{
put(RegistryServiceRegistry.REGISTRY_ADDRESS, address);
put(RegistryServiceRegistry.BIZ, biz);
put(RegistryServiceRegistry.ENV, env);
}});
log.info(">>>>>>>>>>>>>>> byit-demo-service 向注册中心注册config初始化完成");
return providerFactory;
}
}
package com.byit.demo.client.controller;
import com.byit.demo.client.api.DemoService;
import com.byit.demo.client.api.dto.UserDTO;
import com.byit.rpc.remoting.invoker.annotation.RpcReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* @author liyuan
* create date on 2019-11-14 15:24
* description:
* <p></p>
* modified By
**/
@Controller
public class IndexController {
@RpcReference
private DemoService demoService;
@RequestMapping("/demo")
@ResponseBody
public UserDTO say(String name){
return demoService.hello(name);
}
}
myth-rpc.registry.address=http://localhost:8080/myth-register
myth-rpc.registry.env=liyuan
myth-rpc.registry.biz=byit-myth-job
myth-rpc.registry.port=9996
logging.config=classpath:logback.xml
\ No newline at end of file
myth-rpc.registry.address=http://localhost:8080/myth-register
myth-rpc.registry.env=pre
myth-rpc.registry.biz=byit-myth-job
myth-rpc.registry.port=9996
logging.config=classpath:logback.xml
\ No newline at end of file
myth-rpc.registry.address=http://localhost:8080/myth-register
myth-rpc.registry.env=test
myth-rpc.registry.biz=byit-myth-job
myth-rpc.registry.port=9996
logging.config=classpath:logback.xml
\ No newline at end of file
server.port=9997
server.context-path=/demo-client
spring.application.name=demo-client
spring.profiles.active=dev
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false" scan="true" scanPeriod="1 seconds">
<contextName>logback</contextName>
<property name="log.path" value="/Users/liyuan/codes/open/rpc/data/applogs/myth-registry/myth-registry-admin.log"/>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log.path}.%d{yyyy-MM-dd}.zip</fileNamePattern>
</rollingPolicy>
<encoder>
<pattern>%date %level [%thread] %logger{36} [%file : %line] %msg%n
</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="console"/>
<appender-ref ref="file"/>
</root>
</configuration>
\ No newline at end of file
package com.byit.demo.client.service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @author liyuan
* create date on 2019-11-14 15:31
* description:
* <p></p>
* modified By
**/
@SpringBootApplication
@Slf4j
public class DemoServiceApplication {
public static void main(String[] args) {
SpringApplication.run(DemoServiceApplication.class, args);
log.info("demo-service启动成功……");
}
}
package com.byit.demo.client.service.config;
import com.byit.rpc.registry.impl.RegistryServiceRegistry;
import com.byit.rpc.remoting.provider.impl.RpcSpringProviderFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
/**
* @author liyuan
* create date on 2019-11-14 15:09
* description:
* <p></p>
* modified By
**/
@Configuration
@Slf4j
public class DemoRegisterConfig {
@Value("${myth-rpc.remoting.port}")
private int port;
@Value("${myth-rpc.registry.address}")
private String address;
@Value("${myth-rpc.registry.env}")
private String env;
@Value("${myth-rpc.registry.biz}")
private String biz;
@Bean
public RpcSpringProviderFactory rpcSpringProviderFactory() {
RpcSpringProviderFactory providerFactory = new RpcSpringProviderFactory();
providerFactory.setPort(port);
providerFactory.setServiceRegistryClass(RegistryServiceRegistry.class);
providerFactory.setServiceRegistryParam(new HashMap<String, String>() {{
put(RegistryServiceRegistry.REGISTRY_ADDRESS, address);
put(RegistryServiceRegistry.BIZ, biz);
put(RegistryServiceRegistry.ENV, env);
}});
log.info(">>>>>>>>>>>>>>> byit-demo-service 向注册中心注册config初始化完成");
return providerFactory;
}
}
package com.byit.demo.client.service.service;
import com.byit.demo.client.api.DemoService;
import com.byit.demo.client.api.dto.UserDTO;
import com.byit.rpc.remoting.provider.annotation.RpcService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.text.MessageFormat;
/**
* @author liyuan
* create date on 2019-11-14 15:35
* description:
* <p></p>
* modified By
**/
@RpcService
@Service
@Slf4j
public class DemoServiceImpl implements DemoService {
@Override
public UserDTO hello(String name) {
String word = MessageFormat.format("Hi {0}, from {1} as {2}",
name, DemoServiceImpl.class.getName(), String.valueOf(System.currentTimeMillis()));
UserDTO userDTO = new UserDTO();
userDTO.setName(name);
userDTO.setWord(word);
log.info(userDTO.toString());
return userDTO;
}
}
server.port=9999
spring.application.name=demo-service
spring.profiles.active=dev
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false" scan="true" scanPeriod="1 seconds">
<contextName>logback</contextName>
<property name="log.path" value="/Users/liyuan/codes/open/rpc/data/applogs/myth-registry/myth-registry-admin.log"/>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log.path}.%d{yyyy-MM-dd}.zip</fileNamePattern>
</rollingPolicy>
<encoder>
<pattern>%date %level [%thread] %logger{36} [%file : %line] %msg%n
</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="console"/>
<appender-ref ref="file"/>
</root>
</configuration>
\ No newline at end of file
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