Venus Service Framework提供服务器端开发SDK以及客户端SDK。它们之间采用Venus自定义的私有协议。encoder、decoder采用多种序列化方式,客户端根据自己的语言选择一种序列化方式。

目前提供3种序列化方式:0:表示JSON, 1:表示BSON , 3:表示JAVA对象序列化(仅限于java语言)。

Venus为让开发人员只专注服务开发而努力,开发人员在设计接口的时候只需要按照java的接口设计原则进行设计,把接口、接口中使用的参数对象类、接口异常类封装成API包即可对外提供。

而Venus则承担协调沟通客户端服务器端的通讯框架。


接口定义
接口:用来约束客户端、服务端的应用层协议,他申明了具体服务接口的调用方式,参数的数据类型,具体功能的声明、异常的描述等等信息,它有服务端开发工程师,服务使用方工程师共同制定的。
package com.meidusa.venus.hello.api;

import com.meidusa.venus.annotations.Endpoint;
import com.meidusa.venus.annotations.Param;
import com.meidusa.venus.annotations.Service;
import com.meidusa.venus.notify.InvocationListener; /**
* Service framework的 HelloService 接口例子.</p>
* 支持3种调用方式:</p>
* <li> 请求应答模式:普通的request、response,一般用于接口有返回值</li>
* <li> 异步请求模式:通常用于接口无返回值,客户端并不关心服务器的处理结果,也不用关心服务器处理多少时间</li>
* <li> 异步回调模式:接口无返回值,处理通常消化大量时间,需要服务端通知处理结果的业务接口</li>
*
* @author Struct
*
*/
@Service(name="HelloService",version=1)
public interface HelloService { /**
* 无返回结果的服务调用,支持回调方式,该服务在通讯层面上为异步调用
* @param name
* @param invocationListener 客户端的回调接口
*/
@Endpoint(name="sayHelloWithCallbak")
public abstract void sayHello(@Param(name="name") String name,
@Param(name="callback") InvocationListener<Hello> invocationListener);
/**
* 无返回结果的服务调用,支持同步或者异步调用,
* 该接口申明:同步,并且接口申明异常
* @param name
*/
@Endpoint(name="sayHello",async=false)
public abstract void sayHello(@Param(name="name") String name) throws HelloNotFoundException; /**
* 无返回结果的服务调用,支持同步或者异步调用,无异常申明
* @param name
*/
@Endpoint(name="sayAsyncHello",async=true)
public abstract void sayAsyncHello(@Param(name="name") String name); /**
* 有返回结果的服务调用,该接口只能支持同步调用
* @param name
* @return
*/
@Endpoint(name="getHello")
public abstract Hello getHello(@Param(name="name") String name);
}
客户端开发
1、引入venus相关依赖
2、编写Spring的配置文件
3、编写venus客户端配置文件:VenusClient-simple.xml
4、编写Testcase进行junit测试

1、依赖管理

pom.xml

<dependencies>
<dependency>
<groupId>com.meidusa.service</groupId>
<artifactId>venus-client</artifactId>
<version>${venus.version}</version>
</dependency>
</dependencies>
<properties>
<venus.version>3.0.0</venus.version>
</properties>

2、客户端spring配置文件

<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
<bean id="serviceFactory" class="com.meidusa.venus.client.VenusServiceFactory">
<property name="configFiles">
<list>
<value>classpath:VenusClient-simple.xml</value>
<!--
支持file: 绝对路径与classpath:,这儿可以配置多个文件
<value>file:VenusClient-simple.xml</value>
-->
</list>
</property>
</bean>

3、客户端的 venus.xml的配置

<?xml version="1.0" encoding="utf8"?>
<venus-client> <!-- 服务接口列表 -->
<services>
<!-- 定义服务以及指定该服务提供方的远程相关配置 -->
<service type="com.meidusa.venus.hello.api.HelloService">
<property name="ipAddressList">127.0.0.1:16800</property>
</service>
</services>
</venus-client>

4、testCase using Spring autowire

import org.springframework.beans.factory.annotation.Autowired;

package com.meidusa.venus.hello.client;

import java.util.concurrent.CountDownLatch;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.meidusa.venus.exception.CodedException;
import com.meidusa.venus.hello.api.Hello;
import com.meidusa.venus.hello.api.HelloNotFoundException;
import com.meidusa.venus.hello.api.HelloService;
import com.meidusa.venus.notify.InvocationListener; @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:/applicationContext-helloworld-client.xml")
public class TestHelloService { @Autowired
private HelloService helloService; @Test
public void saySync(){
System.out.println(helloService.getHello("jack"));
} @Test
public void testSyncWithException(){
try {
helloService.sayHello("jack");
} catch (HelloNotFoundException e) {
System.out.println("throw an user defined HelloNotFoundException");
}
} @Test
public void testAsync(){
helloService.sayAsyncHello("jack");
} }
服务端开发
1、引入对venus的依赖
2、实现HelloService接口
3、Venus的服务端配置:VenusServices-simple.xml
4、Spring的相关Bean的配置(注意:需要让spring容器默认采用 byName autowire 的功能: default-autowire="byName")

