Goeasy push Real-time messages to the web side

Source: Internet
Author: User

The previous time with goeasy implementation of real-time push function, here to write a work note for later viewing, but also hope to help other people need to push in real-time friends.
Goeasy is a third-party push service. If you use the original ecological Socket.io, websocket development, need to take the time to study how to achieve, and do not say that the two techniques to use the good, the test alone is enough for me, you have to carry out stress testing, performance testing, functional testing, the overall development of the cost of a long cycle, High maintenance costs, so I chose a third-party push service. After I compared a few to do push the third-party products, personal feeling goeasy push more stable, push fast, code simple and easy to understand get started quickly, so finally I recommend Goeasy to my leader.Goeasy official website: Goeasy.io

The principle of push: the principle of goeasy is very simple, is that one end of the push message is only responsible for push, and the need to receive the page needs to be pre-subscribed. Subscribe to what? Subscribe to channel. When a message is pushed to a channel, the client subscribes to the same channel so that it can be received accurately. By channel we can specify which pages or which users can receive messages that are pushed out of the channel.

If you implement Web real-time push
Development language: Java

1. Get Goeasy's Appkey
Appkey is a "key" pushed with Goeasy. After registering on the Goeasy website, create a free application, and then you can see a application with two keys. One is the supper key and the other is the subscribe key. The difference between this two key is that supper key can be used for both push and subscribe, but subscribe key can only be used for subscriptions, and it does not have permission to push information. For security reasons, I use supper key to push messages and subscribe to messages with Subscribe key.

2. Web Client Subscription channel
1) Introduction of Goeasy.js
<script type= "Text/javascript" src= "Https://cdn.goeasy.io/goeasy.js" ></script>

2) Connection Goeasy
<script type= "Text/javascript" >
if (typeof goeasy!== ' undefined ') {
var goeasy = new Goeasy ({
Appkey: ' Appkey ',
Onconnected:function () {
Console.log ("Connect to Goeasy success.");
} ,
Ondisconnected:function () {
Console.log ("Disconnect to Goeasy server.");
} ,
Onconnectfailed:function (Error) {
Console.log ("Connect to Goeasy failed, error code:" + error.code+ "error message:" + error.content);
}
});
}
</script>

3) Subscribe to Channel
function Subscribe () {
Goeasy.subscribe ({
Channel: ' Demo_channel ',
Onmessage:function (message) {
When a message is pushed to the channel "Demo_channel", the console automatically prints out the push message
Console.log (' Meessage received: ' +message.content);
},
Onsuccess:function () {
Console.log ("Subscribe the Channel successfully.");
},
Onfailed:function (Error) {
Console.log ("Subscribe the Channel failed, error code:" + error.code + "error message:" + error.content);
}

});

}


3. Push messages to channel with Java SDK

1) Add Goeasy maven repository to Pom.xml
<repositories>
...
<repository>
<id>goeasy</id>
<name>goeasy</name>
<url>http://maven.goeasy.io/content/repositories/releases/</url>
</repository>
</repositories>


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

It is important to note that you need to rely on two jar packages when using Java SDK, please join in your project.
Gson.jar
Slf4j-api.jar

2) push message to channel
Goeasy goeasy = new Goeasy ("Your supper key");
Goeasy.publish ("Demo_channel", "Welcome xueting", New Publishlistener () {
@Override
public void onfailed (Goeasyerror error) {
System.out.println ("Error code:" + error.getcode () + "; Error content: "+error.getcontent ()");
}

@Override
public void onsuccess () {
System.out.println ("Publish success");
}
});


For friends who are not using MAVEN, you can manually download the SDK for Java. :http://maven.goeasy.io/service/local/artifact/maven/redirect?r=releases&g=io.goeasy&a=goeasy-sdk& V=latest&e=jar

If you are using a different development language, Goeasy also provides RESTFULAPI in the background to push messages. For specific use, please refer to the Goeasy official website for the use of parameters and instructions.

All push messages and receive conditions can be logged into the goeasy background for viewing. Considering the security of the information, you can decide whether or not to encrypt the information before pushing it according to your own needs.

Interested friends can first go to Https://goeasy.io to see the results of the demo page. Well, I hope this article is helpful to everyone. Share......

This article is from the "11888087" blog, please be sure to keep this source http://11898087.blog.51cto.com/11888087/1829676

Goeasy push Real-time messages to the web side

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.