<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ## API數據源 [TOC] ### 1.新增數據集 * 點擊`“數據集管理”`或者`“數據”`中數據集后的![](https://img.kancloud.cn/3c/e3/3ce36fa23f10fe6f2aca31e537b67009_45x31.png) 均可打開數據集管理界面 ![](https://img.kancloud.cn/d3/bc/d3bce4a4709c7b336cd215de51d4025b_1410x890.png) ![](https://img.kancloud.cn/07/41/0741652cf531572eea618b5af44f82d5_1333x786.png) * 點擊`“新增分組”`可添加分組信息;點擊`“新增數據集”`可添加數據集信息 ![](https://img.kancloud.cn/ef/3c/ef3cbb5170342b2f13bf5e04f5eeb91a_1332x851.png) ### 2.新增分組 輸入分組名稱,添加即可 ![](https://img.kancloud.cn/48/c3/48c3da64ba7dff3434a5d639976e2016_524x195.png) ### 3.新增數據源 數據集名稱:可隨意輸入 分組:選擇分組信息 數據類型:選擇`“Websocket”` 數據源:選擇數據源 [數據源維護](多數據源配置.md) ![](https://img.kancloud.cn/41/53/415395ff1285680945bbbba5810790cb_1522x886.png) ### **4配置接口地址** 在接口地址一欄填寫我們制作的接口地址,并點擊刷新應用接口,如下圖 接口地址示例:ws://localhost:8080/jeecg-boot/websocket/drag https使用wss ### **5編寫WebSocket服務端** 示例代碼如下: 示例中使用了([redis訂閱發布](https://blog.csdn.net/qq_39507276/article/details/89045275))機制解決消息集群問題 ``` package org.jeecg.modules.drag.config.websocket; import java.util.HashMap; import java.util.Map; import java.util.concurrent.CopyOnWriteArraySet; import javax.annotation.Resource; import javax.websocket.OnClose; import javax.websocket.OnMessage; import javax.websocket.OnOpen; import javax.websocket.Session; import javax.websocket.server.PathParam; import javax.websocket.server.ServerEndpoint; import org.jeecg.common.base.BaseMap; import org.jeecg.common.constant.WebsocketConst; import org.jeecg.common.modules.redis.client.JeecgRedisClient; import org.springframework.stereotype.Component; import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; /** * 拖拽websocket服務端 * * @author zyf */ @Component @Slf4j @ServerEndpoint("/websocket/drag/{chartId}") public class DragWebSocket { /** * 鏈接會話 */ private Session session; /** * 圖表ID */ private String chartId; /** * redis隊列名稱 */ private static final String REDIS_TOPIC_NAME = "dragSocketHandler"; @Resource private JeecgRedisClient jeecgRedisClient; /** * 緩存 webSocket連接到單機服務class中(整體方案支持集群) */ private static CopyOnWriteArraySet<DragWebSocket> webSockets = new CopyOnWriteArraySet<>(); private static Map<String, Session> sessionPool = new HashMap<String, Session>(); @OnOpen public void onOpen(Session session, @PathParam(value = "chartId") String chartId) { try { this.session = session; this.chartId = chartId; webSockets.add(this); sessionPool.put(chartId, session); log.info("【websocket消息】有新的連接,總數為:" + webSockets.size()); } catch (Exception e) { } } @OnClose public void onClose() { try { webSockets.remove(this); sessionPool.remove(this.chartId); log.info("【websocket消息】連接斷開,總數為:" + webSockets.size()); } catch (Exception e) { } } /** * 服務端推送消息 * * @param chartId * @param message */ public void pushMessage(String chartId, String message) { Session session = sessionPool.get(chartId); if (session != null && session.isOpen()) { try { log.info("【websocket消息】 單點消息:" + message); session.getAsyncRemote().sendText(message); } catch (Exception e) { e.printStackTrace(); } } } /** * 服務器端推送消息 */ public void pushMessage(String message) { try { webSockets.forEach(ws -> ws.session.getAsyncRemote().sendText(message)); } catch (Exception e) { e.printStackTrace(); } } @OnMessage public void onMessage(String message) { //todo 現在有個定時任務刷,應該去掉 log.debug("【websocket消息】收到客戶端消息:" + message); JSONObject obj = new JSONObject(); //業務類型 obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_CHECK); //消息內容 obj.put(WebsocketConst.MSG_TXT, "心跳響應"); for (DragWebSocket webSocket : webSockets) { webSocket.pushMessage(message); } } /** * 后臺發送消息到redis * * @param message */ public void sendMessage(String message) { log.info("【websocket消息】廣播消息:" + message); BaseMap baseMap = new BaseMap(); baseMap.put("chartId", ""); baseMap.put("message", message); jeecgRedisClient.sendMessage(REDIS_TOPIC_NAME, baseMap); } /** * 此為單點消息 * * @param chartId * @param message */ public void sendMessage(String chartId, String message) { BaseMap baseMap = new BaseMap(); baseMap.put("chartId", chartId); baseMap.put("message", message); jeecgRedisClient.sendMessage(REDIS_TOPIC_NAME, baseMap); } /** * 此為單點消息(多組件) * * @param chartIds * @param message */ public void sendMessage(String[] chartIds, String message) { for (String chartId : chartIds) { sendMessage(chartId, message); } } } ``` ### **6編寫消息推送測試方法** ``` package org.jeecg.modules.drag.controller; import com.alibaba.fastjson.JSONObject; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.jeecg.common.api.vo.Result; import org.jeecg.modules.drag.config.websocket.DragWebSocket; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * 測試拖拽websocket接口 * * @author zyf */ @RestController @Api(tags = "拖拽WebSocket測試") @RequestMapping("/drag/websocket") public class DragWebSocketController { @Autowired private DragWebSocket webSocket; @PostMapping("/sendData") @ApiOperation(value = "測試拖拽組件更新", notes = "測試拖拽組件更新") public Result<String> sendData() { Result<String> result = new Result<>(); //需要推送數據的組件ID String chartId = "cfb9bb9a-5d4d-4cd0-9d2e-fb9e2be1fc92"; String message = "[{\"value\":1048,\"name\":\"波導\"},{\"value\":735,\"name\":\"oppo\"},{\"value\":580,\"name\":\"華為\"},{\"value\":484,\"name\":\"小米\"},{\"value\":300,\"name\":\"魅族\"}]"; JSONObject obj = new JSONObject(); obj.put("chartId", chartId); obj.put("result", message); webSocket.sendMessage(chartId, obj.toJSONString()); result.setResult("單發"); return result; } } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看