1、引入Venus相关的依赖

pom.xml

<dependencies>
<dependency>
<groupId>com.meidusa.service</groupId>
<artifactId>venus-backend</artifactId>
<version>${venus.version}</version>
</dependency> </dependencies>
<properties>
<venus.version>3.0.0</venus.version>
</properties>

2、实现HelloWorld接口

package com.meidusa.venus.hello.impl;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map; import com.meidusa.venus.hello.api.Hello;
import com.meidusa.venus.hello.api.HelloNotFoundException;
import com.meidusa.venus.hello.api.HelloService;
import com.meidusa.venus.notify.InvocationListener; public class DefaultHelloService implements HelloService {
private String greeting;
public String getGreeting() {
return greeting;
} public void setGreeting(String greeting) {
this.greeting = greeting;
}
public Hello getHello(String name) {
Hello hello = new Hello();
hello.setName(name);
hello.setGreeting(greeting);
Map<String,Object> map = new HashMap<String,Object>();
hello.setMap(map);
map.put("1", 1);
map.put("2", new Long(2));
map.put("3", new Integer(3));
hello.setBigDecimal(new BigDecimal("1.341241233412"));
return hello;
} public void sayHello(String name) throws HelloNotFoundException {
throw new HelloNotFoundException(name +" not found");
} @Override
public void sayAsyncHello(String name) {
System.out.println("method sayAsyncHello invoked");
} public void sayHello(String name,
InvocationListener<Hello> invocationListener) {
Hello hello = new Hello();
hello.setName(name);
hello.setGreeting(greeting);
Map<String,Object> map = new HashMap<String,Object>();
hello.setMap(map);
map.put("1", 1);
map.put("2", new Long(2));
map.put("3", new Integer(3)); if(invocationListener != null){
invocationListener.callback(hello);
} }
}

3、VenusService-simple.xml的配置

<?xml version="1.0" encoding="utf-8"?>
<venus-server>
<services>
<!-- 有2种方式暴露Service,1: instance由venus负责实例化,如下代码: -->
<service type="com.meidusa.venus.hello.api.HelloService">
<instance class="com.meidusa.venus.hello.impl.DefaultHelloService">
<property name="greeting">hello venus hello service</property>
</instance>
</service> <!-- 第二种:instance由Spring负责提供,则需要采用${...} 这种方式引用Spring的bean,这种方式主要是Spring内其他bean依赖该bean,则通常采用这种 -->
<!-- 这儿的 ${helloService} 表示在你的spring xml中需要配置一个 beanName为 helloService,type为DefaultHelloService的一个bean
<service type="com.meidusa.venus.hello.api.HelloService">
<property name="instance">${helloService}</property>
</service> -->
</services>
</venus-server>

4、Spring相关的venus 配置

<!-- 引入venus Service 相关的配置 -->
<import resource="classpath:/spring/applicationContext-service-container.xml"/> <!-- 加载服务配置文件 -->
<bean id="serviceManager" class="com.meidusa.venus.backend.services.xml.XmlFileServiceManager">
<property name="configFiles">
<list>
<value>classpath:VenusServices-simple.xml</value>
</list>
</property>
</bean> <!-- 设置authenticateProvider,默认为可以使用该配置 -->
<!-- venus目前提供2种方式的认证,一种是默认的采用虚拟的方式,另外一种支持用户名/密码登录,你也可以自己实现provider -->
<bean id="authenticateProvider" class="com.meidusa.venus.backend.authenticate.SimpleAuthenticateProvider">
<property name="useDummy" value="true"/>
<property name="username" value="venus"/>
<property name="password" value="venus"/>
</bean>
服务端的启动控制台展示
1、显示了多少个Service暴露出来
2、显示了每个Service有哪些Endpoint暴露出来
3、服务端的监听端口
-- ::, INFO  xml.XmlFileServiceManager - Add Endpoint: HelloService.sayHello
-- ::, INFO xml.XmlFileServiceManager - Add Endpoint: HelloService.sayHelloWithCallbak
-- ::, INFO xml.XmlFileServiceManager - Add Endpoint: HelloService.sayAsyncHello
-- ::, INFO xml.XmlFileServiceManager - Add Endpoint: HelloService.getHello
-- ::, INFO xml.XmlFileServiceManager - Add Endpoint: ParameterizedService.arrayLong
-- ::, INFO xml.XmlFileServiceManager - Add Endpoint: ParameterizedService.arraylong
-- ::, INFO net.ServerableConnectionManager - Server listening on 0.0.0.0/0.0.0.0:.

PropertyPlaceholder:用于替换venus的配置文件中包含 ${}变量的东西

<bean class="com.meidusa.venus.spring.VenusPropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>file:${project.home:.}/application.properties</value> </list>
</property>
</bean>

helloworld源代码地址:

