Real-time web push using GoEasy

 JAVA Web real-time message background server push technology

 

Without further ado, let’s go straight to the topic, how to achieve:

1. Get appkey from GoEasy

The appkey is a unique identifier that verifies the validity of the user.

  • Register an account. GoEasy official website: http://goeasy.io
  • Log in to GoEasy's background management system with the registered account and create your own application.
  • After the Application is created, the system will automatically generate an appkey for you

The system will generate two keys, a Super key and a Subscribe key; the difference between them is that the former can be subscribed and pushed, but the latter can only be used for subscription.

2. GoEasy implements the principle of pushing to specific user groups

Knowing their push principles makes it easier for us to understand their services and the code we write. In fact, the principle is very simple, you only need to determine which users need to receive information, and then let these users subscribe to the same channel (channel). Then you can push messages on this platform! The key to all lies in the channel. If the channel is consistent, the information can be received, otherwise it cannot be received!

The necessary information for subscription is: Appkey, channel

The necessary information for push is: Appkey, channel, content

3. An example of implementing subscription (receiving) with GoEasy

copy code
 1  <script type="text/javascript" src="https://cdn.goeasy.io/goeasy.js"></script>
 2 
 3                     <script type="text/javascript">
 4             var goEasy = new GoEasy({appkey: 'your appkey'});
 5                                goEasy.subscribe({
 6                         channel: 'your_channel',
 7                         onMessage: function(message){
 8                             alert('接收到消息:'+message.content);              });
10                        }
9After getting the information, you can do whatever you want//
  11   </script>     
copy code

   With these lines of code, as long as the network is unblocked, the page will automatically pop up the information you push from any platform.

4. Examples of Push and Receive with GoEasy

GoEasy currently supports three push methods: Java background push (they provide JAVA SDK and maven remote repository), JS push, RestAPI push (with RestAPI, we can use PHP, .NET, Ruby... to push information, very Convenience)

 

Having said so much, let's take a look at how to use GoEasy's three ways to achieve push.

4.1. Push with GoEasy SDK

1. How to obtain the Java SDK, the first method is to download it directly from the official website of goeasy; the second method is to use the maven remote library to directly import it into the project. Although the official website has already made the same instructions, I still post the key points here for your convenience.

GoEasy SDK download link: http://maven.goeasy.io/service/local/artifact/maven/redirect?r=releases&g=io.goeasy&a=goeasy-sdk&v=0.3.3&e=jar

   Configuration of GoEasy remote maven library:

copy code
 1           <repository>
 2               <id>goeasy</id>
 3               <name>goeasy</name>
 4               <url>http://maven.goeasy.io/content/repositories/releases/</url>
 5          </repository>
 6  7           <dependency>
 8                <groupId>io.goeasy</groupId>
 9                <artifactId>goeasy-sdk</artifactId>
10                <version>0.3.3</version>
11          </dependency>
copy code

 

      需要注意的是:GoEasy需要依赖两个额外的jar 包:
      gson.jar : http://repo.maven.apache.org/maven2/com/google/code/gson/gson/2.3.1/gson-2.3.1.jar
      slf4j-api.jar : http://repo.maven.apache.org/maven2/org/slf4j/slf4j-api/1.7.2/slf4j-api-1.7.2.jar
 2. 实例化GoEasy对象
1 GoEasy goEasy = new GoEasy("your appkey");

 

c. 推送消息
1 goEasy.publish('your_channel', 'First message');

 

4.2. JS推送

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

 

b.       实例化Goeasy对象,并用publish函数进行推送
copy code
1 <script type="text/javascript">
2        var goEasy = new GoEasy({appkey: 'your appkey'});
3                goEasy. publish ({
4                     channel: 'your_channel', 
5                     message: 'Second message!'
6        });
7  </script>
copy code

 

4.3. 用RestAPI进行推送
URL: https://goeasy.io/goeasy/publish
Method: Post
参数:appkey, channel, content
For example: https://goeasy.io/goeasy/publish?appkey={your_appkey}&channel={your_channel}&content={your_message }
 
GoEasy official website: http://goeasy.io
Quick Start: http://goeasy.io/www/started
Document download: http://goeasy.io/www/documents


http://www.cnblogs.com/jishaochengduo/articles/5552645.html

Guess you like

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