GoEasy pushes and receives on the web side

When it comes to real-time push, you will think of two points, one is polling, and the other is HTTP long connection. GoEasy is a free push service based on http long connection encapsulation. We don't need to consider how the background is implemented, and it is very fast to get started. A demo can be done in a few minutes. GoEasy push supports Java,  Android , and JavaScript push. Here I only give an example of push and reception in JavaScript. For the rest, please refer to the goeasy official website https://goeasy.io/www/started.jsp, and the official website has detailed usage Documentation https://goeasy.io/www/docs.jsp.

 

How to use GoEasy to push and receive information:

1. First, I need to register an account on the GoEasy official website. After registration, I can add an application by myself. After the application is added, GoEasy will automatically generate two keys for me, one is the Super key and the other is the Subscribe key.

    GoEasy official website: https://goeasy.io

    Super key: for push or receive

    Subscribe key: only for receiving, not for pushing information

    These two keys are equivalent to the password for using the GoEasy service.

2. Push the message published by the customer with super key in the java background

    2.1. Before starting to write code, we need to download a jar package from the GoEasy official website and import it into the project.

    2.2. It is not convenient to show the source code of our project here, I will use a JUnit method instead:

   public void testPublishMessageInGoEasy(){
      GoEasy goEasy = new GoEasy("your super key");
      goEasy.publish("your_channel","your message");
   }

    Note: You can only use your super key here, "your_channel" -- you can name it whatever you want (preferably a meaningful name), the channel is very important, it determines which pages need to receive your messages.

3. Receive push messages in the jsp page. Since the customer requires that every user needs to be able to receive the message on any page, I put the code of the part that receives the information in main.jsp, and all pages have introduced this jsp page. Here is the code that receives the information in main.jsp:

    3.1. Introducing goeasy.js

           <script type="text/javascript" src="https://cdn.goeasy.io/goeasy.js"></script>

    3.2. Initialize the GoEasy object and subscribe to the channel ( the subscribed channel must be the same as the channel when the message was pushed! )

          var goeasy = new GoEasy({
                              appkey: 'your super key or your subscribe key',

                               });

         goeasy.subscribe({
                            channel: 'your_channel',
          onMessage: function (result) {
          alert("You hava a new message: " + result.content);
             }
   });

The code part is complete, you can open some pages first, and then run the JUnit test method, you can see that all the opened pages receive the messages pushed from the Junit test.

GoEasy provides some callback functions for push, connection and subscription methods to meet our different needs. For more information, please refer to their documentation (has both Chinese and English versions) https://goeasy.io/www/docs. jsp

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326607818&siteId=291194637