svn 地址:svn://svn.hexnova.com/venus/venus-helloworld/trunk

转载自:http://wiki.hexnova.com/pages/viewpage.action?pageId=2883620

venus之hello world的更多相关文章

  1. venus

    The Venus system was a small timesharing system serving five or six users at a time:分时系统 The design ...

  2. venus java高并发框架

    http://www.iteye.com/topic/1118484 因为有 netty.mima等远程框架.包括spring jboss等remoting框架 和阿里的dubbo相比, 没有亮点.. ...

  3. gradle学习笔记(1)

    1. 安装     (1) 下载最新gradle压缩包,解压到某处.地址是:Gradle web site:     (2) 添加环境变量:             1) 变量名:GRADLE_HOM ...

  4. [C#] 进阶 - LINQ 标准查询操作概述

    LINQ 标准查询操作概述 序 “标准查询运算符”是组成语言集成查询 (LINQ) 模式的方法.大多数这些方法都在序列上运行,其中的序列是一个对象,其类型实现了IEnumerable<T> ...

  5. [转] 从知名外企到创业公司做CTO是一种怎样的体验?

    这是我近期接受51CTO记者李玲玲采访的一篇文章,分享给大家. 作者:李玲玲来源:51cto.com|2016-12-30 15:47 http://cio.51cto.com/art/201612/ ...

  6. HTML基础

    HTML指的是超文本标记语言 (Hyper Text Markup Language), HTML不是一种编程语言,而是一种标记语言 (markup language) ,HTML使用标记标签来描述网 ...

  7. 【Python五篇慢慢弹(3)】函数修行知python

    函数修行知python 作者:白宁超 2016年10月9日21:51:52 摘要:继<快速上手学python>一文之后,笔者又将python官方文档认真学习下.官方给出的pythondoc ...

  8. html+ccs3太阳系行星运转动画之土星有个环,地球有颗小卫星

    在上一篇<html+ccs3太阳系行星运转动画>中实现了太阳系八大行星的基本运转动画. 太阳系又何止这些内容,为丰富一下动画,接下来增加“土星环”和“月球”来充盈太阳系动画. 下面是充盈后 ...

  9. html+ccs3太阳系行星运转动画

    做一个太阳系八大行星的运转动画,不包括行星的卫星,所有行星围绕太阳公转,行星采用纯色,暂时没有自转. 效果静态图: 动画中包括:太阳及各行星,运行轨道,行星公转动画. 先画好草图,设计好大小和位置,根 ...

随机推荐

  1. .NET的堆和栈02,值类型和引用类型参数传递以及内存分配

    在" .NET的堆和栈01,基本概念.值类型内存分配"中,了解了"堆"和"栈"的基本概念,以及值类型的内存分配.我们知道:当执行一个方法的时 ...

  2. Maven实战(四)——基于Maven的持续集成实践

    Martin的<持续集成> 相信非常多读者和我一样.最早接触到持续集成的概念是来自Martin的著名文章<持续集成>.该文最早公布于2000年9月,之后在2006年进行了一次修 ...

  3. plsql调用无参/有参存储过程

    --有参调用方式:declare STERMINAL ); SPROCESS NUMBER; begin sj_transfera_digi_getmapping(,,'DYH010006783031 ...

  4. 10 Big Data Possibilities for 2017 Based on Oracle's Predictions

    2017 will see a host of informed predictions, lower costs, and even business-centric gains, courtesy ...

  5. VUE router-view 页面布局 (嵌套路由+命名视图)

    嵌套路由 实际生活中的应用界面,通常由多层嵌套的组件组合而成.同样地,URL 中各段动态路径也按某种结构对应嵌套的各层组件,例如: /user/foo/profile /user/foo/posts ...

  6. API手册 常用功能

    directive [ng] a form input input [checkbox] input [email] input [number] input [radio] input [text] ...

  7. xUtils框架的使用详解

    一.xUtils简介 xUtils 最初源于Afinal框架,进行了大量重构,使得xUtils支持大文件上传,更全面的http请求协议支持(10种谓词),拥有更加灵活的ORM,更多的事件注解支持且不受 ...

  8. Android -- ImageLoader本地缓存

    传送门 <Android -- ImageLoader简析>  http://www.cnblogs.com/yydcdut/p/4008097.html 本地缓存 在缓存文件时对文件名称 ...

  9. 微信小程序中用户唯一ID的获取

    折腾到半夜,搞得挺兴奋,总结一下,免得忘了: 1.微信小程序直接获得的是一些简单信息,基本无用 2.用户唯一标识是openid,还有一个unionid是关联多个公众号之类情况下用,我不大关心 3.在g ...

  10. java代码在开始事务后,先做了一个查询,再insert,此时会报: java.sql.SQLException: could not retrieve transation read-only status server

    解决过程: 查看mysql的事物隔离级别 SHOW VARIABLES LIKE '%iso%'; 返回结果: REPEATABLE-READ 把这个改成:READ-COMMITTED 就好了: SE ...