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.   Before the time with Goeasy to achieve real-time push function, here to write a work note for easy viewing later, but also hope to help other people need to push the real-time friends. Goeasy is a third-party push service. If you use the original ecological socket.io, websocket for development, need to spend 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 conduct stress testing, performance testing, functional test   test, In general, the development cost of their own 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   speed, code easy to understand the quick, so finally I recommend Goeasy to my leader. 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 requires pre-subscription. Subscribe to what? Subscribe to channel. To push messages to   on a channel, the client subscribes to the same channel, which ensures accurate reception. By channel we can specify which pages or which users can   receive messages that are pushed out of the channel.    Development language: Java  appkey is a "key" pushed with Goeasy. After registering on the Goeasy website create a free application,  you can see a application with two keys. One is supper key,  The other is 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.   1)   introduced goeasy.js <script type= "Text/javascript"  src= "https://cdn.goeasy.io/ Goeasy.js "></script> 2)   Connect 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 () {       &nbsP;             console.log ("Disconnect  To goeasy server. ");                  } ,                   Onconnectfailed:function (Error) {                      console.log ("connect to goeasy failed,  error code:  "+ error.code+"  Error message:  "+ error.content";                  }              });        &NBSP;&NBSP;}&NBSP;&LT;/SCRIPT&GT;&NBSP;3)   Subscribe channel function subscribe () {   goEAsy.subscribe ({             channel:  ' Demo_channel ',             onmessage:  function (message) {                  //when a message is pushed to 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. ");              },    &nbsP;        onfailed: function (Error) {                  console.log ("Subscribe the  Channel failed, error code:  "+ error.code + "  error message :  "+ error.content);              }          });  }  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 add to your project. &NBSP;GSON.JAR&NBSP;SLF4J-API.JAR&NBSP;2)   Push messages 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 Java sdk. :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 first to see the effect of the demo page. Well, I hope this article is helpful to everyone. Share......


This article is from the "12261154" blog, please be sure to keep this source http://12271154.blog.51cto.com/12261154/1897880

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.