Java发送Websocket消息 - GoEasy PubSub

本节内容为Java实现GoEasy Rest接口发送消息, 使用时,可参阅Rest接口的详细介绍

获取Java SDK

方式一: Maven

添加goeasy添加到您的pom.xml文件:

<dependencies>
    ...
    <dependency>
        <groupId>io.goeasy</groupId>
        <artifactId>goeasy-sdk</artifactId>
        <version>0.3.16</version>
    </dependency>
</dependencies>

方式二: 手动下载sdk

goeasy-sdk-0.3.16.jar

下载依赖包:​ gson-2.3.1.jar, slf4j-api-1.7.2.jar

用Java在服务器端发送消息

        GoEasy goEasy = new GoEasy( "http(s)://<REST Host>”, "my_appkey");
        goEasy.publish("my_channel", "Hello GoEasy",new PublishListener(){
            @Override
            public void onSuccess() {
                System.out.println("Publish success.");
            }

            @Override
            public void onFailed(GoEasyError error) {
                System.out.println("Failed to Publish message, error:" + error.getCode() + " , " + error.getContent());
            }
        });

REST Host

杭州: rest-hangzhou.goeasy.io
新加坡: rest-singapore.goeasy.io

results matching ""

    No results matching ""