Code Monkey home page Code Monkey logo

jiguang-java-client-common's Introduction

JiGuang Common for Java

Common lib for JiGuang Java clients.

概述

这是极光 Java client 的公共封装开发包,为 jpush, jmessage, jsms 等 client 提供公共依赖。

版本更新:Release页面。下载更新请到这里。

新增 http2 分支,使用 Netty 第三方工具支持使用 Http/2 发送请求,详情参考 http2 分支下的 ReadMe

新增 ApacheHttpClient,效率更高

新增 NettyHttpClient(多线程还是不推荐,因为使用了同步锁,可能会有各种意外。异步请求方式比较推荐),用法如下:

  • 同步方式(以 PushClient 为例),发送完请求后,请务必调用 close 方法,否则不会自动结束进程。
//在 PushClient 中将 NativeHttpClient 改为 NettyHttpClient, 发送请求方式和之前一样。
this._httpClient = new NettyHttpClient(authCode, proxy, conf);
...


  • 异步方式,异步方式在调用结束后自动关闭。
public void testSendPushWithCallback() {
        ClientConfig clientConfig = ClientConfig.getInstance();
        String host = (String) clientConfig.get(ClientConfig.PUSH_HOST_NAME);
        NettyHttpClient client = new NettyHttpClient(ServiceHelper.getBasicAuthorization(APP_KEY, MASTER_SECRET),
                null, clientConfig);
        try {
            URI uri = new URI(host + clientConfig.get(ClientConfig.PUSH_PATH));
            PushPayload payload = buildPushObject_all_alias_alert();
            client.sendRequest(HttpMethod.POST, payload.toString(), uri, new NettyHttpClient.BaseCallback() {
                @Override
                public void onSucceed(ResponseWrapper responseWrapper) {
                    LOG.info("Got result: " + responseWrapper.responseContent);
                }
            });
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
    }

非常欢迎各位开发者提交代码,贡献一份力量,Review 过有效的代码将会合入本项目。

安装

maven 方式

将下边的依赖条件放到你项目的 maven pom.xml 文件里。

其中 slf4j 可以与 logback, log4j, commons-logging 等日志框架一起工作,可根据你的需要配置使用。

<dependency>
    <groupId>cn.jpush.api</groupId>
    <artifactId>jiguang-common</artifactId>
    <version>1.1.2</version>
</dependency>
<dependency>
	<groupId>com.google.code.gson</groupId>
	<artifactId>gson</artifactId>
	<version>2.2.4</version>
</dependency>
<dependency>
	<groupId>org.slf4j</groupId>
	<artifactId>slf4j-api</artifactId>
	<version>1.7.5</version>
</dependency>
<!-- For log4j -->
<dependency>
	<groupId>org.slf4j</groupId>
	<artifactId>slf4j-log4j12</artifactId>
	<version>1.7.5</version>
</dependency>
<dependency>
	<groupId>log4j</groupId>
	<artifactId>log4j</artifactId>
	<version>1.2.16</version>
</dependency>

jar 包方式

  • jiguang-common的jar包下载。请点击
  • slf4j / log4j (Logger)
  • gson (Google JSON Utils)

项目 libs/ 目录下可以找到 slf4j 及 gson jar 包复制到你的项目里去。

编译源码

如果开发者想基于本项目做一些扩展的开发,或者想了解本项目源码,可以参考此章,否则可略过此章。

jiguang-java-client-common's People

Contributors

kenchoi1992 avatar joshlipan avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.