All Projects → zhoumengkang → Yar Java Client

zhoumengkang / Yar Java Client

Java client for laruence’s yar, concurrent async request supported.

Programming Languages

java
68154 projects - #9 most used programming language

Labels

Projects that are alternatives of or similar to Yar Java Client

Nettyrpc
NettyRPC is high performance java rpc server base on Netty,using kryo,hessian,protostuff support message serialization.
Stars: ✭ 1,131 (+1262.65%)
Mutual labels:  rpc
Thriftpy
Thriftpy has been deprecated, please migrate to https://github.com/Thriftpy/thriftpy2
Stars: ✭ 1,156 (+1292.77%)
Mutual labels:  rpc
Rsf
已作为 Hasor 的子项目,迁移到:http://git.oschina.net/zycgit/hasor
Stars: ✭ 77 (-7.23%)
Mutual labels:  rpc
Haskell Capnp
Cap'n Proto for Haskell
Stars: ✭ 65 (-21.69%)
Mutual labels:  rpc
Isomorphine
Require server-side modules from the browser, remotely.
Stars: ✭ 66 (-20.48%)
Mutual labels:  rpc
Rpcx Java
rpcx implementation in Java for server side and client side
Stars: ✭ 71 (-14.46%)
Mutual labels:  rpc
Kubemq
KubeMQ is Enterprise-grade message broker native for Docker and Kubernetes
Stars: ✭ 58 (-30.12%)
Mutual labels:  rpc
Client
An alternative Polkadot Runtime Environment implementation acting as a full-node (excluding block production for validators) for syncing with Substrate-based chains.
Stars: ✭ 82 (-1.2%)
Mutual labels:  rpc
Socket.io Rpc
Extend your promises across a network with socket.io
Stars: ✭ 67 (-19.28%)
Mutual labels:  rpc
Discordrpcvs
An extension for Visual Studio 2017 that enables Discord Rich Presence.
Stars: ✭ 77 (-7.23%)
Mutual labels:  rpc
Core Geth
A highly configurable Go implementation of the Ethereum protocol.
Stars: ✭ 66 (-20.48%)
Mutual labels:  rpc
Hprose Golang
Hprose is a cross-language RPC. This project is Hprose for Golang.
Stars: ✭ 1,143 (+1277.11%)
Mutual labels:  rpc
Nethereum
Ethereum .Net cross platform integration library
Stars: ✭ 1,191 (+1334.94%)
Mutual labels:  rpc
Blitz3d msvc2017
Blitz3D Source for MSVC Community Edition 2017
Stars: ✭ 64 (-22.89%)
Mutual labels:  rpc
Easyrpc
EasyRpc is a simple, high-performance, easy-to-use RPC framework based on Netty, ZooKeeper and ProtoStuff.
Stars: ✭ 79 (-4.82%)
Mutual labels:  rpc
Nettythrift
Thrift on Netty, support TCP/HTTP/WebSocket at same port. support multiple Protocols at same time. multil Simple Clients with Connection Pool.
Stars: ✭ 60 (-27.71%)
Mutual labels:  rpc
Swoft Framework
[READ ONLY] Swoft Framework, base of Swoft
Stars: ✭ 70 (-15.66%)
Mutual labels:  rpc
Butterfly
🔥 蝴蝶--【简单】【稳定】【好用】的 Python web 框架🦋 除 Python 2.7,无其他依赖; 🦋 butterfly 是一个 RPC 风格 web 框架,同时也是微服务框架,自带消息队列通信机制实现分布式
Stars: ✭ 82 (-1.2%)
Mutual labels:  rpc
Fox
fox is a distributed RPC framework
Stars: ✭ 79 (-4.82%)
Mutual labels:  rpc
Netty Stroll
RPC基础通信框架
Stars: ✭ 77 (-7.23%)
Mutual labels:  rpc

简介

Build Status

Yar 是一个轻量级, 高效的 RPC 框架, 它提供了一种简单方法来让 PHP 项目之间可以互相远程调用对方的本地方法. 并且 Yar 也提供了并行调用的能力. 可以支持同时调用多个远程服务的方法.

Yar 鸟哥博客介绍 http://www.laruence.com/2012/09/15/2779.html

Yar 鸟哥原始项目 https://github.com/laruence/yar

Yar Java Client 则实现了跨语言的远程调用。使得 Java 客户端能够调用 Yar PHP 服务器端本地的方法。

