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. Tomcat集群Spring+Quartz多次执行解决方案记录

    由于在集群环境下定时器会出现并发和重复执行的问题,我再三考虑记录有5 一.把定时器模块单独拿出来放到一台tomcat或者新建一个Java工程手动启动定时器,这样定时器的任务就可以从原来的集群中抽离开来 ...

  2. Excel 批量快速合并相同的单元格:数据透视表、宏代码、分类汇总

    Excel 批量快速合并相同的单元格   在制作Excel表格的时候,为了使得自己制作的报表更加简洁明了,方便查阅,经常需要合并很多相同的单元格,如果有几千几万条记录需要合并的话,真的会让人发疯.怎样 ...

  3. memcpy实现

    typedef unsigned int size_t; void * my_memcpy ( void *dest, const void *src, size_t num ) { void* re ...

  4. [转]C++之运算符重载(2)

    上一节主要讲解了C++里运算符重载函数,在看了单目运算符(++)重载的示例后,也许有些朋友会问这样的问题.++自增运算符在C或C++中既可以放在操作数之前,也可以放在操作数之后,但是前置和后置的作用又 ...

  5. [9] 圆环(Ring)图形的生成算法

    顶点数据的生成 bool YfBuildRingVertices ( Yreal radius, Yreal assistRadius, Yreal height, Yuint slices, Yui ...

  6. C#中Serializable序列化

    序列化就是是将对象转换为容易传输的格式的过程,一般情况下转化打流文件,放入内存或者IO文件 中.例如,可以序列化一个对象,然后使用 HTTP 通过 Internet 在客户端和服务器之间传输该对象,或 ...

  7. IE浏览器报Promise未定义的错误、解决vuex requires a Promise polyfill in this browser问题

    一个vue-cli构建的vue项目,一个使用angular的项目,两个项目在其他浏览器一切正常,但是ie中会报Promise未定义的错误 解决办法: 一.vue的项目: 1.npm install b ...

  8. vue当前路由跳转初步研究

    一样闲话少说,直接上问题,如图: 也是消息面板,没想到一个小小的消息面板,碰到这么多坑,惆怅. 就是如果当前路由和跳转路由不一样时,正常跳转没有任何问题.但是如果一样时,就不会跳转了,用了很多方法,比 ...

  9. IOS Xib使用——Xib表示局部界面

    Xib文件是一个轻量级的用来描述局部界面的文件,在之前的文章讲解了为控制器添加Xib文件,本节主要讲解一下通过xib文件表示局部界面. <一> 创建Xib文件 Xib文件创建的时候是选择U ...

  10. [置顶] 自定义的解压进度条 关于ProgressBar的使用

    整体布局 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android ...