jiazx0107@163.com
2023-11-09 1f5947ccb5b02817dbe5aaae943c0a7fcfc2cd62
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.fzzy.gateway.hx2023.websocket;
 
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
 
import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
 
 
/**
 * 下发调用粮温检测接口指令 topic
 */
@Slf4j
@Component
@ServerEndpoint(value = "/{productId}/{deviceId}/properties/report")
public class WebSockDeviceMessageReport {
 
    @OnOpen
    public void onOpen(Session session,
                       @PathParam("productId") String productId,
                       @PathParam("deviceId") String deviceId
    ) throws Exception {
 
        log.info("--------下发调用粮温检测接口指令 topic------");
    }
 
    @OnClose
    public void onClose() {
 
        log.info("WebSocket连接关闭={}");
    }
 
    /**
     * 收到前端发送的信息
     *
     * @param message
     * @param session
     */
    @OnMessage
    public void onMessage(String message, Session session) {
 
        log.info("来自前端的信息:\n" + message);
    }
 
    @OnError
    public void onError(Session session, Throwable error) {
        log.error("发生错误");
    }
}