-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/com/alipay/sofa/rpc/HessianServiceServerMain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.alipay.sofa.rpc; | ||
|
||
import com.alipay.sofa.rpc.config.ProviderConfig; | ||
import com.alipay.sofa.rpc.config.RegistryConfig; | ||
import com.alipay.sofa.rpc.config.ServerConfig; | ||
import com.alipay.sofa.rpc.context.RpcRuntimeContext; | ||
import com.alipay.sofa.rpc.hessian.HelloService; | ||
import com.alipay.sofa.rpc.hessian.HelloServiceImpl; | ||
import com.alipay.sofa.rpc.log.Logger; | ||
import com.alipay.sofa.rpc.log.LoggerFactory; | ||
import com.alipay.sofa.rpc.protobuf.ProtoService; | ||
import com.alipay.sofa.rpc.protobuf.ProtoServiceImpl; | ||
|
||
public class HessianServiceServerMain { | ||
|
||
/** | ||
* Logger for ProtobufServiceServerMain | ||
**/ | ||
private static final Logger LOGGER = LoggerFactory.getLogger(ProtobufServiceServerMain.class); | ||
|
||
public static void main(String[] args) { | ||
// 指定注册中心 | ||
RegistryConfig registryConfig = new RegistryConfig() | ||
.setProtocol("zookeeper") | ||
.setAddress("127.0.0.1:2181"); | ||
|
||
ServerConfig serverConfig = new ServerConfig() | ||
.setProtocol("bolt") // 设置一个协议,默认bolt | ||
.setSerialization("hessian2") | ||
.setPort(12200) // 设置一个端口,默认12200 | ||
.setDaemon(false); // 非守护线程 | ||
|
||
ProviderConfig<HelloService> providerConfig = new ProviderConfig<HelloService>() | ||
.setInterfaceId(HelloService.class.getName()) // 指定接口 | ||
.setRef(new HelloServiceImpl()) // 指定实现 | ||
.setServer(serverConfig) // 指定服务端 | ||
.setRegistry(registryConfig); | ||
|
||
|
||
providerConfig.export(); // 发布服务 | ||
|
||
LOGGER.error("started at pid {}", RpcRuntimeContext.PID); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.alipay.sofa.rpc.hessian; | ||
|
||
public interface HelloService { | ||
String sayHello(String name); | ||
|
||
User echoUser(User user); | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/alipay/sofa/rpc/hessian/HelloServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.alipay.sofa.rpc.hessian; | ||
|
||
public class HelloServiceImpl implements HelloService { | ||
public String sayHello(String name) { | ||
return "hello " + name; | ||
} | ||
|
||
public User echoUser(User user) { | ||
return user; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.alipay.sofa.rpc.hessian; | ||
|
||
import java.io.Serializable; | ||
import java.util.Date; | ||
|
||
public class User implements Serializable { | ||
private int id; | ||
private String name; | ||
private String address; | ||
private int salary; | ||
private Date birthday; | ||
|
||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getAddress() { | ||
return address; | ||
} | ||
|
||
public int getSalary() { | ||
return salary; | ||
} | ||
|
||
public void setId(int id) { | ||
this.id = id; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public void setAddress(String address) { | ||
this.address = address; | ||
} | ||
|
||
public void setSalary(int salary) { | ||
this.salary = salary; | ||
} | ||
|
||
public Date getBirthday() { | ||
return birthday; | ||
} | ||
|
||
public void setBirthday(Date birthday) { | ||
this.birthday = birthday; | ||
} | ||
} |