Implementing Java real-time push with Goeasy push

Source: Internet
Author: User

Some time ago the customer has a demand he wants him to post a message on the admin page, all users of this system can receive the information he posted in a timely manner, regardless of the page, I used Ajax timing to go to the server pull information, if there is a display , but this way very consumes the resources of the client, I later on the internet to find a third party free push service-goeasy push, it can meet my needs, below is how to use goeasy information push and receive:

1. First I need to register an account on the Goeasy official website, after the registration is complete, I can add application,application add the completion, Goeasy will automatically help me to generate two keys, one is super key, the other is subscribe Key

Goeasy Official website: Https://goeasy.io

Super key: For push or receive

Subscribe key: For receiving only, cannot be used to push information

These two keys are equivalent to passwords that use the Goeasy service.

2. Push customer-published messages with Super key in Java background

2.1. Before we start writing code, we need to download a jar package from the Goeasy website and introduce it into the project.

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

public void Testpublishmessageingoeasy () {
   New Goeasy ("Your Super Key");
Goeasy.publish ("Your_channel","your message");
}

Note: This can only be done with your super key, "Your_channel"-You can name it (preferably a meaningful name), the channel is very important, it determines which pages need to receive the message you sent.

3. In the JSP page to receive the push message, because the customer requires each user to be able to receive the message on any page, I put the part of the code to receive the information in the main.jsp, all the pages are introduced to this JSP page. Here is the code that receives the message in main.jsp:

3.1. Introduction of 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 consistent with the channel of the push message!) )

          var. Span style= "color: #660e7a; Font-style:italic; " >goeasy = new goeasy ({
                                appkey: "your super key or your subscribe key ',

                                })

          Goeasy. subscribe ({
                             channel: ' Your_channel ',
onmessage: function (Result) {
alert ( "you hava a new Messa GE: "+ result. content);
}
})

The Code section is complete, you can open some pages first, and then run the JUnit test method to see that all open pages receive messages pushed out of junit test.

Goeasy to push, connect, subscribe methods provide some callback functions to meet our different needs, more please refer to their documents (in English and Chinese) https://goeasy.io/www/docs.jsp

I hope this article is helpful to other friends who need to push!

Implementing Java real-time push with Goeasy push

Related Article

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.