特性

  1. 执行速度快,依旧保持鸟哥初衷,框架轻,使用简单

  2. 支持并行的 RPC 调用

  3. 方法的使用和参数的和 PHP 版本保持一致

范例

更详细的使用说明请参考 wiki

PHP服务器端

提供了两个 rpc api ,模拟的业务场景是点赞赠送金币和发布帖子赠送金币。

<?php
 
class RewardScoreService {
    /**
     * $uid 给 $fid 点赞
     * @param $fid  interge
     * @param $uid  interge
     * @return void
     */
    public function support($uid,$fid){
        return "support:uid:$uid:fid:$fid";
    }
 
    /**
     * $uid 发布了帖子 $fid 
     * @param $fid  interge
     * @param $uid  interge
     * @return void
     */
    public function post($uid,$fid){
        return "post:uid:$uid:fid:$fid";
    }
}
 
$yar_server = new Yar_server(new RewardScoreService());
$yar_server->handle();

Java客户端同步调用这两个服务

public class YarClientTest extends TestCase {
    /**
     * 定义 rpc 接口
     */
    public interface RewardScoreService{
        String support(int uid,int fid);
        String post(int uid,int fid);
    }

    /**
     * rpc api 地址
     */
    static String uri = "http://mengkang.net/demo/yar-server/RewardScoreService.php";

    public void testUserService(){
        // 第一种调用方式
        YarClient yarClient  = new YarClient(uri);
        RewardScoreService rewardScoreService = (RewardScoreService) yarClient.useService(RewardScoreService.class);
        System.out.println(rewardScoreService.support(1, 2));
        
        // 第二种调用方式
        YarClientOptions yarClientOptions = new YarClientOptions();
        yarClientOptions.setConnect_timeout(2000);
        
        YarClient yarClient2  = new YarClient(uri,yarClientOptions);
        RewardScoreService rewardScoreService2 = (RewardScoreService) yarClient2.useService(RewardScoreService.class);
        System.out.println(rewardScoreService2.post(1, 20));
    }

}

Java客户端并行调用这两个服务

并发调用的 api 均按照 php c 扩展版本的 yar 协议为准 原版 api http://php.net/manual/zh/class.yar-concurrent-client.php

YarConcurrentClient.call方法注册,

YarConcurrentClient.loop并行调用,

YarConcurrentClient.reset清空任务。

回调函数需要继承实现YarConcurrentCallback里面定义了两个方法:async是针对并行调用发出之后立即执行的任务,而success则是每个请求之后返回的结果。

public class YarConcurrentClientTest extends TestCase {

    /**
     * rpc api 地址
     */
    static String uri = "http://mengkang.net/demo/yar-server/RewardScoreService.php";

    public class callback extends YarConcurrentCallback {

        public void async() {
            System.out.println("现在, 所有的请求都发出去了, 还没有任何请求返回");
        }

        public Object success() {
            return retValue;
        }

    }

    public class errorCallback extends YarConcurrentErrorCallback {
        @Override
        void error() {
            System.out.println("出错了");
        }
    }

    public void testLoop() throws Exception {

        String packagerName = YarConfig.getString("yar.packager");
        YarClientOptions yarClientOptions = new YarClientOptions();
        yarClientOptions.setConnect_timeout(2000);

        // 第一种调用方式
        YarConcurrentClient.call(new YarConcurrentTask(uri, "support", new Object[]{1, 2}, packagerName, new callback()));
        
        // 第二种调用方式 增加一些额外配置选项
        YarConcurrentClient.call(new YarConcurrentTask(uri, "support", new Object[]{1, 2}, packagerName, new callback(),yarClientOptions));

        // 第三种调用方式 有正确的回调和错误的回调
        YarConcurrentClient.call(new YarConcurrentTask(uri,"post",new Object[]{1,2},packagerName,new callback(),new errorCallback()));
        
        // 第四种调用方式 在第三种的基础上增加额外的配置选项
        YarConcurrentClient.call(new YarConcurrentTask(uri,"post",new Object[]{1,2},packagerName,new callback(),new errorCallback(),yarClientOptions));

        YarConcurrentClient.loop(new callback());
        YarConcurrentClient.reset();
    }
}

其他

更多详细的说明,请查看 wiki

有任何使用的问题和技术交流,欢迎使用 issues

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].